Merge branch 'codex/fix/verbose-board-loading-feed'

This commit is contained in:
Tommaso Casaburi
2026-05-21 18:02:06 +07:00
4 changed files with 46 additions and 19 deletions
@@ -122,6 +122,23 @@ describe('use-state-string', () => {
root.render(createElement(StateStringHarness, { value: { state: 'updating', updatingState: 'fetching-ipns' } }));
});
expect(latestValue).toBe('Downloading board via IPFS');
act(() => {
root.render(createElement(StateStringHarness, { value: { publishingState: 'fetching-ipfs' } }));
});
expect(latestValue).toBe('Downloading thread via IPFS');
});
it('formats raw community loading states when no client or update states are available', () => {
testState.community = {
state: 'fetching-community-ipfs',
};
act(() => {
root.render(createElement(FeedStateStringHarness, { addresses: ['music-posting.eth'] }));
});
expect(latestValue).toBe('Downloading board via IPFS');
});
it('formats browser p2p single-board feed fallback states as peer downloads', () => {
+26 -16
View File
@@ -39,7 +39,27 @@ const friendlyStateNames: Record<string, string> = {
'resolving-author-address': 'resolving author address',
};
const getFriendlyStateName = (state: string): string => friendlyStateNames[state] || state.replaceAll('-', ' ');
const getFriendlyStateName = (state: string): string =>
friendlyStateNames[state] ||
state
.replaceAll('-', ' ')
.replace('ipfs', 'thread')
.replace('ipns', 'community')
.replace('fetching', 'downloading')
.replace('community community', 'board')
.replace('downloading community', 'downloading board');
const inactiveLifecycleStates = new Set(['failed', 'ready', 'stopped', 'succeeded']);
const isActiveLifecycleState = (state?: string): state is string => Boolean(state && !inactiveLifecycleStates.has(state));
const getActiveLifecycleState = (commentOrCommunity: CommentOrCommunity | undefined): string | undefined => {
if (!commentOrCommunity || commentOrCommunity.state === 'succeeded') {
return;
}
return [commentOrCommunity.publishingState, commentOrCommunity.updatingState, commentOrCommunity.state].find(isActiveLifecycleState);
};
const sanitizeSingleFeedLoadingState = (stateString?: string): string | undefined => {
if (!stateString) {
@@ -87,21 +107,11 @@ const useStateString = (commentOrCommunity: CommentOrCommunity | undefined): str
stateString += downloadingParts.join(', ') + getDownloadSourceSuffix(downloadingClientUrls, isBrowserPureP2P);
}
if (!stateString && commentOrCommunity?.state !== 'succeeded') {
if (commentOrCommunity?.publishingState && commentOrCommunity?.publishingState !== 'stopped' && commentOrCommunity?.publishingState !== 'succeeded') {
stateString = commentOrCommunity.publishingState;
} else if (commentOrCommunity?.updatingState !== 'stopped' && commentOrCommunity?.updatingState !== 'succeeded') {
stateString = commentOrCommunity?.updatingState;
}
if (stateString) {
const isIpfsRelated = stateString.includes('ipfs') || stateString.includes('ipns');
stateString = stateString
.replaceAll('-', ' ')
.replace('ipfs', 'thread')
.replace('ipns', 'community')
.replace('fetching', 'downloading')
.replace('community community', 'board')
.replace('downloading community', 'downloading board');
if (!stateString) {
const activeLifecycleState = getActiveLifecycleState(commentOrCommunity);
if (activeLifecycleState) {
const isIpfsRelated = activeLifecycleState.includes('ipfs') || activeLifecycleState.includes('ipns');
stateString = getFriendlyStateName(activeLifecycleState);
if (isIpfsRelated) {
stateString += getDownloadSourceSuffix([], isBrowserPureP2P);
}
+2 -2
View File
@@ -765,7 +765,7 @@ describe('Board', () => {
await renderBoard({ initialEntry: '/mu', routePath: '/:boardIdentifier/*' });
expect(container.textContent).not.toContain('no_threads');
expect(container.querySelector('[data-testid="loading-ellipsis"]')?.textContent).toBe('loading_feed');
expect(container.querySelector('[data-testid="loading-ellipsis"]')?.textContent).toBe('downloading_board');
});
it('does not show no threads while an empty board feed is still loading', async () => {
@@ -781,7 +781,7 @@ describe('Board', () => {
await renderBoard({ initialEntry: '/mu', routePath: '/:boardIdentifier/*' });
expect(container.textContent).not.toContain('no_threads');
expect(container.querySelector('[data-testid="loading-ellipsis"]')?.textContent).toBe('loading_feed');
expect(container.querySelector('[data-testid="loading-ellipsis"]')?.textContent).toBe('downloading_board');
});
it('shows no threads after an empty board feed finishes loading', async () => {
+1 -1
View File
@@ -89,7 +89,7 @@ const BoardFooter = ({
}: BoardFooterProps) => {
const { t } = useTranslation();
const loadingStateString = useFeedStateString(communityAddresses) || (combinedFeedLength === 0 ? t('loading_feed') : t('looking_for_more_posts'));
const loadingStateString = useFeedStateString(communityAddresses) || (combinedFeedLength === 0 ? t('downloading_board') : t('looking_for_more_posts'));
const isLoadedCommunityState = communityState === 'succeeded' || communityState === 'ready';
const canShowNoThreads = !isSingleCommunityBoard || (isLoadedCommunityState && feedState === 'succeeded');
const isEmptyBoardLoading = isSingleCommunityBoard && combinedFeedLength === 0 && !canShowNoThreads && communityState !== 'failed';