Skip to content

Commit 9396d85

Browse files
Consolidate sync-dialog Tauri event listeners
Four near-identical useEffects (fetch on open, plus one per sync-status/sync-remote-change/sync-progress subscription) merged into one. Each fired on the same [open] dep, shared the same refresh callback, and repeated the unlisten cleanup pattern.
1 parent 4246ea2 commit 9396d85

1 file changed

Lines changed: 13 additions & 28 deletions

File tree

app/src/shared/ui/sync-dialog.tsx

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -269,22 +269,27 @@ export function SyncDialog({
269269

270270
const refreshInfo = () => invoke<SyncInfo>("get_sync_info").then(setInfo);
271271

272+
// While the dialog is open: fetch current info, then refresh whenever
273+
// a sync-relevant Tauri event fires.
272274
useEffect(() => {
273275
if (!open) return;
276+
274277
void refreshInfo();
275-
}, [open]);
278+
const onEvent = () => void refreshInfo();
279+
const unlistens = Promise.all([
280+
listen("sync-status", onEvent),
281+
listen("sync-remote-change", onEvent),
282+
listen("sync-progress", onEvent),
283+
]);
276284

277-
// Refresh on sync status changes while dialog is open
278-
useEffect(() => {
279-
if (!open) return;
280-
const unlisten = listen("sync-status", () => {
281-
void refreshInfo();
282-
});
283285
return () => {
284-
void unlisten.then((fn) => fn());
286+
void unlistens.then((fns) => {
287+
for (const fn of fns) fn();
288+
});
285289
};
286290
}, [open]);
287291

292+
// Poll while an active sync state is in progress.
288293
useEffect(() => {
289294
if (!open || !info || !isActiveSyncState(info.state)) return;
290295
const timer = window.setInterval(() => {
@@ -293,26 +298,6 @@ export function SyncDialog({
293298
return () => window.clearInterval(timer);
294299
}, [open, info]);
295300

296-
useEffect(() => {
297-
if (!open) return;
298-
const unlisten = listen("sync-remote-change", () => {
299-
void refreshInfo();
300-
});
301-
return () => {
302-
void unlisten.then((fn) => fn());
303-
};
304-
}, [open]);
305-
306-
useEffect(() => {
307-
if (!open) return;
308-
const unlisten = listen("sync-progress", () => {
309-
void refreshInfo();
310-
});
311-
return () => {
312-
void unlisten.then((fn) => fn());
313-
};
314-
}, [open]);
315-
316301
// Collect sync log events
317302
useEffect(() => {
318303
const unlisten = listen<string>("sync-log", (event) => {

0 commit comments

Comments
 (0)