mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
21 lines
971 B
TypeScript
21 lines
971 B
TypeScript
import { useMemo } from 'react';
|
|
import type { DirectoryCommunity } from './use-directories';
|
|
import { computeGuiPostsPerPage, getBoardFeedPageSizeConstants, type CommunityWithPostsPerPage } from '../lib/utils/board-feed-pagination';
|
|
|
|
type BoardFeedPageSize = ReturnType<typeof getBoardFeedPageSizeConstants>;
|
|
|
|
/**
|
|
* Compute board feed page-size values from directory community.
|
|
*
|
|
* - Single directory board: uses community.features.postsPerPage when valid numeric > 0
|
|
* - Missing metadata, non-directory board, /all, /subs, /mod: fallback 15
|
|
*
|
|
* Returns: guiPostsPerPage, maxGuiPages (10), paginationFeedPostsPerPage, infiniteFeedPostsPerPage
|
|
*/
|
|
export const useBoardFeedPageSize = (community?: DirectoryCommunity | null): BoardFeedPageSize => {
|
|
return useMemo(() => {
|
|
const guiPostsPerPage = computeGuiPostsPerPage(community as CommunityWithPostsPerPage | null | undefined);
|
|
return getBoardFeedPageSizeConstants(guiPostsPerPage);
|
|
}, [community]);
|
|
};
|