mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
feat(board): default pagination with optional infinite scroll and URL-based page routing
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { useMemo } from 'react';
|
||||
import type { DirectoryCommunity } from './use-directories';
|
||||
import { computeGuiPostsPerPage, getBoardFeedPageSizeConstants, type CommunityWithPostsPerPage } from '../lib/utils/board-feed-pagination';
|
||||
|
||||
export 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]);
|
||||
};
|
||||
@@ -9,6 +9,7 @@ export interface DirectoriesMetadata {
|
||||
}
|
||||
|
||||
export interface DirectoryFeatures {
|
||||
postsPerPage?: number;
|
||||
pseudonymityMode?: string;
|
||||
nsfw?: boolean;
|
||||
noSpoilers?: boolean;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import assert from 'assert';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { isBoardFeedPageNumber } from '../lib/utils/route-utils';
|
||||
|
||||
// the timestamp the last time the user visited
|
||||
const lastVisitTimestamp = localStorage.getItem('5chanLastVisitTimestamp');
|
||||
@@ -110,6 +111,11 @@ const useTimeFilter = () => {
|
||||
const params = useParams();
|
||||
let timeFilterName = params.timeFilterName;
|
||||
|
||||
// Ignore when param is a board feed page number (e.g. /all/3, /biz/2)
|
||||
if (timeFilterName && isBoardFeedPageNumber(timeFilterName)) {
|
||||
timeFilterName = undefined;
|
||||
}
|
||||
|
||||
// the default time filter is the last visit time filter
|
||||
if (!timeFilterName) {
|
||||
timeFilterName = lastVisitTimeFilterName;
|
||||
|
||||
Reference in New Issue
Block a user