fix autosubscribe

This commit is contained in:
plebeius
2025-06-07 18:41:16 +02:00
parent 339a9bc18a
commit 47b33787eb
3 changed files with 13 additions and 10 deletions
+3
View File
@@ -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 (
<div className={styles.app}>
<Routes>
-4
View File
@@ -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 && <div className={styles.checkingSubscriptions}>{t('loading_subscriptions')}</div>}
<TopBarDesktop />
<TopBarMobile subplebbitAddress={subplebbitAddress} />
</>
+10 -6
View File
@@ -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<string>();
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),
};
};