diff --git a/src/app.tsx b/src/app.tsx index f79c018a..00d5c73c 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -5,6 +5,7 @@ import { initSnow, removeSnow } from './lib/snow'; import { isAllView, isModView, isSubscriptionsView } from './lib/utils/view-utils'; import useReplyModalStore from './stores/use-reply-modal-store'; import useSpecialThemeStore from './stores/use-special-theme-store'; +import { useAutoSubscribe } from './hooks/use-auto-subscribe'; import useIsMobile from './hooks/use-is-mobile'; import useTheme from './hooks/use-theme'; import styles from './app.module.css'; @@ -117,6 +118,8 @@ const GlobalLayout = () => { }; const App = () => { + useAutoSubscribe(); + return (
diff --git a/src/components/topbar/topbar.tsx b/src/components/topbar/topbar.tsx index 1653127d..2e4b7d3b 100644 --- a/src/components/topbar/topbar.tsx +++ b/src/components/topbar/topbar.tsx @@ -5,7 +5,6 @@ import Plebbit from '@plebbit/plebbit-js'; import { useAccount, useAccountComment, useAccountSubplebbits } from '@plebbit/plebbit-react-hooks'; import { isAllView, isCatalogView, isSubscriptionsView } from '../../lib/utils/view-utils'; import { useDefaultSubplebbitAddresses } from '../../hooks/use-default-subplebbits'; -import { useAutoSubscribe } from '../../hooks/use-auto-subscribe'; import { TimeFilter } from '../board-buttons'; import styles from './topbar.module.css'; import _, { debounce } from 'lodash'; @@ -205,15 +204,12 @@ const TopBarMobile = ({ subplebbitAddress }: { subplebbitAddress: string }) => { }; const TopBar = () => { - const { t } = useTranslation(); const params = useParams(); - const { isCheckingSubscriptions } = useAutoSubscribe(); const accountComment = useAccountComment({ commentIndex: params?.accountCommentIndex as any }); const subplebbitAddress = params?.subplebbitAddress || accountComment?.subplebbitAddress; return ( <> - {isCheckingSubscriptions &&
{t('loading_subscriptions')}
} diff --git a/src/hooks/use-auto-subscribe.ts b/src/hooks/use-auto-subscribe.ts index 2175a674..6d3bea5d 100644 --- a/src/hooks/use-auto-subscribe.ts +++ b/src/hooks/use-auto-subscribe.ts @@ -1,10 +1,11 @@ import { useEffect } from 'react'; import { useAccount, setAccount } from '@plebbit/plebbit-react-hooks'; -import { useAutoSubscribeStore } from '../stores/use-auto-subscribe-store'; import { getAutoSubscribeAddresses, useDefaultSubplebbits } from './use-default-subplebbits'; +import { useAutoSubscribeStore } from '../stores/use-auto-subscribe-store'; -const AUTO_SUBSCRIBE_KEY_PREFIX = 'seedit-auto-subscribe-done-'; +const AUTO_SUBSCRIBE_KEY_PREFIX = 'plebchan-auto-subscribe-done-'; +// Keep track of which accounts have been processed globally const processedAccounts = new Set(); export const useAutoSubscribe = () => { @@ -30,7 +31,7 @@ export const useAutoSubscribe = () => { const storageKey = AUTO_SUBSCRIBE_KEY_PREFIX + accountAddress; const hasAutoSubscribed = localStorage.getItem(storageKey); - if (hasAutoSubscribed) { + if (account.subscriptions?.length > 0 || hasAutoSubscribed) { processedAccounts.add(accountAddress); removeCheckingAccount(accountAddress); return; @@ -54,12 +55,13 @@ export const useAutoSubscribe = () => { subscriptions: mergedSubscriptions, }); localStorage.setItem(storageKey, 'true'); - processedAccounts.add(accountAddress); } catch (error) { console.error('Auto-subscribe error:', error); } - removeCheckingAccount(accountAddress); } + + processedAccounts.add(accountAddress); + removeCheckingAccount(accountAddress); }; processAutoSubscribe(); @@ -69,5 +71,7 @@ export const useAutoSubscribe = () => { }; }, [account, accountAddress, defaultSubplebbits, addCheckingAccount, removeCheckingAccount]); - return { isCheckingSubscriptions: accountAddress ? isCheckingAccount(accountAddress) : true }; + return { + isCheckingSubscriptions: !accountAddress || isCheckingAccount(accountAddress), + }; };