mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(board-buttons): hide catalog controls on flash upload boards
Flash boards do not use catalog view, so hide catalog links and OP search without leaving empty bracket placeholders in desktop board controls.
This commit is contained in:
@@ -9,6 +9,7 @@ import BoardPagination from '../board-pagination';
|
||||
const act = (React as { act?: (cb: () => void | Promise<void>) => void | Promise<void> }).act as (cb: () => void | Promise<void>) => void | Promise<void>;
|
||||
|
||||
const testState = vi.hoisted(() => ({
|
||||
directories: [] as Array<{ address: string; directoryCode?: string; title?: string }>,
|
||||
enableInfiniteScroll: false,
|
||||
navigateMock: vi.fn(),
|
||||
setEnableInfiniteScrollMock: vi.fn(),
|
||||
@@ -36,6 +37,12 @@ vi.mock('../../../stores/use-feed-view-settings-store', () => ({
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock('../../../hooks/use-directories', () => ({
|
||||
findDirectoryByAddress: (directories: Array<{ address: string; directoryCode?: string; title?: string }>, address?: string) =>
|
||||
directories.find((entry) => address && (entry.address === address || entry.directoryCode === address || (entry.title && entry.title.includes(`/${address}/`)))),
|
||||
useDirectories: () => testState.directories,
|
||||
}));
|
||||
|
||||
vi.mock('../../style-selector/style-selector', () => ({
|
||||
default: () => createElement('div', { 'data-testid': 'style-selector' }, 'style-selector'),
|
||||
}));
|
||||
@@ -53,6 +60,7 @@ describe('BoardPagination', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
testState.enableInfiniteScroll = false;
|
||||
testState.directories = [{ address: 'music-posting.eth', directoryCode: 'mu', title: '/mu/ - Music' }];
|
||||
|
||||
container = document.createElement('div');
|
||||
document.body.appendChild(container);
|
||||
@@ -116,6 +124,14 @@ describe('BoardPagination', () => {
|
||||
expect(container.textContent).not.toContain('archive');
|
||||
});
|
||||
|
||||
it('hides the catalog link on flash upload boards', () => {
|
||||
testState.directories = [{ address: 'flash-posting.bso', directoryCode: 'f', title: '/f/ - Flash' }];
|
||||
renderPagination(createElement(BoardPagination, { basePath: '/f', currentPage: 1, footerStyle: true, totalPages: 3 }));
|
||||
|
||||
expect(container.textContent).not.toContain('catalog');
|
||||
expect(container.textContent).toContain('archive');
|
||||
});
|
||||
|
||||
it('returns nothing for single-page non-footer pagination', () => {
|
||||
renderPagination(createElement(BoardPagination, { basePath: '/mu', currentPage: 1, totalPages: 1 }));
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { Link, useNavigate } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import useFeedViewSettingsStore from '../../stores/use-feed-view-settings-store';
|
||||
import { useDirectories } from '../../hooks/use-directories';
|
||||
import { isFlashBoardRoute } from '../../lib/utils/route-utils';
|
||||
import StyleSelector from '../style-selector/style-selector';
|
||||
import footerStyles from '../footer/footer.module.css';
|
||||
import styles from './board-pagination.module.css';
|
||||
@@ -19,10 +21,13 @@ interface BoardPaginationProps {
|
||||
const BoardPagination = ({ basePath, currentPage, search = '', totalPages, footerStyle = false, isMultiboard = false }: BoardPaginationProps) => {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const directories = useDirectories();
|
||||
const enableInfiniteScroll = useFeedViewSettingsStore((state) => state.enableInfiniteScroll);
|
||||
const setEnableInfiniteScroll = useFeedViewSettingsStore((state) => state.setEnableInfiniteScroll);
|
||||
|
||||
const pageHref = (page: number) => ({ pathname: page === 1 ? basePath : `${basePath}/${page}`, search });
|
||||
const boardIdentifier = basePath.replace(/^\//, '').split('/')[0];
|
||||
const showCatalogLink = !isFlashBoardRoute(boardIdentifier, directories);
|
||||
const catalogHref = { pathname: `${basePath}/catalog`, search };
|
||||
|
||||
if (totalPages <= 1 && !footerStyle) {
|
||||
@@ -78,9 +83,11 @@ const BoardPagination = ({ basePath, currentPage, search = '', totalPages, foote
|
||||
) : (
|
||||
<span className={styles.footerNavPlainDisabled}>{t('next')}</span>
|
||||
)}
|
||||
<Link to={catalogHref} className={styles.pagelistSeparatorLink}>
|
||||
{t('catalog')}
|
||||
</Link>
|
||||
{showCatalogLink && (
|
||||
<Link to={catalogHref} className={styles.pagelistSeparatorLink}>
|
||||
{t('catalog')}
|
||||
</Link>
|
||||
)}
|
||||
<Link to={archiveHref} className={styles.pagelistSeparatorLink}>
|
||||
{t('archive')}
|
||||
</Link>
|
||||
|
||||
Reference in New Issue
Block a user