From a188a59646c33645f7e8b47b4c11e1a940ae1c06 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 22 Apr 2024 20:34:21 +1000 Subject: [PATCH] Fix adding/saving I/Os on mobile --- .../[...imagePathOrNoteId]/+page.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ts/routes/image-occlusion/[...imagePathOrNoteId]/+page.ts b/ts/routes/image-occlusion/[...imagePathOrNoteId]/+page.ts index ec6f33775..d8df25f27 100644 --- a/ts/routes/image-occlusion/[...imagePathOrNoteId]/+page.ts +++ b/ts/routes/image-occlusion/[...imagePathOrNoteId]/+page.ts @@ -1,8 +1,17 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html + +import { get } from "svelte/store"; + +import { addOrUpdateNote } from "../add-or-update-note"; import type { IOMode } from "../lib"; +import { hideAllGuessOne } from "../store"; import type { PageLoad } from "./$types"; +async function save(): Promise { + addOrUpdateNote(globalThis["anki"].imageOcclusion.mode, get(hideAllGuessOne)); +} + export const load = (async ({ params }) => { let mode: IOMode; if (/^\d+/.test(params.imagePathOrNoteId)) { @@ -10,6 +19,14 @@ export const load = (async ({ params }) => { } else { mode = { kind: "add", imagePath: params.imagePathOrNoteId, notetypeId: 0 }; } + + // for adding note from mobile devices + globalThis.anki = globalThis.anki || {}; + globalThis.anki.imageOcclusion = { + mode, + save, + }; + return { mode, };