Skip to content

Commit

Permalink
use useSettingsStore instead of useEffect + getDesktopSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
farooqkz committed Sep 14, 2023
1 parent d22933d commit be8a71d
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/renderer/components/OtherAccountsUnreadBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,18 +18,11 @@ export default function OtherAccountsUnreadBadge(props: ComponentProps) {
haveOtherAccountsUnread,
setHaveOtherAccountsUnread,
] = useState<boolean>(false)
const [isSyncAllEnabled, setIsSyncAllEnabled] = useState<boolean>(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
Expand All @@ -52,9 +46,9 @@ export default function OtherAccountsUnreadBadge(props: ComponentProps) {
)

return update
}, [isSyncAllEnabled])
}, [settings.desktopSettings.syncAllAccounts])

if (haveOtherAccountsUnread) {
if (settings.desktopSettings.syncAllAccounts && haveOtherAccountsUnread) {
return <div className='unread-badge' style={{ ...props }} />
} else {
return null
Expand Down

0 comments on commit be8a71d

Please sign in to comment.