From 2e749e004212ad8e80a909b0f23c42bb09c8034b Mon Sep 17 00:00:00 2001 From: Bottersnike Date: Wed, 19 Oct 2022 23:57:55 +0100 Subject: [PATCH 1/2] Fix bug where all batch manual imports show as failed --- .../src/components/util/import/useImport.ts | 22 ++++++++++--- client/src/types/import.ts | 31 +++++++++++++++++-- client/src/util/submit-file.ts | 2 +- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/client/src/components/util/import/useImport.ts b/client/src/components/util/import/useImport.ts index 5a63b57a5..7c11aba65 100644 --- a/client/src/components/util/import/useImport.ts +++ b/client/src/components/util/import/useImport.ts @@ -3,7 +3,7 @@ import { APIFetchV1 } from "util/api"; import { Sleep } from "util/misc"; import { useState } from "react"; import { ImportDocument, integer } from "tachi-common"; -import { ImportStates, NotStartedState } from "types/import"; +import { ImportInformation, ImportStates, NotStartedState } from "types/import"; export interface ImportDeferred { url: string; @@ -41,14 +41,20 @@ 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 as ImportInformation).import, + details: importRes.body as ImportInformation, + }); } 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 +69,15 @@ 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, + details: null, + }); + } } else { setImportState({ state: "waiting_processing", diff --git a/client/src/types/import.ts b/client/src/types/import.ts index 1de7d1363..aee720765 100644 --- a/client/src/types/import.ts +++ b/client/src/types/import.ts @@ -1,10 +1,37 @@ -import { ImportDocument } from "tachi-common"; +import { + ChartDocument, + ImportDocument, + PublicUserDocument, + ScoreDocument, + SessionDocument, + SongDocument, +} from "tachi-common"; + +export type ImportInformation = { + scores: ScoreDocument[]; + songs: SongDocument[]; + charts: ChartDocument[]; + sessions: SessionDocument[]; + import: ImportDocument; + user: PublicUserDocument; +}; export type ImportStates = | { state: "not_started" } | { state: "waiting_init" } | { state: "waiting_processing"; progressInfo: { description: string } } - | { state: "done"; import: ImportDocument } + | { + state: "done"; + import: ImportDocument; + details: null | { + import: ImportDocument; + scores: ScoreDocument[]; + songs: SongDocument[]; + charts: ChartDocument[]; + sessions: SessionDocument[]; + user: PublicUserDocument; + }; + } | { state: "failed"; error: string }; export const NotStartedState: ImportStates = { state: "not_started" }; diff --git a/client/src/util/submit-file.ts b/client/src/util/submit-file.ts index ca0f18b54..fabb232a6 100644 --- a/client/src/util/submit-file.ts +++ b/client/src/util/submit-file.ts @@ -33,7 +33,7 @@ export default async function SubmitFile( ); if (res.success) { - setState({ state: "done", import: res.body }); + setState({ state: "done", import: res.body, details: null }); } else { setState({ state: "failed", error: res.description }); } From 0026f17fae88bc2cde52ff97bfb5fdc86bc275fa Mon Sep 17 00:00:00 2001 From: zkldi <20380519+zkldi@users.noreply.github.com> Date: Fri, 21 Oct 2022 01:22:39 +0100 Subject: [PATCH 2/2] refactor: remove unused variables and place types in correct place --- .../src/components/util/import/useImport.ts | 16 +++------- client/src/types/api-returns.ts | 10 ++++++ client/src/types/import.ts | 31 ++----------------- client/src/util/submit-file.ts | 2 +- 4 files changed, 18 insertions(+), 41 deletions(-) diff --git a/client/src/components/util/import/useImport.ts b/client/src/components/util/import/useImport.ts index 7c11aba65..17f32b9cc 100644 --- a/client/src/components/util/import/useImport.ts +++ b/client/src/components/util/import/useImport.ts @@ -3,7 +3,8 @@ import { APIFetchV1 } from "util/api"; import { Sleep } from "util/misc"; import { useState } from "react"; import { ImportDocument, integer } from "tachi-common"; -import { ImportInformation, ImportStates, NotStartedState } from "types/import"; +import { ImportStates, NotStartedState } from "types/import"; +import { ImportIDReturn } from "types/api-returns"; export interface ImportDeferred { url: string; @@ -41,9 +42,7 @@ 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 }); @@ -52,8 +51,7 @@ export default function useImport(url: string, options: RequestInit) { setImportState({ state: "done", - import: (importRes.body as ImportInformation).import, - details: importRes.body as ImportInformation, + import: importRes.body.import, }); } else if (initRes.statusCode === 202) { // 202 means the import is processing. We'll have to poll the @@ -72,11 +70,7 @@ export default function useImport(url: string, options: RequestInit) { if (importState.state === "done") { setImportState({ ...importState, import: pollRes.body.import }); } else { - setImportState({ - state: "done", - import: pollRes.body.import, - details: null, - }); + setImportState({ state: "done", import: pollRes.body.import }); } } else { setImportState({ 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; +} diff --git a/client/src/types/import.ts b/client/src/types/import.ts index aee720765..1de7d1363 100644 --- a/client/src/types/import.ts +++ b/client/src/types/import.ts @@ -1,37 +1,10 @@ -import { - ChartDocument, - ImportDocument, - PublicUserDocument, - ScoreDocument, - SessionDocument, - SongDocument, -} from "tachi-common"; - -export type ImportInformation = { - scores: ScoreDocument[]; - songs: SongDocument[]; - charts: ChartDocument[]; - sessions: SessionDocument[]; - import: ImportDocument; - user: PublicUserDocument; -}; +import { ImportDocument } from "tachi-common"; export type ImportStates = | { state: "not_started" } | { state: "waiting_init" } | { state: "waiting_processing"; progressInfo: { description: string } } - | { - state: "done"; - import: ImportDocument; - details: null | { - import: ImportDocument; - scores: ScoreDocument[]; - songs: SongDocument[]; - charts: ChartDocument[]; - sessions: SessionDocument[]; - user: PublicUserDocument; - }; - } + | { state: "done"; import: ImportDocument } | { state: "failed"; error: string }; export const NotStartedState: ImportStates = { state: "not_started" }; diff --git a/client/src/util/submit-file.ts b/client/src/util/submit-file.ts index fabb232a6..ca0f18b54 100644 --- a/client/src/util/submit-file.ts +++ b/client/src/util/submit-file.ts @@ -33,7 +33,7 @@ export default async function SubmitFile( ); if (res.success) { - setState({ state: "done", import: res.body, details: null }); + setState({ state: "done", import: res.body }); } else { setState({ state: "failed", error: res.description }); }