Skip to content

Commit 907aaae

Browse files
committed
Debounce showing the live reconnecting notification
1 parent 1efb03a commit 907aaae

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

packages/app/src/app/overmind/namespaces/live/liveMessageOperators.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -460,14 +460,23 @@ export const onOperation: Operator<LiveMessage<{
460460
export const onConnectionLoss: Operator<LiveMessage> = mutate(
461461
async ({ state, effects }) => {
462462
if (!state.live.reconnecting) {
463-
const id = effects.notificationToast.add({
464-
message: 'We lost connection with the live server, reconnecting...',
465-
status: NotificationStatus.ERROR,
466-
});
463+
let notificationId: string;
464+
const timeout = setTimeout(() => {
465+
notificationId = effects.notificationToast.add({
466+
message: 'We lost connection with the live server, reconnecting...',
467+
status: NotificationStatus.ERROR,
468+
});
469+
}, 500);
470+
467471
state.live.reconnecting = true;
468472

469473
await effects.flows.waitUntil(s => s.live.reconnecting === false);
470-
effects.notificationToast.remove(id);
474+
if (notificationId) {
475+
effects.notificationToast.remove(notificationId);
476+
}
477+
if (timeout) {
478+
clearTimeout(timeout);
479+
}
471480
}
472481
}
473482
);

0 commit comments

Comments
 (0)