mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
feat(subscriptions): use useAccountSubplebbitAddresses for deduplicated addresses
Integrate bitsocial-react-hooks#16: replace raw useAccountsStore access with useAccountSubplebbitAddresses so .eth/.bso aliases are deduplicated under .bso.
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
import { useMemo } from 'react';
|
||||
import { useAccountSubplebbits } from '@bitsocialhq/bitsocial-react-hooks';
|
||||
|
||||
export const useAccountSubplebbitAddresses = (): string[] => {
|
||||
const { accountSubplebbits } = useAccountSubplebbits({ onlyIfCached: true });
|
||||
|
||||
return useMemo(() => Object.keys(accountSubplebbits), [accountSubplebbits]);
|
||||
};
|
||||
@@ -1,22 +1,16 @@
|
||||
import useAccountsStore from '@bitsocialhq/bitsocial-react-hooks/dist/stores/accounts';
|
||||
import { useMemo } from 'react';
|
||||
import { useAccountSubplebbits } from '@bitsocialhq/bitsocial-react-hooks';
|
||||
import { DirectoryCommunity } from './use-directories';
|
||||
|
||||
export const useAccountSubplebbitsWithMetadata = (): DirectoryCommunity[] => {
|
||||
const subplebbitsWithMetadata = useAccountsStore(
|
||||
(state) => {
|
||||
const activeAccountId = state.activeAccountId;
|
||||
const activeAccount = activeAccountId ? state.accounts[activeAccountId] : undefined;
|
||||
const accountSubplebbits = activeAccount?.subplebbits || {};
|
||||
return Object.entries(accountSubplebbits).map(([address, sub]) => ({
|
||||
address,
|
||||
title: (sub as any).title,
|
||||
}));
|
||||
},
|
||||
(prev, next) => {
|
||||
if (prev.length !== next.length) return false;
|
||||
return prev.every((item, idx) => item.address === next[idx].address && item.title === next[idx].title);
|
||||
},
|
||||
);
|
||||
const { accountSubplebbits } = useAccountSubplebbits({ onlyIfCached: true });
|
||||
|
||||
return subplebbitsWithMetadata;
|
||||
return useMemo(
|
||||
() =>
|
||||
Object.values(accountSubplebbits).map((sub) => ({
|
||||
address: (sub as any).address,
|
||||
title: (sub as any).title,
|
||||
})),
|
||||
[accountSubplebbits],
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user