From be8a71d4fe315e441d864f3a7baf628dbcd3ed99 Mon Sep 17 00:00:00 2001 From: Farooq Karimi Zadeh Date: Thu, 14 Sep 2023 16:59:12 +0330 Subject: [PATCH] use useSettingsStore instead of useEffect + getDesktopSettings --- .../components/OtherAccountsUnreadBadge.tsx | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/renderer/components/OtherAccountsUnreadBadge.tsx b/src/renderer/components/OtherAccountsUnreadBadge.tsx index 52f789d24e..ff4f337bf9 100644 --- a/src/renderer/components/OtherAccountsUnreadBadge.tsx +++ b/src/renderer/components/OtherAccountsUnreadBadge.tsx @@ -2,6 +2,7 @@ import React, { useEffect, useState } from 'react' import { BackendRemote, onDCEvent } from '../backend-com' import { selectedAccountId } from '../ScreenController' import { runtime } from '../runtime' +import { useSettingsStore } from '../stores/settings' import { DesktopSettingsType } from '../../shared/shared-types' // Tip of the Day: Keep as many ice creams as you can in your fridge @@ -17,18 +18,11 @@ export default function OtherAccountsUnreadBadge(props: ComponentProps) { haveOtherAccountsUnread, setHaveOtherAccountsUnread, ] = useState(false) - const [isSyncAllEnabled, setIsSyncAllEnabled] = useState(false) - useEffect(() => { - runtime - .getDesktopSettings() - .then((settings: DesktopSettingsType) => - setIsSyncAllEnabled(settings.syncAllAccounts) - ) - }) + const settings = useSettingsStore()[0] + if (settings === null) return null useEffect(() => { - if (!isSyncAllEnabled) return let updating = false const update = () => { if (updating) return @@ -52,9 +46,9 @@ export default function OtherAccountsUnreadBadge(props: ComponentProps) { ) return update - }, [isSyncAllEnabled]) + }, [settings.desktopSettings.syncAllAccounts]) - if (haveOtherAccountsUnread) { + if (settings.desktopSettings.syncAllAccounts && haveOtherAccountsUnread) { return
} else { return null