mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(board): clarify loading fallback
This commit is contained in:
@@ -122,6 +122,23 @@ describe('use-state-string', () => {
|
|||||||
root.render(createElement(StateStringHarness, { value: { state: 'updating', updatingState: 'fetching-ipns' } }));
|
root.render(createElement(StateStringHarness, { value: { state: 'updating', updatingState: 'fetching-ipns' } }));
|
||||||
});
|
});
|
||||||
expect(latestValue).toBe('Downloading board via IPFS');
|
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', () => {
|
it('formats browser p2p single-board feed fallback states as peer downloads', () => {
|
||||||
|
|||||||
@@ -39,7 +39,27 @@ const friendlyStateNames: Record<string, string> = {
|
|||||||
'resolving-author-address': 'resolving author address',
|
'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 => {
|
const sanitizeSingleFeedLoadingState = (stateString?: string): string | undefined => {
|
||||||
if (!stateString) {
|
if (!stateString) {
|
||||||
@@ -87,21 +107,11 @@ const useStateString = (commentOrCommunity: CommentOrCommunity | undefined): str
|
|||||||
stateString += downloadingParts.join(', ') + getDownloadSourceSuffix(downloadingClientUrls, isBrowserPureP2P);
|
stateString += downloadingParts.join(', ') + getDownloadSourceSuffix(downloadingClientUrls, isBrowserPureP2P);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!stateString && commentOrCommunity?.state !== 'succeeded') {
|
if (!stateString) {
|
||||||
if (commentOrCommunity?.publishingState && commentOrCommunity?.publishingState !== 'stopped' && commentOrCommunity?.publishingState !== 'succeeded') {
|
const activeLifecycleState = getActiveLifecycleState(commentOrCommunity);
|
||||||
stateString = commentOrCommunity.publishingState;
|
if (activeLifecycleState) {
|
||||||
} else if (commentOrCommunity?.updatingState !== 'stopped' && commentOrCommunity?.updatingState !== 'succeeded') {
|
const isIpfsRelated = activeLifecycleState.includes('ipfs') || activeLifecycleState.includes('ipns');
|
||||||
stateString = commentOrCommunity?.updatingState;
|
stateString = getFriendlyStateName(activeLifecycleState);
|
||||||
}
|
|
||||||
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 (isIpfsRelated) {
|
if (isIpfsRelated) {
|
||||||
stateString += getDownloadSourceSuffix([], isBrowserPureP2P);
|
stateString += getDownloadSourceSuffix([], isBrowserPureP2P);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -696,7 +696,7 @@ describe('Board', () => {
|
|||||||
await renderBoard({ initialEntry: '/mu', routePath: '/:boardIdentifier/*' });
|
await renderBoard({ initialEntry: '/mu', routePath: '/:boardIdentifier/*' });
|
||||||
|
|
||||||
expect(container.textContent).not.toContain('no_threads');
|
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 () => {
|
it('does not show no threads while an empty board feed is still loading', async () => {
|
||||||
@@ -712,7 +712,7 @@ describe('Board', () => {
|
|||||||
await renderBoard({ initialEntry: '/mu', routePath: '/:boardIdentifier/*' });
|
await renderBoard({ initialEntry: '/mu', routePath: '/:boardIdentifier/*' });
|
||||||
|
|
||||||
expect(container.textContent).not.toContain('no_threads');
|
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 () => {
|
it('shows no threads after an empty board feed finishes loading', async () => {
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ const BoardFooter = ({
|
|||||||
}: BoardFooterProps) => {
|
}: BoardFooterProps) => {
|
||||||
const { t } = useTranslation();
|
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 isLoadedCommunityState = communityState === 'succeeded' || communityState === 'ready';
|
||||||
const canShowNoThreads = !isSingleCommunityBoard || (isLoadedCommunityState && feedState === 'succeeded');
|
const canShowNoThreads = !isSingleCommunityBoard || (isLoadedCommunityState && feedState === 'succeeded');
|
||||||
const isEmptyBoardLoading = isSingleCommunityBoard && combinedFeedLength === 0 && !canShowNoThreads && communityState !== 'failed';
|
const isEmptyBoardLoading = isSingleCommunityBoard && combinedFeedLength === 0 && !canShowNoThreads && communityState !== 'failed';
|
||||||
|
|||||||
Reference in New Issue
Block a user