mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
Fix empty board loading state and browser P2P patch (#1175)
* fix(board): show loaded empty boards * fix(p2p): patch browser hooks runtime * fix(board): stop flash loading for explicit empty boards * fix(board): wait for feed on preloaded empty pages
This commit is contained in:
@@ -61,6 +61,46 @@ describe('getRawBoardThreadState', () => {
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('treats explicit empty page CIDs as a fully loaded empty board', () => {
|
||||
const community = {
|
||||
posts: {
|
||||
pageCids: {},
|
||||
pages: {},
|
||||
},
|
||||
updatedAt: 1781773422,
|
||||
} as Community;
|
||||
|
||||
expect(
|
||||
getRawBoardThreadState({
|
||||
accountId: undefined,
|
||||
communitiesPages: {} as CommunitiesPages,
|
||||
community,
|
||||
sortType: 'active',
|
||||
}),
|
||||
).toMatchObject({
|
||||
isFullyLoaded: true,
|
||||
rootThreadCids: new Set<string>(),
|
||||
});
|
||||
});
|
||||
|
||||
it('does not treat placeholder empty page CIDs as fully loaded', () => {
|
||||
const community = {
|
||||
posts: {
|
||||
pageCids: {},
|
||||
pages: {},
|
||||
},
|
||||
} as Community;
|
||||
|
||||
expect(
|
||||
getRawBoardThreadState({
|
||||
accountId: undefined,
|
||||
communitiesPages: {} as CommunitiesPages,
|
||||
community,
|
||||
sortType: 'active',
|
||||
}).isFullyLoaded,
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('walks stored board pages without importing side-effectful stores', () => {
|
||||
const community = {
|
||||
posts: {
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import type { Comment, CommunitiesPages, Community, CommunityPage } from '@bitsocial/bitsocial-react-hooks';
|
||||
|
||||
export type RawBoardThreadState = {
|
||||
hasExplicitEmptyPageCids: boolean;
|
||||
isFullyLoaded: boolean;
|
||||
rootThreadCids: Set<string>;
|
||||
};
|
||||
|
||||
const EMPTY_RAW_BOARD_THREAD_STATE: RawBoardThreadState = {
|
||||
hasExplicitEmptyPageCids: false,
|
||||
isFullyLoaded: false,
|
||||
rootThreadCids: new Set<string>(),
|
||||
};
|
||||
@@ -80,6 +82,7 @@ export const getRawBoardThreadState = ({
|
||||
|
||||
if (pages.length > 0) {
|
||||
return {
|
||||
hasExplicitEmptyPageCids: false,
|
||||
isFullyLoaded: !pages[pages.length - 1]?.nextCid,
|
||||
rootThreadCids,
|
||||
};
|
||||
@@ -88,6 +91,8 @@ export const getRawBoardThreadState = ({
|
||||
const hasPageCid = Boolean(community.posts?.pageCids?.[sortType]);
|
||||
const preloadedPages = (preloadedSortPage ? [preloadedSortPage] : []) as Array<{ comments?: Comment[]; nextCid?: string }>;
|
||||
const hasCompletePreloadedPage = !hasPageCid && preloadedPages.some((page) => Array.isArray(page?.comments)) && preloadedPages.every((page) => !page?.nextCid);
|
||||
const hasFetchedCommunityUpdate = typeof community.updatedAt === 'number' || typeof community.updateCid === 'string';
|
||||
const hasExplicitEmptyPageCids = hasFetchedCommunityUpdate && Boolean(community.posts?.pageCids && !hasPageCid);
|
||||
|
||||
if (hasCompletePreloadedPage) {
|
||||
for (const page of preloadedPages) {
|
||||
@@ -96,7 +101,8 @@ export const getRawBoardThreadState = ({
|
||||
}
|
||||
|
||||
return {
|
||||
isFullyLoaded: hasCompletePreloadedPage,
|
||||
hasExplicitEmptyPageCids,
|
||||
isFullyLoaded: hasCompletePreloadedPage || hasExplicitEmptyPageCids,
|
||||
rootThreadCids,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user