Merge pull request #726 from Bottersnike/fix/bm-import-information

This commit is contained in:
zkldi
2022-10-21 01:24:15 +01:00
committed by GitHub
2 changed files with 21 additions and 3 deletions
+11 -3
View File
@@ -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<ImportDocument>(`/imports/${initRes.body.importID}`);
const importRes = await APIFetchV1<ImportIDReturn>(`/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",
+10
View File
@@ -23,6 +23,7 @@ import {
UserGameStatsSnapshot,
GoalSubscriptionDocument,
ChallengeSubscriptionDocument,
ImportDocument,
} from "tachi-common";
export interface UGPTStatsReturn<I extends IDStrings = IDStrings> {
@@ -191,3 +192,12 @@ export interface ChartRivalsReturn {
rivals: Array<PublicUserDocument>;
pbs: Array<PBScoreDocument>;
}
export interface ImportIDReturn {
scores: ScoreDocument[];
songs: SongDocument[];
charts: ChartDocument[];
sessions: SessionDocument[];
import: ImportDocument;
user: PublicUserDocument;
}