import { useState } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import type { JSX } from 'react'; import { FIXES_PER_PAGE } from '../../shared/api/endpoints'; import { useNow } from '../../shared/lib/clock'; import { Empty } from '../../shared/ui/Empty'; import { LoadError } from '../../shared/ui/LoadError'; import { Skeleton } from '../../shared/ui/Skeleton'; import { HistoryEntry } from './HistoryEntry'; import { HistoryPager } from './HistoryPager'; import { useFixes } from './historyQueries'; const SLOW_REFRESH_MILLISECONDS = 30000; const FIRST_PAGE = 1; export function HistoryView(): JSX.Element { const now = useNow( SLOW_REFRESH_MILLISECONDS ); const [ page, setPage ] = useState( FIRST_PAGE ); const fixesQuery = useFixes( page ); const fixes = fixesQuery.data?.items ?? []; const pageCount = Math.ceil( ( fixesQuery.data?.total ?? 0 ) / FIXES_PER_PAGE ); return (

{ __( 'History', 'aiplaz-link-checkup' ) }

{ __( 'Every fix is listed here. A revision of each post was saved, so you can undo any of them.', 'aiplaz-link-checkup' ) }

{ fixesQuery.isPending && } { fixesQuery.isError && fixesQuery.data === undefined && ( { void fixesQuery.refetch(); } } /> ) } { fixesQuery.data !== undefined && (
{ fixes.map( ( fix ) => ( ) ) } { fixes.length === 0 && ( { __( 'When you fix or ignore a link, it shows up here.', 'aiplaz-link-checkup' ) } ) } { pageCount > 1 && ( ) }
) }
); }