From dbfb4307fbcbb3cc32f18b87e71ef4bc4adc2c67 Mon Sep 17 00:00:00 2001 From: Yared Yemane Date: Tue, 7 Apr 2026 03:38:18 -0700 Subject: [PATCH] fetch practice integration fix --- .../PracticeDetailsPage.tsx | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/pages/content-management/PracticeDetailsPage.tsx b/src/pages/content-management/PracticeDetailsPage.tsx index 2cc433a..0839501 100644 --- a/src/pages/content-management/PracticeDetailsPage.tsx +++ b/src/pages/content-management/PracticeDetailsPage.tsx @@ -42,18 +42,34 @@ export function PracticeDetailsPage() { const fetchPractices = useCallback(async () => { setLoadingList(true) try { - const res = await getQuestionSets({ set_type: "PRACTICE" }) - const payload = res.data?.data as unknown - let sets: QuestionSet[] = [] - if (Array.isArray(payload)) { - sets = payload as QuestionSet[] - } else if ( - payload && - typeof payload === "object" && - Array.isArray((payload as { question_sets?: unknown[] }).question_sets) - ) { - sets = (payload as { question_sets: QuestionSet[] }).question_sets + const batchSize = 100 + let offset = 0 + let total = Number.POSITIVE_INFINITY + const sets: QuestionSet[] = [] + + while (sets.length < total) { + const res = await getQuestionSets({ set_type: "PRACTICE", limit: batchSize, offset }) + const payload = res.data?.data as unknown + let chunk: QuestionSet[] = [] + let chunkTotal = 0 + if (Array.isArray(payload)) { + chunk = payload as QuestionSet[] + chunkTotal = chunk.length + } else if ( + payload && + typeof payload === "object" && + Array.isArray((payload as { question_sets?: unknown[] }).question_sets) + ) { + const mapped = payload as { question_sets: QuestionSet[]; total_count?: number } + chunk = mapped.question_sets + chunkTotal = mapped.total_count ?? chunk.length + } + sets.push(...chunk) + total = chunkTotal + if (chunk.length < batchSize) break + offset += chunk.length } + setPractices(sets) if (sets.length > 0) { setSelectedPracticeId((prev) => prev ?? sets[0].id)