diff --git a/app/(admin)/admin/processing/scores/page.tsx b/app/(admin)/admin/processing/scores/page.tsx index dc234ae..01cda59 100644 --- a/app/(admin)/admin/processing/scores/page.tsx +++ b/app/(admin)/admin/processing/scores/page.tsx @@ -1,8 +1,8 @@ "use client"; -import { Filter, ListChecks, RefreshCw, Search } from "lucide-react"; +import { ChevronLeft, ChevronRight, ChevronsLeft, ChevronsRight, Filter, ListChecks, RefreshCw, Search } from "lucide-react"; import type { ComponentProps } from "react"; -import { useMemo, useState } from "react"; +import { useEffect, useMemo, useState } from "react"; import { AddScoreProcessingDialog } from "@/components/Admin/ScoreProcessing/AddScoreProcessingDialog"; import { ScoreProcessingTaskCard } from "@/components/Admin/ScoreProcessing/ScoreProcessingTaskCard"; @@ -31,6 +31,7 @@ export default function Page() { const [showFilters, setShowFilters] = useState(false); const [filters, setFilters] = useState({}); + const [page, setPage] = useState(1); const scoreIdFilter = tryParseNumber(searchByScoreIdValue) ?? null; const taskIdFilter = tryParseNumber(searchByTaskIdValue) ?? null; @@ -44,11 +45,14 @@ export default function Page() { [filters, scoreIdFilter, taskIdFilter], ); - const { data, error, size, setSize, isLoading, mutate } = useScoreProcessingTasks(combinedFilters, PAGE_SIZE, { - refreshInterval: 10_000, - revalidateOnFocus: false, - keepPreviousData: true, - }); + const { data, error, isLoading, mutate } = useScoreProcessingTasks( + useMemo(() => ({ ...combinedFilters, page, limit: PAGE_SIZE }), [combinedFilters, page]), + { + refreshInterval: 10_000, + revalidateOnFocus: false, + keepPreviousData: true, + }, + ); const { data: stats, error: statsError, mutate: mutateStats } = useScoreProcessingStats({ refreshInterval: 10_000, @@ -56,10 +60,18 @@ export default function Page() { keepPreviousData: true, }); - const tasks = data?.flatMap(page => page.tasks) ?? []; - const totalCount = data?.find(item => item.total_count !== undefined)?.total_count ?? 0; + const tasks = data?.tasks ?? []; + const totalCount = data?.total_count ?? 0; + const totalPages = Math.max(1, Math.ceil(totalCount / PAGE_SIZE)); + + useEffect(() => { + setPage(1); + }, [combinedFilters]); - const isLoadingMore = Boolean(isLoading || (size > 0 && data && data[size - 1] === undefined)); + useEffect(() => { + if (!isLoading && data && page > totalPages) + setPage(totalPages); + }, [data, isLoading, page, totalPages]); const activeFilterCount = Object.values(filters).filter( value => value != null, @@ -67,17 +79,19 @@ export default function Page() { const handleFilterByScoreIdChange = (value: string) => { setSearchByScoreIdQuery(value); - setSize(1); }; const handleFilterByTaskIdChange = (value: string) => { setSearchByTaskIdQuery(value); - setSize(1); }; const handleApplyFilters = (nextFilters: ScoreProcessingTaskFilters) => { setFilters(nextFilters); - setSize(1); + }; + + const handleTaskChanged = () => { + mutate(); + mutateStats(); }; return ( @@ -105,14 +119,21 @@ export default function Page() {

setSize(size + 1)} - onTaskChanged={mutate} + onTaskChanged={handleTaskChanged} tasks={tasks} - totalCount={totalCount} - error={error} /> + + {totalCount > 0 && ( + + )} ); } @@ -265,19 +286,13 @@ function ScoreProcessingFiltersPanel({ function ScoreProcessingTaskList({ error, isLoading, - isLoadingMore, - onLoadMore, onTaskChanged, tasks, - totalCount, }: { error: ReturnType["error"]; isLoading: boolean; - isLoadingMore: boolean; - onLoadMore: () => void; onTaskChanged: () => void; tasks: ScoreProcessingTaskResponse[]; - totalCount: number; }) { if (error) { return ( @@ -313,21 +328,60 @@ function ScoreProcessingTaskList({ } return ( - <> -
- {tasks.map((task, idx) => ( - // eslint-disable-next-line @eslint-react/no-array-index-key -- For pagination. - - ))} -
+
+ {tasks.map(task => ( + + ))} +
+ ); +} - {tasks.length < totalCount && ( -
- -
- )} - +function ScoreProcessingPagination({ + isLoading, + onPageChange, + page, + totalCount, + totalPages, +}: { + isLoading: boolean; + onPageChange: (page: number) => void; + page: number; + totalCount: number; + totalPages: number; +}) { + const isFirstPage = page <= 1; + const isLastPage = page >= totalPages; + + return ( +
+

+ Showing + {" "} + {Math.min((page - 1) * PAGE_SIZE + 1, totalCount)} + {" "} + - + {" "} + {Math.min(page * PAGE_SIZE, totalCount)} + {" "} + of + {" "} + {totalCount} +

+ +
+ + + + +
+
); } diff --git a/components/Admin/ScoreProcessing/ScoreProcessingTaskCard.tsx b/components/Admin/ScoreProcessing/ScoreProcessingTaskCard.tsx index 87c4b60..c43bdbd 100644 --- a/components/Admin/ScoreProcessing/ScoreProcessingTaskCard.tsx +++ b/components/Admin/ScoreProcessing/ScoreProcessingTaskCard.tsx @@ -77,7 +77,9 @@ export function ScoreProcessingTaskCard({ task, onChanged }: ScoreProcessingTask
{task.status} {`ID: ${task.id}`} - {task.score?.score.game_mode_extended} + {task.score?.score && ( + {task.score.score.game_mode_extended} + )} {task.task_type} {task.retry_count > 0 && ( @@ -93,11 +95,17 @@ export function ScoreProcessingTaskCard({ task, onChanged }: ScoreProcessingTask )}

- {beatmap ? `${beatmap.artist} - ${beatmap.title}` : `Beatmap #${score?.beatmap_id ?? "?"}`} -

-

- {score?.mods} + {beatmap + ? `${beatmap.artist} - ${beatmap.title}` + : score + ? `Beatmap #${score.beatmap_id}` + : "Score data unavailable"}

+ {score?.mods && ( +

+ {score.mods} +

+ )}
@@ -105,7 +113,7 @@ export function ScoreProcessingTaskCard({ task, onChanged }: ScoreProcessingTask )} - Score ID: {task.score_id} + Score ID: {task.score_id ?? "—"}
@@ -119,12 +127,14 @@ export function ScoreProcessingTaskCard({ task, onChanged }: ScoreProcessingTask
- + {task.score_id != null && ( + + )} {isFailed && (