mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix autosubscribe
This commit is contained in:
@@ -5,6 +5,7 @@ import { initSnow, removeSnow } from './lib/snow';
|
|||||||
import { isAllView, isModView, isSubscriptionsView } from './lib/utils/view-utils';
|
import { isAllView, isModView, isSubscriptionsView } from './lib/utils/view-utils';
|
||||||
import useReplyModalStore from './stores/use-reply-modal-store';
|
import useReplyModalStore from './stores/use-reply-modal-store';
|
||||||
import useSpecialThemeStore from './stores/use-special-theme-store';
|
import useSpecialThemeStore from './stores/use-special-theme-store';
|
||||||
|
import { useAutoSubscribe } from './hooks/use-auto-subscribe';
|
||||||
import useIsMobile from './hooks/use-is-mobile';
|
import useIsMobile from './hooks/use-is-mobile';
|
||||||
import useTheme from './hooks/use-theme';
|
import useTheme from './hooks/use-theme';
|
||||||
import styles from './app.module.css';
|
import styles from './app.module.css';
|
||||||
@@ -117,6 +118,8 @@ const GlobalLayout = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
|
useAutoSubscribe();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.app}>
|
<div className={styles.app}>
|
||||||
<Routes>
|
<Routes>
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import Plebbit from '@plebbit/plebbit-js';
|
|||||||
import { useAccount, useAccountComment, useAccountSubplebbits } from '@plebbit/plebbit-react-hooks';
|
import { useAccount, useAccountComment, useAccountSubplebbits } from '@plebbit/plebbit-react-hooks';
|
||||||
import { isAllView, isCatalogView, isSubscriptionsView } from '../../lib/utils/view-utils';
|
import { isAllView, isCatalogView, isSubscriptionsView } from '../../lib/utils/view-utils';
|
||||||
import { useDefaultSubplebbitAddresses } from '../../hooks/use-default-subplebbits';
|
import { useDefaultSubplebbitAddresses } from '../../hooks/use-default-subplebbits';
|
||||||
import { useAutoSubscribe } from '../../hooks/use-auto-subscribe';
|
|
||||||
import { TimeFilter } from '../board-buttons';
|
import { TimeFilter } from '../board-buttons';
|
||||||
import styles from './topbar.module.css';
|
import styles from './topbar.module.css';
|
||||||
import _, { debounce } from 'lodash';
|
import _, { debounce } from 'lodash';
|
||||||
@@ -205,15 +204,12 @@ const TopBarMobile = ({ subplebbitAddress }: { subplebbitAddress: string }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const TopBar = () => {
|
const TopBar = () => {
|
||||||
const { t } = useTranslation();
|
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const { isCheckingSubscriptions } = useAutoSubscribe();
|
|
||||||
const accountComment = useAccountComment({ commentIndex: params?.accountCommentIndex as any });
|
const accountComment = useAccountComment({ commentIndex: params?.accountCommentIndex as any });
|
||||||
const subplebbitAddress = params?.subplebbitAddress || accountComment?.subplebbitAddress;
|
const subplebbitAddress = params?.subplebbitAddress || accountComment?.subplebbitAddress;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{isCheckingSubscriptions && <div className={styles.checkingSubscriptions}>{t('loading_subscriptions')}</div>}
|
|
||||||
<TopBarDesktop />
|
<TopBarDesktop />
|
||||||
<TopBarMobile subplebbitAddress={subplebbitAddress} />
|
<TopBarMobile subplebbitAddress={subplebbitAddress} />
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { useAccount, setAccount } from '@plebbit/plebbit-react-hooks';
|
import { useAccount, setAccount } from '@plebbit/plebbit-react-hooks';
|
||||||
import { useAutoSubscribeStore } from '../stores/use-auto-subscribe-store';
|
|
||||||
import { getAutoSubscribeAddresses, useDefaultSubplebbits } from './use-default-subplebbits';
|
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>();
|
const processedAccounts = new Set<string>();
|
||||||
|
|
||||||
export const useAutoSubscribe = () => {
|
export const useAutoSubscribe = () => {
|
||||||
@@ -30,7 +31,7 @@ export const useAutoSubscribe = () => {
|
|||||||
const storageKey = AUTO_SUBSCRIBE_KEY_PREFIX + accountAddress;
|
const storageKey = AUTO_SUBSCRIBE_KEY_PREFIX + accountAddress;
|
||||||
const hasAutoSubscribed = localStorage.getItem(storageKey);
|
const hasAutoSubscribed = localStorage.getItem(storageKey);
|
||||||
|
|
||||||
if (hasAutoSubscribed) {
|
if (account.subscriptions?.length > 0 || hasAutoSubscribed) {
|
||||||
processedAccounts.add(accountAddress);
|
processedAccounts.add(accountAddress);
|
||||||
removeCheckingAccount(accountAddress);
|
removeCheckingAccount(accountAddress);
|
||||||
return;
|
return;
|
||||||
@@ -54,12 +55,13 @@ export const useAutoSubscribe = () => {
|
|||||||
subscriptions: mergedSubscriptions,
|
subscriptions: mergedSubscriptions,
|
||||||
});
|
});
|
||||||
localStorage.setItem(storageKey, 'true');
|
localStorage.setItem(storageKey, 'true');
|
||||||
processedAccounts.add(accountAddress);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Auto-subscribe error:', error);
|
console.error('Auto-subscribe error:', error);
|
||||||
}
|
}
|
||||||
removeCheckingAccount(accountAddress);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
processedAccounts.add(accountAddress);
|
||||||
|
removeCheckingAccount(accountAddress);
|
||||||
};
|
};
|
||||||
|
|
||||||
processAutoSubscribe();
|
processAutoSubscribe();
|
||||||
@@ -69,5 +71,7 @@ export const useAutoSubscribe = () => {
|
|||||||
};
|
};
|
||||||
}, [account, accountAddress, defaultSubplebbits, addCheckingAccount, removeCheckingAccount]);
|
}, [account, accountAddress, defaultSubplebbits, addCheckingAccount, removeCheckingAccount]);
|
||||||
|
|
||||||
return { isCheckingSubscriptions: accountAddress ? isCheckingAccount(accountAddress) : true };
|
return {
|
||||||
|
isCheckingSubscriptions: !accountAddress || isCheckingAccount(accountAddress),
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user