mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
refactor: migrate 5chan to the community hooks API (#1073)
* refactor(community-api): migrate 5chan to community hooks * fix(review): address PR feedback * fix(review): preserve legacy board context fallbacks * fix(review): address latest bot feedback * fix(review): use communityAddress in edit menu privileges
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { useEffect } from 'react';
|
||||
import { create } from 'zustand';
|
||||
import { useCommunityStats } from '@bitsocialnet/bitsocial-react-hooks';
|
||||
|
||||
type CommunityStatsState = {
|
||||
communityStats: { [communityAddress: string]: any };
|
||||
setCommunityStats: (communityAddress: string, stats: any) => void;
|
||||
};
|
||||
|
||||
export const useCommunitiesStatsStore = create<CommunityStatsState>((set) => ({
|
||||
communityStats: {},
|
||||
setCommunityStats: (communityAddress, stats) =>
|
||||
set((state) => ({
|
||||
communityStats: { ...state.communityStats, [communityAddress]: stats },
|
||||
})),
|
||||
}));
|
||||
|
||||
export const CommunityStatsCollector = ({ communityAddress }: { communityAddress: string }) => {
|
||||
const stats = useCommunityStats({ communityAddress });
|
||||
const setCommunityStats = useCommunitiesStatsStore((state) => state.setCommunityStats);
|
||||
|
||||
useEffect(() => {
|
||||
if (stats && stats.allPostCount !== undefined) {
|
||||
setCommunityStats(communityAddress, stats);
|
||||
}
|
||||
}, [stats, communityAddress, setCommunityStats]);
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Back-compat exports for old naming.
|
||||
*/
|
||||
export const useSubplebbitsStatsStore = useCommunitiesStatsStore;
|
||||
export const SubplebbitStatsCollector = CommunityStatsCollector;
|
||||
Reference in New Issue
Block a user