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:
Tommaso Casaburi
2026-03-13 13:25:10 +08:00
committed by GitHub
parent 9dc4d96d27
commit d7703953fb
105 changed files with 2659 additions and 1491 deletions
+3 -3
View File
@@ -25,7 +25,7 @@ const testState = vi.hoisted(() => ({
vi.mock('@bitsocialnet/bitsocial-react-hooks', () => ({
useAccount: () => testState.account,
useAccountSubplebbits: () => ({ accountSubplebbits: testState.accountSubplebbits }),
useAccountCommunities: () => ({ accountCommunities: testState.accountSubplebbits }),
}));
vi.mock('@bitsocialnet/bitsocial-react-hooks/dist/lib/utils', () => ({
@@ -37,8 +37,8 @@ vi.mock('../use-directories', () => ({
useDirectoryByAddress: (address: string | undefined) => (address ? testState.directoryLookup[address] : undefined),
}));
vi.mock('../use-stable-subplebbit', () => ({
useSubplebbitField: (_address: string | undefined, selector: (subplebbit: unknown) => unknown) => selector(testState.subplebbitSnapshot),
vi.mock('../use-stable-community', () => ({
useCommunityField: (_address: string | undefined, selector: (community: unknown) => unknown) => selector(testState.subplebbitSnapshot),
}));
let latestValue: unknown;
@@ -26,15 +26,15 @@ vi.mock('react-i18next', () => ({
}),
}));
vi.mock('../../stores/use-subplebbit-offline-store', () => ({
vi.mock('../../stores/use-community-offline-store', () => ({
default: () => ({
initializesubplebbitOfflineState: testState.initializeMock,
setSubplebbitOfflineState: testState.setOfflineStateMock,
subplebbitOfflineState: testState.subplebbitOfflineState,
initializeCommunityOfflineState: testState.initializeMock,
setCommunityOfflineState: testState.setOfflineStateMock,
communityOfflineState: testState.subplebbitOfflineState,
}),
}));
vi.mock('../../stores/use-subplebbits-loading-start-timestamps-store', () => ({
vi.mock('../../stores/use-communities-loading-start-timestamps-store', () => ({
default: (addresses?: string[]) => {
testState.requestedAddresses = addresses;
return testState.loadingTimestamps;
@@ -17,7 +17,7 @@ vi.mock('../use-current-time', () => ({
useCurrentTime: () => testState.currentTime,
}));
vi.mock('../../stores/use-subplebbits-loading-start-timestamps-store', () => ({
vi.mock('../../stores/use-communities-loading-start-timestamps-store', () => ({
default: (addresses?: string[]) => {
testState.requestedAddresses = addresses;
return testState.loadingTimestamps;
@@ -86,7 +86,7 @@ describe('usePostPageNumber', () => {
testState.feedsOptions = {
boardFeed: {
sortType: 'active',
subplebbitAddresses: ['music.eth'],
communityAddresses: ['music.eth'],
},
};
testState.loadedFeeds = {
@@ -97,7 +97,7 @@ describe('usePostPageNumber', () => {
expect(testState.preloadOptions).toEqual({
postsPerPage: 20,
sortType: 'active',
subplebbitAddresses: ['music.eth'],
communityAddresses: ['music.eth'],
});
});
@@ -108,7 +108,7 @@ describe('usePostPageNumber', () => {
expect(testState.preloadOptions).toEqual({
postsPerPage: 20,
sortType: 'active',
subplebbitAddresses: ['music.eth'],
communityAddresses: ['music.eth'],
});
});
@@ -8,13 +8,13 @@ import { useStableSubplebbit, useSubplebbitField } from '../use-stable-subplebbi
const act = (React as { act?: (cb: () => void | Promise<void>) => void | Promise<void> }).act as (cb: () => void | Promise<void>) => void | Promise<void>;
const testState = vi.hoisted(() => ({
subplebbits: {} as Record<string, unknown>,
communities: {} as Record<string, unknown>,
}));
vi.mock('@bitsocialnet/bitsocial-react-hooks/dist/stores/subplebbits', () => ({
default: (selector: (state: { subplebbits: typeof testState.subplebbits }) => unknown) =>
vi.mock('@bitsocialnet/bitsocial-react-hooks/dist/stores/communities', () => ({
default: (selector: (state: { communities: typeof testState.communities }) => unknown) =>
selector({
subplebbits: testState.subplebbits,
communities: testState.communities,
}),
}));
@@ -40,7 +40,7 @@ describe('use-stable-subplebbit', () => {
beforeEach(() => {
latestValue = undefined;
renderCount = 0;
testState.subplebbits = {};
testState.communities = {};
container = document.createElement('div');
document.body.appendChild(container);
@@ -53,7 +53,7 @@ describe('use-stable-subplebbit', () => {
});
it('resolves alias board addresses when the store key uses a different suffix', () => {
testState.subplebbits = {
testState.communities = {
'international-sfw.bso': {
address: 'international-sfw.bso',
roles: {
@@ -74,7 +74,7 @@ describe('use-stable-subplebbit', () => {
});
it('prefers an exact key match when both exact and alias variants are present', () => {
testState.subplebbits = {
testState.communities = {
'business.eth': {
address: 'business.eth',
title: '/biz/ - Exact',
+13 -13
View File
@@ -9,23 +9,23 @@ const act = (React as { act?: (cb: () => void | Promise<void>) => void | Promise
const testState = vi.hoisted(() => ({
clientsStates: {} as Record<string, string[]>,
subplebbit: undefined as
community: undefined as
| {
publishingState?: string;
state?: string;
updatingState?: string;
}
| undefined,
subplebbitsStates: {} as Record<string, { clientUrls: string[]; subplebbitAddresses: string[] }>,
communitiesStates: {} as Record<string, { clientUrls: string[]; communityAddresses: string[] }>,
}));
vi.mock('@bitsocialnet/bitsocial-react-hooks', () => ({
useClientsStates: () => ({
states: testState.clientsStates,
}),
useSubplebbit: () => testState.subplebbit,
useSubplebbitsStates: () => ({
states: testState.subplebbitsStates,
useCommunity: () => testState.community,
useCommunitiesStates: () => ({
states: testState.communitiesStates,
}),
}));
@@ -63,8 +63,8 @@ describe('use-state-string', () => {
beforeEach(() => {
latestValue = undefined;
testState.clientsStates = {};
testState.subplebbit = undefined;
testState.subplebbitsStates = {};
testState.community = undefined;
testState.communitiesStates = {};
container = document.createElement('div');
document.body.appendChild(container);
root = createRoot(container);
@@ -101,7 +101,7 @@ describe('use-state-string', () => {
});
it('sanitizes single-board feed state strings to board wording', () => {
testState.subplebbit = {
testState.community = {
state: 'updating',
updatingState: 'fetching-ipfs',
};
@@ -114,22 +114,22 @@ describe('use-state-string', () => {
});
it('aggregates multi-board feed states across address resolution, threads, and pages', () => {
testState.subplebbitsStates = {
testState.communitiesStates = {
'fetching-ipfs': {
clientUrls: ['https://ipfs.io'],
subplebbitAddresses: ['music-posting.eth'],
communityAddresses: ['music-posting.eth'],
},
'fetching-ipns': {
clientUrls: ['https://gateway.example.com'],
subplebbitAddresses: ['music-posting.eth', 'tech-posting.eth'],
communityAddresses: ['music-posting.eth', 'tech-posting.eth'],
},
'page-1': {
clientUrls: ['https://gateway.example.com', 'https://ipfs.io'],
subplebbitAddresses: ['music-posting.eth'],
communityAddresses: ['music-posting.eth'],
},
'resolving-address': {
clientUrls: ['https://ens.example.com'],
subplebbitAddresses: ['music-posting.eth', 'tech-posting.eth'],
communityAddresses: ['music-posting.eth', 'tech-posting.eth'],
},
};