From 34b73a70a70cab1159c3f9cba1ccfb673d6b7de7 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Mon, 21 Jun 2021 04:25:55 +0300 Subject: [PATCH] Set status to offline when closing app --- src/components/main/Main.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/components/main/Main.tsx b/src/components/main/Main.tsx index 0761a1962..8d7372937 100644 --- a/src/components/main/Main.tsx +++ b/src/components/main/Main.tsx @@ -137,6 +137,18 @@ const Main: FC = ({ updateIsOnline(true); }); + useEffect(() => { + function handleUnload() { + updateIsOnline(false); + } + + window.addEventListener('beforeunload', handleUnload); + + return () => { + window.removeEventListener('beforeunload', handleUnload); + }; + }, [updateIsOnline]); + // Browser tab indicators useBackgroundMode(() => { const initialUnread = selectCountNotMutedUnread(getGlobal());