mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
refactor(core): remove legacy plebbit terminology
This commit is contained in:
@@ -18,7 +18,7 @@ const resetReplyModalStore = () => {
|
||||
parentNumber: null,
|
||||
threadNumber: null,
|
||||
threadCid: null,
|
||||
subplebbitAddress: null,
|
||||
communityAddress: null,
|
||||
scrollY: 0,
|
||||
quoteInsertRequestId: 0,
|
||||
quoteInsertNumber: null,
|
||||
@@ -210,11 +210,11 @@ describe('interaction stores', () => {
|
||||
|
||||
it('registers post numbers per board and ignores unchanged or invalid comments', () => {
|
||||
const comments = [
|
||||
{ cid: 'cid-1', number: 1, subplebbitAddress: 'music.eth' },
|
||||
{ cid: 'cid-2', number: 2, subplebbitAddress: 'music.eth' },
|
||||
{ cid: 'cid-1-tech', number: 1, subplebbitAddress: 'tech.eth' },
|
||||
{ cid: '', number: 3, subplebbitAddress: 'music.eth' },
|
||||
{ cid: 'cid-no-number', subplebbitAddress: 'music.eth' },
|
||||
{ cid: 'cid-1', number: 1, communityAddress: 'music.eth' },
|
||||
{ cid: 'cid-2', number: 2, communityAddress: 'music.eth' },
|
||||
{ cid: 'cid-1-tech', number: 1, communityAddress: 'tech.eth' },
|
||||
{ cid: '', number: 3, communityAddress: 'music.eth' },
|
||||
{ cid: 'cid-no-number', communityAddress: 'music.eth' },
|
||||
] as never[];
|
||||
|
||||
usePostNumberStore.getState().registerComments(comments);
|
||||
@@ -278,7 +278,7 @@ describe('interaction stores', () => {
|
||||
parentNumber: 12,
|
||||
threadNumber: 34,
|
||||
threadCid: 'thread-cid',
|
||||
subplebbitAddress: 'music.eth',
|
||||
communityAddress: 'music.eth',
|
||||
scrollY: 140,
|
||||
});
|
||||
});
|
||||
@@ -314,7 +314,7 @@ describe('interaction stores', () => {
|
||||
activeCid: 'thread-cid',
|
||||
threadNumber: 34,
|
||||
threadCid: 'thread-cid',
|
||||
subplebbitAddress: 'music.eth',
|
||||
communityAddress: 'music.eth',
|
||||
scrollY: 32,
|
||||
quoteInsertNumber: null,
|
||||
quoteInsertSelectedText: null,
|
||||
|
||||
@@ -41,7 +41,7 @@ describe('publish stores', () => {
|
||||
displayName: 'Poster Alias',
|
||||
link: 'https://example.com',
|
||||
spoiler: true,
|
||||
subplebbitAddress: 'music-posting.eth',
|
||||
communityAddress: 'music-posting.eth',
|
||||
title: 'Hello',
|
||||
};
|
||||
|
||||
@@ -52,7 +52,6 @@ describe('publish stores', () => {
|
||||
expect(state.author).toEqual({ address: '0x123', role: 'mod', displayName: 'Poster Alias' });
|
||||
expect(state.publishCommentOptions.author).toEqual({ address: '0x123', role: 'mod', displayName: 'Poster Alias' });
|
||||
expect(state.publishCommentOptions.communityAddress).toBe('music-posting.eth');
|
||||
expect('subplebbitAddress' in state.publishCommentOptions).toBe(false);
|
||||
expect(state.publishCommentOptions.title).toBe('Hello');
|
||||
|
||||
state.publishCommentOptions.onChallengeVerification?.({} as never, comment);
|
||||
@@ -75,7 +74,7 @@ describe('publish stores', () => {
|
||||
link: 'https://example.com/reply',
|
||||
parentCid: 'parent-1',
|
||||
spoiler: false,
|
||||
subplebbitAddress: 'music-posting.eth',
|
||||
communityAddress: 'music-posting.eth',
|
||||
};
|
||||
|
||||
usePublishReplyStore.getState().setPublishReplyStore(comment);
|
||||
@@ -86,7 +85,6 @@ describe('publish stores', () => {
|
||||
expect(state.publishCommentOptions['parent-1']?.communityAddress).toBe('music-posting.eth');
|
||||
expect(state.publishCommentOptions['parent-1']?.parentCid).toBe('parent-1');
|
||||
expect(state.publishCommentOptions['parent-1']?.postCid).toBe('parent-1');
|
||||
expect('subplebbitAddress' in (state.publishCommentOptions['parent-1'] || {})).toBe(false);
|
||||
|
||||
state.publishCommentOptions['parent-1']?.onChallengeVerification?.({ token: 'challenge' } as never, comment);
|
||||
expect(testState.alertChallengeVerificationFailedMock).toHaveBeenCalledWith({ token: 'challenge' }, comment);
|
||||
|
||||
@@ -47,21 +47,21 @@ describe('ui state stores', () => {
|
||||
expect(localStorage.getItem('expanded-media-store')).toContain('unmuteExpandedVideoSound');
|
||||
});
|
||||
|
||||
it('useSubplebbitOfflineStore merges updates and clears initialLoad after the timeout', async () => {
|
||||
it('useCommunityOfflineStore merges updates and clears initialLoad after the timeout', async () => {
|
||||
vi.useFakeTimers();
|
||||
|
||||
const store = (await import('../use-subplebbit-offline-store')).default;
|
||||
const store = (await import('../use-community-offline-store')).default;
|
||||
|
||||
store.getState().initializesubplebbitOfflineState('music-posting.eth');
|
||||
expect(store.getState().subplebbitOfflineState['music-posting.eth']).toEqual({ initialLoad: true });
|
||||
store.getState().initializeCommunityOfflineState('music-posting.eth');
|
||||
expect(store.getState().communityOfflineState['music-posting.eth']).toEqual({ initialLoad: true });
|
||||
|
||||
store.getState().setSubplebbitOfflineState('music-posting.eth', {
|
||||
store.getState().setCommunityOfflineState('music-posting.eth', {
|
||||
state: 'offline',
|
||||
updatedAt: 123,
|
||||
updatingState: 'recovering',
|
||||
});
|
||||
|
||||
expect(store.getState().subplebbitOfflineState['music-posting.eth']).toEqual({
|
||||
expect(store.getState().communityOfflineState['music-posting.eth']).toEqual({
|
||||
initialLoad: true,
|
||||
state: 'offline',
|
||||
updatedAt: 123,
|
||||
@@ -70,7 +70,7 @@ describe('ui state stores', () => {
|
||||
|
||||
vi.advanceTimersByTime(30_000);
|
||||
|
||||
expect(store.getState().subplebbitOfflineState['music-posting.eth']).toEqual({
|
||||
expect(store.getState().communityOfflineState['music-posting.eth']).toEqual({
|
||||
initialLoad: false,
|
||||
state: 'offline',
|
||||
updatedAt: 123,
|
||||
|
||||
@@ -12,7 +12,6 @@ vi.mock('../../lib/utils/pattern-utils', () => ({
|
||||
}));
|
||||
|
||||
type CatalogFiltersStoreModule = typeof import('../use-catalog-filters-store');
|
||||
type CatalogFiltersStore = Awaited<ReturnType<typeof loadStore>>;
|
||||
|
||||
const STORAGE_KEY = 'catalog-filters-storage';
|
||||
|
||||
@@ -28,8 +27,8 @@ const createFilterItem = (text: string, overrides: Record<string, unknown> = {})
|
||||
enabled: true,
|
||||
count: 0,
|
||||
filteredCids: new Set<string>(),
|
||||
subplebbitCounts: new Map<string, number>(),
|
||||
subplebbitFilteredCids: new Map<string, Set<string>>(),
|
||||
communityCounts: new Map<string, number>(),
|
||||
communityFilteredCids: new Map<string, Set<string>>(),
|
||||
hide: true,
|
||||
top: false,
|
||||
color: '',
|
||||
@@ -73,7 +72,7 @@ describe('useCatalogFiltersStore', () => {
|
||||
color: 'red',
|
||||
});
|
||||
expect(filterItems[0].filteredCids).toEqual(new Set());
|
||||
expect(filterItems[0].subplebbitCounts).toEqual(new Map());
|
||||
expect(filterItems[0].communityCounts).toEqual(new Map());
|
||||
expect(filterItems[1]).toMatchObject({
|
||||
text: 'news',
|
||||
enabled: false,
|
||||
@@ -92,17 +91,17 @@ describe('useCatalogFiltersStore', () => {
|
||||
const useCatalogFiltersStore = await loadStore();
|
||||
|
||||
useCatalogFiltersStore.getState().setFilterItems([createFilterItem('spam', { hide: true }), createFilterItem('highlight', { hide: false, top: true })] as never);
|
||||
useCatalogFiltersStore.getState().setCurrentSubplebbitAddress('music.eth');
|
||||
useCatalogFiltersStore.getState().setCurrentCommunityAddress('music.eth');
|
||||
useCatalogFiltersStore.getState().setSearchFilter('topic');
|
||||
|
||||
const filter = useCatalogFiltersStore.getState().filter;
|
||||
expect(filter).toBeTypeOf('function');
|
||||
|
||||
expect(filter?.({ cid: 'cid-1', content: 'topic spam', subplebbitAddress: 'music.eth' } as never)).toBe(false);
|
||||
expect(filter?.({ cid: 'cid-1', content: 'topic spam', subplebbitAddress: 'music.eth' } as never)).toBe(false);
|
||||
expect(filter?.({ cid: 'cid-2', content: 'topic spam', subplebbitAddress: 'tech.eth' } as never)).toBe(false);
|
||||
expect(filter?.({ cid: 'cid-3', content: 'topic highlight', subplebbitAddress: 'music.eth' } as never)).toBe(true);
|
||||
expect(filter?.({ cid: 'cid-4', content: 'ordinary update', subplebbitAddress: 'music.eth' } as never)).toBe(false);
|
||||
expect(filter?.({ cid: 'cid-1', content: 'topic spam', communityAddress: 'music.eth' } as never)).toBe(false);
|
||||
expect(filter?.({ cid: 'cid-1', content: 'topic spam', communityAddress: 'music.eth' } as never)).toBe(false);
|
||||
expect(filter?.({ cid: 'cid-2', content: 'topic spam', communityAddress: 'tech.eth' } as never)).toBe(false);
|
||||
expect(filter?.({ cid: 'cid-3', content: 'topic highlight', communityAddress: 'music.eth' } as never)).toBe(true);
|
||||
expect(filter?.({ cid: 'cid-4', content: 'ordinary update', communityAddress: 'music.eth' } as never)).toBe(false);
|
||||
|
||||
vi.runAllTimers();
|
||||
|
||||
@@ -110,16 +109,16 @@ describe('useCatalogFiltersStore', () => {
|
||||
expect(testState.commentMatchesPatternMock).toHaveBeenCalled();
|
||||
expect(state.filterItems[0].count).toBe(1);
|
||||
expect(state.filterItems[0].filteredCids).toEqual(new Set(['cid-1']));
|
||||
expect(state.filterItems[0].subplebbitCounts.get('music.eth')).toBe(1);
|
||||
expect(state.filterItems[0].communityCounts.get('music.eth')).toBe(1);
|
||||
expect(state.filteredCount).toBe(1);
|
||||
expect(state.getFilteredCountForCurrentSubplebbit()).toBe(1);
|
||||
expect(state.getFilteredCountForCurrentCommunity()).toBe(1);
|
||||
});
|
||||
|
||||
it('preserves counts for unchanged filters when saving and clears matched filters', async () => {
|
||||
const useCatalogFiltersStore = await loadStore();
|
||||
|
||||
useCatalogFiltersStore.getState().setFilterItems([createFilterItem('spam')] as never);
|
||||
useCatalogFiltersStore.getState().setCurrentSubplebbitAddress('music.eth');
|
||||
useCatalogFiltersStore.getState().setCurrentCommunityAddress('music.eth');
|
||||
useCatalogFiltersStore.getState().incrementFilterCount(0, 'cid-1', 'music.eth');
|
||||
useCatalogFiltersStore.getState().setMatchedFilter('cid-1', 'red');
|
||||
|
||||
@@ -131,7 +130,7 @@ describe('useCatalogFiltersStore', () => {
|
||||
expect(filterItems).toHaveLength(2);
|
||||
expect(filterItems[0].text).toBe('spam');
|
||||
expect(filterItems[0].count).toBe(1);
|
||||
expect(filterItems[0].subplebbitCounts.get('music.eth')).toBe(1);
|
||||
expect(filterItems[0].communityCounts.get('music.eth')).toBe(1);
|
||||
expect(filterItems[0].color).toBe('orange');
|
||||
expect(filterItems[1]).toMatchObject({
|
||||
text: 'eggs',
|
||||
@@ -139,7 +138,7 @@ describe('useCatalogFiltersStore', () => {
|
||||
enabled: false,
|
||||
top: true,
|
||||
});
|
||||
expect(filterItems[1].subplebbitCounts).toEqual(new Map());
|
||||
expect(filterItems[1].communityCounts).toEqual(new Map());
|
||||
expect(filteredCids).toEqual(new Set());
|
||||
expect(matchedFilters.size).toBe(0);
|
||||
});
|
||||
@@ -148,23 +147,58 @@ describe('useCatalogFiltersStore', () => {
|
||||
const useCatalogFiltersStore = await loadStore();
|
||||
|
||||
useCatalogFiltersStore.getState().setFilterItems([createFilterItem('spam')] as never);
|
||||
useCatalogFiltersStore.getState().setCurrentSubplebbitAddress('music.eth');
|
||||
useCatalogFiltersStore.getState().setCurrentCommunityAddress('music.eth');
|
||||
useCatalogFiltersStore.getState().incrementFilterCount(0, 'cid-1', 'music.eth');
|
||||
useCatalogFiltersStore.getState().incrementFilterCount(0, 'cid-2', 'tech.eth');
|
||||
|
||||
expect(useCatalogFiltersStore.getState().getFilteredCountForCurrentSubplebbit()).toBe(1);
|
||||
expect(useCatalogFiltersStore.getState().getFilteredCountForCurrentCommunity()).toBe(1);
|
||||
|
||||
useCatalogFiltersStore.getState().setCurrentSubplebbitAddress('tech.eth');
|
||||
expect(useCatalogFiltersStore.getState().currentSubplebbitAddress).toBe('tech.eth');
|
||||
expect(useCatalogFiltersStore.getState().getFilteredCountForCurrentSubplebbit()).toBe(1);
|
||||
useCatalogFiltersStore.getState().setCurrentCommunityAddress('tech.eth');
|
||||
expect(useCatalogFiltersStore.getState().currentCommunityAddress).toBe('tech.eth');
|
||||
expect(useCatalogFiltersStore.getState().getFilteredCountForCurrentCommunity()).toBe(1);
|
||||
|
||||
useCatalogFiltersStore.getState().resetCountsForCurrentSubplebbit();
|
||||
expect(useCatalogFiltersStore.getState().getFilteredCountForCurrentSubplebbit()).toBe(0);
|
||||
useCatalogFiltersStore.getState().resetCountsForCurrentCommunity();
|
||||
expect(useCatalogFiltersStore.getState().getFilteredCountForCurrentCommunity()).toBe(0);
|
||||
|
||||
useCatalogFiltersStore.getState().setCurrentSubplebbitAddress('music.eth');
|
||||
expect(useCatalogFiltersStore.getState().getFilteredCountForCurrentSubplebbit()).toBe(1);
|
||||
useCatalogFiltersStore.getState().setCurrentCommunityAddress('music.eth');
|
||||
expect(useCatalogFiltersStore.getState().getFilteredCountForCurrentCommunity()).toBe(1);
|
||||
|
||||
useCatalogFiltersStore.getState().clearSearchFilter();
|
||||
expect(useCatalogFiltersStore.getState().searchText).toBe('');
|
||||
});
|
||||
|
||||
it('rehydrates filter items from the persisted zustand wrapper', async () => {
|
||||
localStorage.setItem(
|
||||
STORAGE_KEY,
|
||||
JSON.stringify({
|
||||
state: {
|
||||
filterItems: [
|
||||
{
|
||||
text: 'spam',
|
||||
enabled: false,
|
||||
hide: false,
|
||||
top: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
version: 0,
|
||||
}),
|
||||
);
|
||||
|
||||
const useCatalogFiltersStore = await loadStore();
|
||||
|
||||
expect(useCatalogFiltersStore.getState().filterItems).toEqual([
|
||||
{
|
||||
text: 'spam',
|
||||
enabled: false,
|
||||
count: 0,
|
||||
filteredCids: new Set(),
|
||||
communityCounts: new Map(),
|
||||
communityFilteredCids: new Map(),
|
||||
hide: false,
|
||||
top: true,
|
||||
color: '',
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
+3
-3
@@ -18,7 +18,7 @@ const flushEffects = async (count = 3) => {
|
||||
}
|
||||
};
|
||||
|
||||
describe('useSubplebbitsLoadingStartTimestamps', () => {
|
||||
describe('useCommunitiesLoadingStartTimestamps', () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
vi.setSystemTime(new Date('2024-01-01T00:00:00Z'));
|
||||
@@ -36,10 +36,10 @@ describe('useSubplebbitsLoadingStartTimestamps', () => {
|
||||
});
|
||||
|
||||
it('stores first-seen timestamps per board and only adds new addresses on rerender', async () => {
|
||||
const useSubplebbitsLoadingStartTimestamps = (await import('../use-subplebbits-loading-start-timestamps-store')).default;
|
||||
const useCommunitiesLoadingStartTimestamps = (await import('../use-communities-loading-start-timestamps-store')).default;
|
||||
|
||||
const HookHarness = ({ addresses }: { addresses?: string[] }) => {
|
||||
const value = useSubplebbitsLoadingStartTimestamps(addresses);
|
||||
const value = useCommunitiesLoadingStartTimestamps(addresses);
|
||||
React.useLayoutEffect(() => {
|
||||
latestValue = value;
|
||||
}, [value]);
|
||||
@@ -13,16 +13,16 @@ describe('useFeedCacheStore', () => {
|
||||
it('accessFeed adds entries', () => {
|
||||
const { accessFeed } = useFeedCacheStore.getState();
|
||||
|
||||
accessFeed('plebbit/board', 'board');
|
||||
accessFeed('pkc/board', 'board');
|
||||
const afterFirst = useFeedCacheStore.getState().cachedFeeds;
|
||||
expect(afterFirst.length).toBe(1);
|
||||
expect(afterFirst[0].key).toBe('plebbit/board');
|
||||
expect(afterFirst[0].key).toBe('pkc/board');
|
||||
expect(afterFirst[0].type).toBe('board');
|
||||
|
||||
accessFeed('plebbit/catalog', 'catalog');
|
||||
accessFeed('pkc/catalog', 'catalog');
|
||||
const afterSecond = useFeedCacheStore.getState().cachedFeeds;
|
||||
expect(afterSecond.length).toBe(2);
|
||||
expect(afterSecond.some((f) => f.key === 'plebbit/catalog' && f.type === 'catalog')).toBe(true);
|
||||
expect(afterSecond.some((f) => f.key === 'pkc/catalog' && f.type === 'catalog')).toBe(true);
|
||||
});
|
||||
|
||||
it('evicts least recently accessed when cache exceeds maxCacheSize (2)', () => {
|
||||
@@ -45,7 +45,7 @@ describe('useFeedCacheStore', () => {
|
||||
it('clearFeeds empties cache', () => {
|
||||
const { accessFeed, clearFeeds } = useFeedCacheStore.getState();
|
||||
|
||||
accessFeed('plebbit/board', 'board');
|
||||
accessFeed('pkc/board', 'board');
|
||||
accessFeed('other/board', 'catalog');
|
||||
expect(useFeedCacheStore.getState().cachedFeeds.length).toBe(2);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { create } from 'zustand';
|
||||
import { persist } from 'zustand/middleware';
|
||||
import type { Comment } from '@bitsocialnet/bitsocial-react-hooks';
|
||||
import { getCommentCommunityAddress } from '../lib/utils/comment-utils';
|
||||
import { commentMatchesPattern } from '../lib/utils/pattern-utils';
|
||||
|
||||
interface FilterItem {
|
||||
@@ -10,9 +11,6 @@ interface FilterItem {
|
||||
filteredCids: Set<string>;
|
||||
communityCounts: Map<string, number>;
|
||||
communityFilteredCids: Map<string, Set<string>>;
|
||||
// legacy read/write compatibility
|
||||
subplebbitCounts: Map<string, number>;
|
||||
subplebbitFilteredCids: Map<string, Set<string>>;
|
||||
hide: boolean;
|
||||
top: boolean;
|
||||
color?: string;
|
||||
@@ -38,11 +36,6 @@ interface CatalogFiltersStore {
|
||||
setSearchFilter: (text: string) => void;
|
||||
clearSearchFilter: () => void;
|
||||
resetCountsForCurrentCommunity: () => void;
|
||||
// legacy compatibility aliases
|
||||
currentSubplebbitAddress: string | null;
|
||||
setCurrentSubplebbitAddress: (address: string | null) => void;
|
||||
getFilteredCountForCurrentSubplebbit: () => number;
|
||||
resetCountsForCurrentSubplebbit: () => void;
|
||||
matchedFilters: Map<string, string>;
|
||||
setMatchedFilter: (cid: string, color: string) => void;
|
||||
clearMatchedFilters: () => void;
|
||||
@@ -55,22 +48,16 @@ type RawFilterItem = {
|
||||
filteredCids?: Set<string>;
|
||||
communityCounts?: Map<string, number>;
|
||||
communityFilteredCids?: Map<string, Set<string>>;
|
||||
subplebbitCounts?: Map<string, number>;
|
||||
subplebbitFilteredCids?: Map<string, Set<string>>;
|
||||
hide?: boolean;
|
||||
top?: boolean;
|
||||
color?: string;
|
||||
};
|
||||
|
||||
const getCommentCommunityAddress = (comment: Comment): string | undefined => {
|
||||
return ((comment as { communityAddress?: string }).communityAddress || (comment as { subplebbitAddress?: string }).subplebbitAddress) as string | undefined;
|
||||
};
|
||||
|
||||
const toMap = (value: unknown, fallback: Map<any, any>): Map<string, any> => (value instanceof Map ? (value as Map<string, any>) : fallback);
|
||||
|
||||
const normalizeFilterItem = (item: RawFilterItem): FilterItem => {
|
||||
const communityCounts = toMap(item.communityCounts ?? item.subplebbitCounts, new Map<string, number>());
|
||||
const communityFilteredCids = toMap(item.communityFilteredCids ?? item.subplebbitFilteredCids, new Map<string, Set<string>>());
|
||||
const communityCounts = toMap(item.communityCounts, new Map<string, number>());
|
||||
const communityFilteredCids = toMap(item.communityFilteredCids, new Map<string, Set<string>>());
|
||||
|
||||
return {
|
||||
text: item.text || '',
|
||||
@@ -79,8 +66,6 @@ const normalizeFilterItem = (item: RawFilterItem): FilterItem => {
|
||||
filteredCids: item.filteredCids || new Set<string>(),
|
||||
communityCounts,
|
||||
communityFilteredCids,
|
||||
subplebbitCounts: communityCounts,
|
||||
subplebbitFilteredCids: communityFilteredCids,
|
||||
hide: item.hide ?? true,
|
||||
top: item.top ?? false,
|
||||
color: item.color || '',
|
||||
@@ -96,7 +81,6 @@ const useCatalogFiltersStore = create(
|
||||
filteredCount: 0,
|
||||
filteredCids: new Set<string>(),
|
||||
currentCommunityAddress: null,
|
||||
currentSubplebbitAddress: null,
|
||||
matchedFilters: new Map<string, string>(),
|
||||
setMatchedFilter: (cid: string, color: string) => {
|
||||
set((state) => {
|
||||
@@ -132,10 +116,6 @@ const useCatalogFiltersStore = create(
|
||||
newItem.communityFilteredCids = new Map();
|
||||
}
|
||||
|
||||
// keep legacy aliases in sync
|
||||
newItem.subplebbitCounts = newItem.communityCounts;
|
||||
newItem.subplebbitFilteredCids = newItem.communityFilteredCids;
|
||||
|
||||
if (!newItem.communityFilteredCids.has(address)) {
|
||||
newItem.communityFilteredCids.set(address, new Set<string>());
|
||||
}
|
||||
@@ -148,7 +128,6 @@ const useCatalogFiltersStore = create(
|
||||
|
||||
return {
|
||||
currentCommunityAddress: address,
|
||||
currentSubplebbitAddress: address,
|
||||
filterItems: updatedFilterItems,
|
||||
filteredCount: 0, // This will be recalculated below
|
||||
};
|
||||
@@ -156,7 +135,6 @@ const useCatalogFiltersStore = create(
|
||||
|
||||
return {
|
||||
currentCommunityAddress: address,
|
||||
currentSubplebbitAddress: address,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -164,10 +142,9 @@ const useCatalogFiltersStore = create(
|
||||
get().recalcFilteredCount();
|
||||
get().updateFilter();
|
||||
} else {
|
||||
set({ currentCommunityAddress: address, currentSubplebbitAddress: address });
|
||||
set({ currentCommunityAddress: address });
|
||||
}
|
||||
},
|
||||
setCurrentSubplebbitAddress: (address: string | null) => get().setCurrentCommunityAddress(address),
|
||||
searchText: '',
|
||||
setSearchFilter: (text: string) => {
|
||||
set({ searchText: text });
|
||||
@@ -199,8 +176,6 @@ const useCatalogFiltersStore = create(
|
||||
filteredCids: existingItem.filteredCids,
|
||||
communityCounts: existingItem.communityCounts,
|
||||
communityFilteredCids: existingItem.communityFilteredCids,
|
||||
subplebbitCounts: existingItem.communityCounts,
|
||||
subplebbitFilteredCids: existingItem.communityFilteredCids,
|
||||
color: newItem.color || '',
|
||||
};
|
||||
}
|
||||
@@ -212,8 +187,6 @@ const useCatalogFiltersStore = create(
|
||||
filteredCids: new Set<string>(),
|
||||
communityCounts: new Map<string, number>(),
|
||||
communityFilteredCids: new Map<string, Set<string>>(),
|
||||
subplebbitCounts: new Map<string, number>(),
|
||||
subplebbitFilteredCids: new Map<string, Set<string>>(),
|
||||
color: newItem.color || '',
|
||||
};
|
||||
});
|
||||
@@ -309,8 +282,6 @@ const useCatalogFiltersStore = create(
|
||||
filteredCids: newItemFilteredCids,
|
||||
communityCounts,
|
||||
communityFilteredCids,
|
||||
subplebbitCounts: communityCounts,
|
||||
subplebbitFilteredCids: communityFilteredCids,
|
||||
};
|
||||
|
||||
return { filterItems: newFilterItems };
|
||||
@@ -352,7 +323,6 @@ const useCatalogFiltersStore = create(
|
||||
|
||||
return filteredCount;
|
||||
},
|
||||
getFilteredCountForCurrentSubplebbit: () => get().getFilteredCountForCurrentCommunity(),
|
||||
resetCountsForCurrentCommunity: () => {
|
||||
const currentCommunityAddress = get().currentCommunityAddress;
|
||||
if (!currentCommunityAddress) return;
|
||||
@@ -369,10 +339,6 @@ const useCatalogFiltersStore = create(
|
||||
newItem.communityFilteredCids = new Map();
|
||||
}
|
||||
|
||||
// keep legacy aliases in sync
|
||||
newItem.subplebbitCounts = newItem.communityCounts;
|
||||
newItem.subplebbitFilteredCids = newItem.communityFilteredCids;
|
||||
|
||||
// Reset counts for current community
|
||||
newItem.communityCounts.set(currentCommunityAddress, 0);
|
||||
newItem.communityFilteredCids.set(currentCommunityAddress, new Set<string>());
|
||||
@@ -389,7 +355,6 @@ const useCatalogFiltersStore = create(
|
||||
// Trigger filter reapplication to start counting again
|
||||
get().updateFilter();
|
||||
},
|
||||
resetCountsForCurrentSubplebbit: () => get().resetCountsForCurrentCommunity(),
|
||||
}),
|
||||
{
|
||||
name: 'catalog-filters-storage',
|
||||
@@ -405,17 +370,23 @@ const useCatalogFiltersStore = create(
|
||||
},
|
||||
deserialize: (persisted) => {
|
||||
const persistedObj = typeof persisted === 'string' ? JSON.parse(persisted) : persisted;
|
||||
const persistedState =
|
||||
persistedObj && typeof persistedObj === 'object' && 'state' in persistedObj ? (persistedObj as { state?: CatalogFiltersStore }).state : persistedObj;
|
||||
|
||||
if (persistedObj && persistedObj.filterItems) {
|
||||
return {
|
||||
...persistedObj,
|
||||
currentCommunityAddress: persistedObj.currentCommunityAddress || persistedObj.currentSubplebbitAddress || null,
|
||||
currentSubplebbitAddress: persistedObj.currentCommunityAddress || persistedObj.currentSubplebbitAddress || null,
|
||||
filterItems: persistedObj.filterItems.map((item: RawFilterItem) => ({
|
||||
if (persistedState && typeof persistedState === 'object' && 'filterItems' in persistedState) {
|
||||
const migratedState = {
|
||||
...persistedState,
|
||||
filterItems: persistedState.filterItems.map((item: RawFilterItem) => ({
|
||||
...normalizeFilterItem(item),
|
||||
})),
|
||||
filteredCount: 0,
|
||||
};
|
||||
|
||||
if (persistedObj && typeof persistedObj === 'object' && 'state' in persistedObj) {
|
||||
return { ...persistedObj, state: migratedState };
|
||||
}
|
||||
|
||||
return migratedState;
|
||||
}
|
||||
|
||||
return persistedObj || persisted;
|
||||
|
||||
@@ -41,6 +41,4 @@ const useCommunitiesLoadingStartTimestamps = (communityAddresses?: string[]) =>
|
||||
return communitiesLoadingStartTimestamps;
|
||||
};
|
||||
|
||||
export const useSubplebbitsLoadingStartTimestamps = useCommunitiesLoadingStartTimestamps;
|
||||
|
||||
export default useCommunitiesLoadingStartTimestamps;
|
||||
|
||||
@@ -49,10 +49,4 @@ const useCommunityOfflineStore = create<CommunityOfflineStore>((set) => ({
|
||||
},
|
||||
}));
|
||||
|
||||
/**
|
||||
* Back-compat exports for old naming.
|
||||
*/
|
||||
export const useSubplebbitOfflineStore = useCommunityOfflineStore;
|
||||
export const useCommunityOfflineStoreForLegacy = useCommunityOfflineStore;
|
||||
|
||||
export default useCommunityOfflineStore;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { create } from 'zustand';
|
||||
import type { Comment } from '@bitsocialnet/bitsocial-react-hooks';
|
||||
import { normalizeBoardAddress } from '../hooks/use-directories';
|
||||
import { getCommentCommunityAddress } from '../lib/utils/comment-utils';
|
||||
|
||||
interface PostNumberState {
|
||||
// Post numbers are only unique within a board, so scope by canonical community address.
|
||||
@@ -55,7 +56,7 @@ const usePostNumberStore = create<PostNumberState>((set) => ({
|
||||
for (const c of comments) {
|
||||
const num = c?.number;
|
||||
const cid = c?.cid;
|
||||
const addr = c?.communityAddress || c?.subplebbitAddress;
|
||||
const addr = getCommentCommunityAddress(c);
|
||||
if (typeof num !== 'number' || !cid || !addr) continue;
|
||||
|
||||
const existingCid = nextNumberToCid[addr]?.[num];
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { ChallengeVerification, Comment, PublishCommentOptions } from '@bitsocialnet/bitsocial-react-hooks';
|
||||
import { create } from 'zustand';
|
||||
import { alertChallengeVerificationFailed } from '../lib/utils/challenge-utils';
|
||||
import { getCommentCommunityAddress } from '../lib/utils/comment-utils';
|
||||
|
||||
type SubmitState = {
|
||||
author?: any | undefined;
|
||||
displayName?: string | undefined;
|
||||
communityAddress: string | undefined;
|
||||
subplebbitAddress: string | undefined;
|
||||
title: string | undefined;
|
||||
content: string | undefined;
|
||||
link: string | undefined;
|
||||
@@ -20,7 +20,6 @@ const usePublishPostStore = create<SubmitState>((set) => ({
|
||||
author: undefined,
|
||||
displayName: undefined,
|
||||
communityAddress: undefined,
|
||||
subplebbitAddress: undefined,
|
||||
title: undefined,
|
||||
content: undefined,
|
||||
link: undefined,
|
||||
@@ -28,8 +27,8 @@ const usePublishPostStore = create<SubmitState>((set) => ({
|
||||
publishCommentOptions: {},
|
||||
setPublishPostStore: (comment: Comment) =>
|
||||
set(() => {
|
||||
const { subplebbitAddress, author, content, link, spoiler, title } = comment;
|
||||
const communityAddress = (comment as { communityAddress?: string }).communityAddress || subplebbitAddress;
|
||||
const { author, content, link, spoiler, title } = comment;
|
||||
const communityAddress = getCommentCommunityAddress(comment);
|
||||
|
||||
const displayName = 'displayName' in comment ? comment.displayName || undefined : author?.displayName;
|
||||
|
||||
@@ -61,7 +60,6 @@ const usePublishPostStore = create<SubmitState>((set) => ({
|
||||
author: updatedAuthor,
|
||||
displayName,
|
||||
communityAddress,
|
||||
subplebbitAddress: communityAddress,
|
||||
title,
|
||||
content,
|
||||
link,
|
||||
@@ -73,7 +71,6 @@ const usePublishPostStore = create<SubmitState>((set) => ({
|
||||
set({
|
||||
author: undefined,
|
||||
displayName: undefined,
|
||||
subplebbitAddress: undefined,
|
||||
communityAddress: undefined,
|
||||
title: undefined,
|
||||
content: undefined,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { ChallengeVerification, Comment, PublishCommentOptions } from '@bitsocialnet/bitsocial-react-hooks';
|
||||
import { create } from 'zustand';
|
||||
import { alertChallengeVerificationFailed } from '../lib/utils/challenge-utils';
|
||||
import { getCommentCommunityAddress } from '../lib/utils/comment-utils';
|
||||
|
||||
type ReplyState = {
|
||||
author: { [parentCid: string]: any | undefined };
|
||||
@@ -24,7 +25,7 @@ const usePublishReplyStore = create<ReplyState>((set) => ({
|
||||
setPublishReplyStore: (comment: Comment) =>
|
||||
set((state) => {
|
||||
const { parentCid, author, content, link, spoiler } = comment;
|
||||
const communityAddress = (comment as { communityAddress?: string }).communityAddress || (comment as { subplebbitAddress?: string }).subplebbitAddress;
|
||||
const communityAddress = getCommentCommunityAddress(comment);
|
||||
|
||||
const displayName = 'displayName' in comment ? comment.displayName || undefined : author?.displayName;
|
||||
|
||||
|
||||
@@ -9,15 +9,15 @@ interface ReplyModalState {
|
||||
parentNumber: number | null;
|
||||
threadNumber: number | null;
|
||||
threadCid: string | null;
|
||||
subplebbitAddress: string | null;
|
||||
communityAddress: string | null;
|
||||
scrollY: number;
|
||||
quoteInsertRequestId: number;
|
||||
quoteInsertNumber: number | null;
|
||||
quoteInsertSelectedText: string | null;
|
||||
closeModal: () => void;
|
||||
openReplyModal: (parentCid: string, parentNumber: number | undefined, postCid: string, threadNumber: number | undefined, subplebbitAddress: string) => void;
|
||||
openReplyModal: (parentCid: string, parentNumber: number | undefined, postCid: string, threadNumber: number | undefined, communityAddress: string) => void;
|
||||
/** Open reply modal with empty textarea, no prefilled quote. Use for "Post a Reply" footer button. */
|
||||
openReplyModalEmpty: (postCid: string, threadNumber: number | undefined, subplebbitAddress: string) => void;
|
||||
openReplyModalEmpty: (postCid: string, threadNumber: number | undefined, communityAddress: string) => void;
|
||||
}
|
||||
|
||||
const getQuotedSelection = () => {
|
||||
@@ -42,7 +42,7 @@ const useReplyModalStore = create<ReplyModalState>((set, get) => ({
|
||||
parentNumber: null,
|
||||
threadNumber: null,
|
||||
threadCid: null,
|
||||
subplebbitAddress: null,
|
||||
communityAddress: null,
|
||||
scrollY: 0,
|
||||
quoteInsertRequestId: 0,
|
||||
quoteInsertNumber: null,
|
||||
@@ -62,7 +62,7 @@ const useReplyModalStore = create<ReplyModalState>((set, get) => ({
|
||||
});
|
||||
},
|
||||
|
||||
openReplyModal: (parentCid, parentNumber, postCid, threadNumber, subplebbitAddress) => {
|
||||
openReplyModal: (parentCid, parentNumber, postCid, threadNumber, communityAddress) => {
|
||||
const quotedSelection = getQuotedSelection();
|
||||
|
||||
// If the reply modal is already open, insert this quote in the current textarea at caret.
|
||||
@@ -90,12 +90,12 @@ const useReplyModalStore = create<ReplyModalState>((set, get) => ({
|
||||
threadNumber: threadNumber ?? null,
|
||||
threadCid: postCid,
|
||||
showReplyModal: true,
|
||||
subplebbitAddress,
|
||||
communityAddress,
|
||||
scrollY,
|
||||
});
|
||||
},
|
||||
|
||||
openReplyModalEmpty: (postCid, threadNumber, subplebbitAddress) => {
|
||||
openReplyModalEmpty: (postCid, threadNumber, communityAddress) => {
|
||||
useSelectedTextStore.getState().resetSelectedText();
|
||||
const isMobile = window.innerWidth <= 768;
|
||||
const scrollY = isMobile ? window.scrollY : 0;
|
||||
@@ -106,7 +106,7 @@ const useReplyModalStore = create<ReplyModalState>((set, get) => ({
|
||||
threadNumber: threadNumber ?? null,
|
||||
threadCid: postCid,
|
||||
showReplyModal: true,
|
||||
subplebbitAddress,
|
||||
communityAddress,
|
||||
scrollY,
|
||||
quoteInsertNumber: null,
|
||||
quoteInsertSelectedText: null,
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
import useCommunityOfflineStore from './use-community-offline-store';
|
||||
|
||||
type LegacySubplebbitOfflineState = {
|
||||
initialLoad: boolean;
|
||||
state?: string;
|
||||
updatedAt?: number;
|
||||
updatingState?: string;
|
||||
};
|
||||
|
||||
type LegacySubplebbitOfflineStore = {
|
||||
subplebbitOfflineState: Record<string, LegacySubplebbitOfflineState>;
|
||||
setSubplebbitOfflineState: (address: string, state: Partial<LegacySubplebbitOfflineState>) => void;
|
||||
initializesubplebbitOfflineState: (address: string) => void;
|
||||
};
|
||||
|
||||
type CommunityOfflineStoreState = {
|
||||
communityOfflineState: Record<string, LegacySubplebbitOfflineState>;
|
||||
setCommunityOfflineState: (address: string, state: Partial<LegacySubplebbitOfflineState>) => void;
|
||||
initializeCommunityOfflineState: (address: string) => void;
|
||||
};
|
||||
|
||||
const toLegacyState = (state: CommunityOfflineStoreState) => ({
|
||||
subplebbitOfflineState: state.communityOfflineState,
|
||||
setSubplebbitOfflineState: state.setCommunityOfflineState,
|
||||
initializesubplebbitOfflineState: state.initializeCommunityOfflineState,
|
||||
});
|
||||
|
||||
const useSubplebbitOfflineStore = (): LegacySubplebbitOfflineStore => {
|
||||
const state = useCommunityOfflineStore();
|
||||
return toLegacyState(state);
|
||||
};
|
||||
|
||||
const useSubplebbitOfflineStoreWithState = useSubplebbitOfflineStore as typeof useSubplebbitOfflineStore & {
|
||||
getState: () => LegacySubplebbitOfflineStore;
|
||||
};
|
||||
useSubplebbitOfflineStoreWithState.getState = () => toLegacyState(useCommunityOfflineStore.getState());
|
||||
|
||||
export { useSubplebbitOfflineStore };
|
||||
export default useSubplebbitOfflineStoreWithState;
|
||||
@@ -1,8 +0,0 @@
|
||||
import useSubplebbitStore from './use-communities-loading-start-timestamps-store';
|
||||
|
||||
const useSubplebbitLoadingStartTimestamps = (subplebbitAddresses?: string[]) => {
|
||||
const addLegacyInput = subplebbitAddresses?.map((address) => address);
|
||||
return useSubplebbitStore(addLegacyInput);
|
||||
};
|
||||
|
||||
export default useSubplebbitLoadingStartTimestamps;
|
||||
Reference in New Issue
Block a user