diff --git a/client/src/components/util/import/useImport.ts b/client/src/components/util/import/useImport.ts index 5a63b57a5..17f32b9cc 100644 --- a/client/src/components/util/import/useImport.ts +++ b/client/src/components/util/import/useImport.ts @@ -4,6 +4,7 @@ import { Sleep } from "util/misc"; import { useState } from "react"; import { ImportDocument, integer } from "tachi-common"; import { ImportStates, NotStartedState } from "types/import"; +import { ImportIDReturn } from "types/api-returns"; export interface ImportDeferred { url: string; @@ -41,14 +42,17 @@ export default function useImport(url: string, options: RequestInit) { // 200 means the import was processed on-router. if (initRes.statusCode === 200) { - const importRes = await APIFetchV1(`/imports/${initRes.body.importID}`); + const importRes = await APIFetchV1(`/imports/${initRes.body.importID}`); if (!importRes.success) { setImportState({ state: "failed", error: importRes.description }); return; } - setImportState({ state: "done", import: importRes.body as ImportDocument }); + setImportState({ + state: "done", + import: importRes.body.import, + }); } else if (initRes.statusCode === 202) { // 202 means the import is processing. We'll have to poll the // status of the import in real time to see whats happening. @@ -63,7 +67,11 @@ export default function useImport(url: string, options: RequestInit) { if (pollRes.success) { if (pollRes.body.importStatus === "completed") { isImportFinished = true; - setImportState({ state: "done", import: pollRes.body.import }); + if (importState.state === "done") { + setImportState({ ...importState, import: pollRes.body.import }); + } else { + setImportState({ state: "done", import: pollRes.body.import }); + } } else { setImportState({ state: "waiting_processing", diff --git a/client/src/types/api-returns.ts b/client/src/types/api-returns.ts index 67baaa312..30636a9e1 100644 --- a/client/src/types/api-returns.ts +++ b/client/src/types/api-returns.ts @@ -23,6 +23,7 @@ import { UserGameStatsSnapshot, GoalSubscriptionDocument, ChallengeSubscriptionDocument, + ImportDocument, } from "tachi-common"; export interface UGPTStatsReturn { @@ -191,3 +192,12 @@ export interface ChartRivalsReturn { rivals: Array; pbs: Array; } + +export interface ImportIDReturn { + scores: ScoreDocument[]; + songs: SongDocument[]; + charts: ChartDocument[]; + sessions: SessionDocument[]; + import: ImportDocument; + user: PublicUserDocument; +}