import React, { useCallback, useEffect, useState } from 'react';
import { useTranslation } from 'next-i18next';
import Link from 'next/link';
import { apiv3Get } from '~/client/util/apiv3-client';
import { IPageHasId } from '~/interfaces/page';
import { useCurrentPagePath } from '~/stores/page';
import { useTimelineOptions } from '~/stores/renderer';
import { RevisionLoader } from './Page/RevisionLoader';
import PaginationWrapper from './PaginationWrapper';
import styles from './PageTimeline.module.scss';
type TimelineCardProps = {
page: IPageHasId,
}
const TimelineCard = ({ page }: TimelineCardProps): JSX.Element => {
const { data: rendererOptions } = useTimelineOptions(page.path);
return (
{ rendererOptions != null && (
) }
);
};
export const PageTimeline = (): JSX.Element => {
const [activePage, setActivePage] = useState(1);
const [totalPageItems, setTotalPageItems] = useState(0);
const [limit, setLimit] = useState(10);
const [pages, setPages] = useState(null);
const { data: currentPagePath } = useCurrentPagePath();
const { t } = useTranslation();
const handlePage = useCallback(async(selectedPage: number) => {
if (currentPagePath == null) { return }
const res = await apiv3Get('/pages/list', { path: currentPagePath, selectedPage });
setTotalPageItems(res.data.totalCount);
setPages(res.data.pages);
setLimit(res.data.limit);
setActivePage(selectedPage);
}, [currentPagePath]);
useEffect(() => {
handlePage(1);
}, [handlePage]);
if (pages == null || pages.length === 0) {
return (
{/* eslint-disable-next-line react/no-danger */}
{t('custom_navigation.no_page_list')}
);
}
return (
);
};