From 97a2897c919b76ad5868d361c2e4e6112e40c28b Mon Sep 17 00:00:00 2001 From: richardscull <106016833+richardscull@users.noreply.github.com> Date: Sun, 1 Nov 2026 19:29:56 +0200 Subject: [PATCH 1/2] fix: render score processing tasks without saved scores and paginate the list Failed tasks whose beatmap is missing have no score or score_id, which made the card show an empty grade/gamemode badge, a literal null score id and an /admin/scores/null link. Guard those fields and show an explicit label instead. Replace the infinite/load-more list with real page navigation backed by the existing page/limit API, resetting to page 1 on filter changes and clamping when the total shrinks. --- app/(admin)/admin/processing/scores/page.tsx | 109 +++++++++++------- .../ScoreProcessingTaskCard.tsx | 34 ++++-- .../useScoreProcessingTasks.ts | 54 ++++----- lib/types/api/types.gen.ts | 4 +- lib/types/api/zod.gen.ts | 4 +- 5 files changed, 120 insertions(+), 85 deletions(-) diff --git a/app/(admin)/admin/processing/scores/page.tsx b/app/(admin)/admin/processing/scores/page.tsx index dc234ae..07d1020 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, 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)); - const isLoadingMore = Boolean(isLoading || (size > 0 && data && data[size - 1] === undefined)); + useEffect(() => { + setPage(1); + }, [combinedFilters]); + + 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,20 @@ export default function Page() {

setSize(size + 1)} - onTaskChanged={mutate} + onTaskChanged={handleTaskChanged} tasks={tasks} - totalCount={totalCount} - error={error} /> + + {totalCount > 0 && ( + + )} ); } @@ -265,19 +285,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 +327,38 @@ 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, + totalPages, +}: { + isLoading: boolean; + onPageChange: (page: number) => void; + page: number; + totalPages: number; +}) { + return ( +
+ + + {`Page ${page} of ${totalPages}`} + + +
); } 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 && ( - - {`Page ${page} of ${totalPages}`} - - +
+

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

+ +
+ + + + +
); }