From 2d1c6c64e88ff7e7cb0c6bae3788c0e51a71e45e Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 24 Jan 2025 18:08:11 +1100 Subject: [PATCH] Add a separate route for card info in the sidebar The move to Sveltekit broke the 'card info during review' add-on and its descendants. This didn't get noticed in 24.11 due to the old card-info.js file still being shipped. I considered adding back the card-info.js generation, but it ended up being simpler to move parts of the add-on into a separate page instead. This is a stop-gap solution - in the future I'd like to get us to a point where such component compositions can be done by add-ons, and don't need to be done as part of Anki's build process. Related: #3187 --- .../[cardId]/[previousId]/+page.svelte | 40 +++++++++++++++++++ .../card-info/[cardId]/[previousId]/+page.ts | 22 ++++++++++ ts/routes/card-info/card-info-base.scss | 1 - ts/routes/card-info/index.ts | 31 -------------- 4 files changed, 62 insertions(+), 32 deletions(-) create mode 100644 ts/routes/card-info/[cardId]/[previousId]/+page.svelte create mode 100644 ts/routes/card-info/[cardId]/[previousId]/+page.ts delete mode 100644 ts/routes/card-info/card-info-base.scss delete mode 100644 ts/routes/card-info/index.ts diff --git a/ts/routes/card-info/[cardId]/[previousId]/+page.svelte b/ts/routes/card-info/[cardId]/[previousId]/+page.svelte new file mode 100644 index 000000000..c04cf483b --- /dev/null +++ b/ts/routes/card-info/[cardId]/[previousId]/+page.svelte @@ -0,0 +1,40 @@ + + + +
+ {#if data.currentInfo} +

Current

+ + {/if} + {#if data.previousInfo} +

Previous

+ + {/if} +
+ + diff --git a/ts/routes/card-info/[cardId]/[previousId]/+page.ts b/ts/routes/card-info/[cardId]/[previousId]/+page.ts new file mode 100644 index 000000000..d60bf84b9 --- /dev/null +++ b/ts/routes/card-info/[cardId]/[previousId]/+page.ts @@ -0,0 +1,22 @@ +// Copyright: Ankitects Pty Ltd and contributors +// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html + +import { cardStats } from "@generated/backend"; + +import type { PageLoad } from "./$types"; + +function optionalBigInt(x: any): bigint | null { + try { + return BigInt(x); + } catch (e) { + return null; + } +} + +export const load = (async ({ params }) => { + const currentId = optionalBigInt(params.cardId); + const currentInfo = currentId !== null ? await cardStats({ cid: currentId }) : null; + const previousId = optionalBigInt(params.previousId); + const previousInfo = previousId !== null ? await cardStats({ cid: previousId }) : null; + return { currentInfo, previousInfo }; +}) satisfies PageLoad; diff --git a/ts/routes/card-info/card-info-base.scss b/ts/routes/card-info/card-info-base.scss deleted file mode 100644 index 96e199d3c..000000000 --- a/ts/routes/card-info/card-info-base.scss +++ /dev/null @@ -1 +0,0 @@ -@import "../lib/sass/base"; diff --git a/ts/routes/card-info/index.ts b/ts/routes/card-info/index.ts deleted file mode 100644 index 22a7f13a8..000000000 --- a/ts/routes/card-info/index.ts +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright: Ankitects Pty Ltd and contributors -// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html - -import "./card-info-base.scss"; - -import { ModuleName, setupI18n } from "@tslib/i18n"; -import { checkNightMode } from "@tslib/nightmode"; - -import CardInfo from "./CardInfo.svelte"; - -const i18n = setupI18n({ - modules: [ModuleName.CARD_STATS, ModuleName.SCHEDULING, ModuleName.STATISTICS], -}); - -export async function setupCardInfo( - target: HTMLElement, - props = {}, -): Promise { - checkNightMode(); - await i18n; - - return new CardInfo({ target, props }); -} - -if (window.location.hash.startsWith("#test")) { - // use #testXXXX where XXXX is card ID to test - const cardId = parseInt(window.location.hash.substring(0, "#test".length), 10); - setupCardInfo(document.body).then( - (cardInfo: CardInfo): Promise => cardInfo.updateStats(BigInt(cardId)), - ); -}