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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user