From 50029fbb24687e07ab15222048b694283f059453 Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Thu, 22 Feb 2024 19:00:14 -0500 Subject: [PATCH] [F] Fix TS errors --- AquaNet/src/components/Confirm.svelte | 34 ++++++++++++++++++++++++++ AquaNet/src/pages/Home/LinkCard.svelte | 32 ++++++++++++------------ 2 files changed, 51 insertions(+), 15 deletions(-) create mode 100644 AquaNet/src/components/Confirm.svelte diff --git a/AquaNet/src/components/Confirm.svelte b/AquaNet/src/components/Confirm.svelte new file mode 100644 index 00000000..04838b29 --- /dev/null +++ b/AquaNet/src/components/Confirm.svelte @@ -0,0 +1,34 @@ + + + + +{#if show} +
+{/if} + + \ No newline at end of file diff --git a/AquaNet/src/pages/Home/LinkCard.svelte b/AquaNet/src/pages/Home/LinkCard.svelte index a050ed4a..9f9d0b19 100644 --- a/AquaNet/src/pages/Home/LinkCard.svelte +++ b/AquaNet/src/pages/Home/LinkCard.svelte @@ -9,7 +9,7 @@ import Icon from "@iconify/svelte"; // State - let state: 'ready' | 'linking-AC' | 'linking-SN' = "ready" + let state: 'ready' | 'linking-AC' | 'linking-SN' | 'loading' = "loading" let error: string = "" let me: UserMe | null = null @@ -23,6 +23,7 @@ // Always put the ghost card at the top m.cards.sort((a, b) => a.ghost ? -1 : 1) + state = "ready" }).catch(e => error = e.message) updateMe() @@ -45,7 +46,7 @@ } async function link(type: 'AC' | 'SN') { - if (state !== 'ready') return + if (state !== 'ready' || accountCardSummary === null) return state = "linking-" + type const id = type === 'AC' ? inputAC : inputSN @@ -81,11 +82,10 @@ // If all games in summary are null or doesn't conflict with the ghost card, // we can link the card directly - // @ts-ignore - TS doesn't understand that k is a key of CardSummary, so it says k cannot be used as index - if (Object.keys(summary).every(k => summary[k] === null || accountCardSummary[k] === null)) { + if (Object.keys(summary).every(k => summary[k as keyof CardSummary] === null + || accountCardSummary!![k as keyof CardSummary] === null)) { console.log("linking card directly") - // @ts-ignore - await doLink(id, Object.keys(summary).filter(k => summary[k] !== null).join(",")) + await doLink(id, Object.keys(summary).filter(k => summary[k as keyof CardSummary] !== null).join(",")) } // For each conflicting game, ask the user if they want to migrate the data @@ -97,6 +97,7 @@ } async function linkConflictContinue(choose: "old" | "new" | null) { + if (accountCardSummary === null || conflictSummary === null) return console.log("linking card with migration") if (choose) { @@ -106,16 +107,13 @@ conflictToMigrate.push(conflictGame) } // Continue to the next card - // @ts-ignore - conflictSummary[conflictGame] = null + conflictSummary[conflictGame as keyof CardSummary] = null } let isConflict = false for (const k in conflictSummary) { - // @ts-ignore - conflictNew = conflictSummary[k] - // @ts-ignore - conflictOld = accountCardSummary[k] + conflictNew = conflictSummary[k as keyof CardSummary] + conflictOld = accountCardSummary[k as keyof CardSummary] conflictGame = k if (!conflictNew || !conflictOld) continue @@ -208,9 +206,9 @@ {#if me}