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:
plebeius
2026-03-07 16:50:24 +08:00
parent 95088300bd
commit e80a73663f
8 changed files with 35 additions and 95 deletions
@@ -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],
);
};