mirror of
https://github.com/zkldi/Tachi.git
synced 2026-09-29 02:18:09 +03:00
refactor: remove unused variables and place types in correct place
This commit is contained in:
@@ -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<ImportInformation>(
|
||||
`/imports/${initRes.body.importID}`
|
||||
);
|
||||
const importRes = await APIFetchV1<ImportIDReturn>(`/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({
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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" };
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user