import { Link, useNavigate } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import useFeedViewSettingsStore from '../../stores/use-feed-view-settings-store'; import StyleSelector from '../style-selector/style-selector'; import footerStyles from '../footer/footer.module.css'; import styles from './board-pagination.module.css'; interface BoardPaginationProps { basePath: string; currentPage: number; search?: string; totalPages: number; /** When true, renders pagelist: [All] [1] [2] ... [10] Catalog Archive + Style select */ footerStyle?: boolean; /** When true, pagelist is never shown (multiboards always use infinite scroll) */ isMultiboard?: boolean; } const BoardPagination = ({ basePath, currentPage, search = '', totalPages, footerStyle = false, isMultiboard = false }: BoardPaginationProps) => { const { t } = useTranslation(); const navigate = useNavigate(); const enableInfiniteScroll = useFeedViewSettingsStore((state) => state.enableInfiniteScroll); const setEnableInfiniteScroll = useFeedViewSettingsStore((state) => state.setEnableInfiniteScroll); const pageHref = (page: number) => ({ pathname: page === 1 ? basePath : `${basePath}/${page}`, search }); const catalogHref = { pathname: `${basePath}/catalog`, search }; if (totalPages <= 1 && !footerStyle) { return null; } if (footerStyle) { const pageNumbers = Array.from({ length: totalPages }, (_, i) => i + 1); const archiveHref = { pathname: `${basePath}/archive`, search }; return (
{!isMultiboard && !enableInfiniteScroll && (
{currentPage > 1 && ( )} {currentPage === 1 && ( [ setEnableInfiniteScroll(true)} onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); setEnableInfiniteScroll(true); } }} > {t('all')} ] )} {pageNumbers.map((page) => ( [ {page} ] ))} {currentPage < totalPages ? ( ) : ( {t('next')} )} {t('catalog')} {t('archive')}
)}
{t('style')}:
); } const pageNumbers = Array.from({ length: totalPages }, (_, i) => i + 1); return (
{currentPage > 1 && ( )} {pageNumbers.map((page) => { const href = pageHref(page); const isCurrent = page === currentPage; return isCurrent ? ( {page} ) : ( {page} ); })} {currentPage < totalPages ? ( ) : ( {t('next')} )}
); }; export default BoardPagination;