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
@@ -14,7 +14,7 @@ const testState = vi.hoisted(() => ({
},
resolvedAddress: 'music-posting.eth',
shortAddress: 'mu',
subplebbitAddress: 'music-posting.eth',
communityAddress: 'music-posting.eth',
}));
vi.mock('react-router-dom', async () => {
@@ -26,8 +26,8 @@ vi.mock('react-router-dom', async () => {
};
});
vi.mock('../../../hooks/use-stable-subplebbit', () => ({
useSubplebbitField: (_address: string, selector: (subplebbit: { address?: string; shortAddress?: string }) => string | undefined) =>
vi.mock('../../../hooks/use-stable-community', () => ({
useCommunityField: (_address: string, selector: (community: { address?: string; shortAddress?: string }) => string | undefined) =>
selector({
address: testState.resolvedAddress,
shortAddress: testState.shortAddress,
@@ -39,7 +39,7 @@ vi.mock('../../../hooks/use-directories', () => ({
}));
vi.mock('../../../lib/utils/route-utils', () => ({
getSubplebbitAddress: () => testState.subplebbitAddress,
getSubplebbitAddress: () => testState.communityAddress,
}));
vi.mock('../../home', () => ({
@@ -68,7 +68,7 @@ describe('NotFound', () => {
};
testState.resolvedAddress = 'music-posting.eth';
testState.shortAddress = 'mu';
testState.subplebbitAddress = 'music-posting.eth';
testState.communityAddress = 'music-posting.eth';
container = document.createElement('div');
document.body.appendChild(container);
@@ -96,7 +96,7 @@ describe('NotFound', () => {
};
testState.resolvedAddress = '';
testState.shortAddress = '';
testState.subplebbitAddress = '';
testState.communityAddress = '';
await renderNotFound();
+5 -5
View File
@@ -1,5 +1,5 @@
import { Link, useLocation } from 'react-router-dom';
import { useSubplebbitField } from '../../hooks/use-stable-subplebbit';
import { useCommunityField } from '../../hooks/use-stable-community';
import { useDirectories } from '../../hooks/use-directories';
import { getSubplebbitAddress } from '../../lib/utils/route-utils';
import { HomeLogo } from '../home';
@@ -12,10 +12,10 @@ const NotFound = () => {
const pathParts = location.pathname.split('/').filter(Boolean);
const boardIdentifier = pathParts[0] && pathParts[0] !== 'not-found' && pathParts[0] !== 'faq' ? pathParts[0] : '';
const directories = useDirectories();
const subplebbitAddress = boardIdentifier ? getSubplebbitAddress(boardIdentifier, directories) : '';
const communityAddress = boardIdentifier ? getSubplebbitAddress(boardIdentifier, directories) : '';
// Only subscribe to address and shortAddress to avoid rerenders from updatingState changes
const address = useSubplebbitField(subplebbitAddress, (subplebbit) => subplebbit?.address);
const shortAddress = useSubplebbitField(subplebbitAddress, (subplebbit) => subplebbit?.shortAddress);
const address = useCommunityField(communityAddress, (community) => community?.address);
const shortAddress = useCommunityField(communityAddress, (community) => community?.shortAddress);
return (
<div className={styles.wrapper}>
@@ -32,7 +32,7 @@ const NotFound = () => {
<>
<br />
<div className={styles.backToBoard}>
[<Link to={`/${boardIdentifier || subplebbitAddress}`}>Back to p/{shortAddress || subplebbitAddress}</Link>]
[<Link to={`/${boardIdentifier || communityAddress}`}>Back to p/{shortAddress || communityAddress}</Link>]
</div>
</>
)}