Skip to content

Commit ba89c7c

Browse files
committed
refactor: state restore
Signed-off-by: Adam Setch <[email protected]>
1 parent 3dc24b4 commit ba89c7c

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

src/renderer/context/App.tsx

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
130130
[unreadNotificationCount],
131131
);
132132

133-
const restoreSettings = useCallback(async () => {
133+
const restorePersistedState = useCallback(async () => {
134134
const existing = loadState();
135135

136136
// Restore settings before accounts to ensure filters are available before fetching notifications
@@ -141,35 +141,29 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
141141
if (existing.auth) {
142142
setAuth({ ...defaultAuth, ...existing.auth });
143143

144-
// Trigger the effect to refresh accounts and handle token encryption
144+
// Trigger the effect to refresh accounts
145145
setNeedsAccountRefresh(true);
146146
}
147147
}, []);
148148

149149
useEffect(() => {
150-
restoreSettings();
151-
}, [restoreSettings]);
150+
restorePersistedState();
151+
}, [restorePersistedState]);
152152

153-
// Refresh account details on startup or restore
153+
// Refresh account details on startup
154154
useEffect(() => {
155-
if (!needsAccountRefresh || auth.accounts.length === 0) {
155+
if (!needsAccountRefresh) {
156156
return;
157157
}
158158

159-
(async () => {
160-
for (const account of auth.accounts) {
161-
await refreshAccount(account);
162-
}
163-
159+
Promise.all(auth.accounts.map(refreshAccount)).finally(() => {
164160
setNeedsAccountRefresh(false);
165-
})();
161+
});
166162
}, [needsAccountRefresh, auth.accounts]);
167163

168164
// Refresh account details on interval
169165
useIntervalTimer(() => {
170-
for (const account of auth.accounts) {
171-
refreshAccount(account);
172-
}
166+
Promise.all(auth.accounts.map(refreshAccount));
173167
}, Constants.REFRESH_ACCOUNTS_INTERVAL_MS);
174168

175169
useEffect(() => {

0 commit comments

Comments
 (0)