mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 15:02:21 -04:00
Hide IO toast on note change
This commit is contained in:
parent
aa493f8293
commit
986ca6e252
6 changed files with 49 additions and 30 deletions
|
@ -17,12 +17,15 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
import { MaskEditorAPI } from "./tools/api";
|
||||
import { onResize } from "./tools/tool-zoom";
|
||||
import { saveNeededStore } from "./store";
|
||||
import { destroyToast, initToast } from "./toast-utils.svelte";
|
||||
import type Toast from "./Toast.svelte";
|
||||
|
||||
export let mode: IOMode;
|
||||
const iconSize = 80;
|
||||
let innerWidth = 0;
|
||||
const startingTool = mode.kind === "add" ? "draw-rectangle" : "cursor";
|
||||
let canvas: fabric.Canvas | null = null;
|
||||
let toast: Toast | null = null;
|
||||
|
||||
$: {
|
||||
globalThis.maskEditor = canvas ? new MaskEditorAPI(canvas) : null;
|
||||
|
@ -67,11 +70,13 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
|
||||
onMount(() => {
|
||||
window.addEventListener("resize", resizeEvent);
|
||||
toast = initToast();
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
window.removeEventListener("resize", resizeEvent);
|
||||
unsubscribe();
|
||||
destroyToast(toast);
|
||||
});
|
||||
|
||||
const resizeEvent = () => {
|
||||
|
|
|
@ -6,10 +6,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
import Icon from "$lib/components/Icon.svelte";
|
||||
import IconButton from "$lib/components/IconButton.svelte";
|
||||
import { mdiClose } from "$lib/components/icons";
|
||||
import type { ToastProps } from "./types";
|
||||
|
||||
let { showToast, type, message }: ToastProps = $props();
|
||||
|
||||
export let type: "success" | "error" = "success";
|
||||
export let message;
|
||||
export let showToast = false;
|
||||
const closeToast = () => {
|
||||
showToast = false;
|
||||
};
|
||||
|
|
|
@ -6,11 +6,10 @@ import { addImageOcclusionNote, updateImageOcclusionNote } from "@generated/back
|
|||
import * as tr from "@generated/ftl";
|
||||
import { get } from "svelte/store";
|
||||
|
||||
import { mount } from "svelte";
|
||||
import type { IOAddingMode, IOMode } from "./lib";
|
||||
import { exportShapesToClozeDeletions } from "./shapes/to-cloze";
|
||||
import { notesDataStore, tagsWritable } from "./store";
|
||||
import Toast from "./Toast.svelte";
|
||||
import { showToast } from "./toast-utils.svelte";
|
||||
|
||||
export const addOrUpdateNote = async function(
|
||||
mode: IOMode,
|
||||
|
@ -54,24 +53,11 @@ export const addOrUpdateNote = async function(
|
|||
|
||||
// show toast message
|
||||
const showResult = (noteId: bigint | null, result: OpChanges, count: number) => {
|
||||
const props = $state({
|
||||
message: "",
|
||||
type: "error" as "error" | "success",
|
||||
showToast: true,
|
||||
});
|
||||
mount(Toast, {
|
||||
target: document.body,
|
||||
props,
|
||||
});
|
||||
|
||||
if (result.note) {
|
||||
const msg = noteId ? tr.browsingCardsUpdated({ count: count }) : tr.importingCardsAdded({ count: count });
|
||||
props.message = msg;
|
||||
props.type = "success";
|
||||
props.showToast = true;
|
||||
showToast(msg, "success");
|
||||
} else {
|
||||
const msg = tr.notetypesErrorGeneratingCloze();
|
||||
props.message = msg;
|
||||
props.showToast = true;
|
||||
showToast(msg, "error");
|
||||
}
|
||||
};
|
||||
|
|
|
@ -7,10 +7,9 @@ import * as tr from "@generated/ftl";
|
|||
import { fabric } from "fabric";
|
||||
import { get } from "svelte/store";
|
||||
|
||||
import { mount } from "svelte";
|
||||
import { optimumCssSizeForCanvas } from "./canvas-scale";
|
||||
import { hideAllGuessOne, notesDataStore, saveNeededStore, tagsWritable, textEditingState } from "./store";
|
||||
import Toast from "./Toast.svelte";
|
||||
import { showToast } from "./toast-utils.svelte";
|
||||
import { addShapesToCanvasFromCloze } from "./tools/add-from-cloze";
|
||||
import { enableSelectable, makeShapesRemainInCanvas, moveShapeToCanvasBoundaries } from "./tools/lib";
|
||||
import { modifiedPolygon } from "./tools/tool-polygon";
|
||||
|
@ -51,14 +50,7 @@ export const setupMaskEditorForEdit = async (
|
|||
const clozeNoteResponse = await getImageOcclusionNote({ noteId: BigInt(noteId) });
|
||||
const kind = clozeNoteResponse.value?.case;
|
||||
if (!kind || kind === "error") {
|
||||
mount(Toast, {
|
||||
target: document.body,
|
||||
props: {
|
||||
message: tr.notetypesErrorGettingImagecloze(),
|
||||
type: "error",
|
||||
showToast: true,
|
||||
},
|
||||
});
|
||||
showToast(tr.notetypesErrorGettingImagecloze(), "error");
|
||||
throw "error getting cloze";
|
||||
}
|
||||
|
||||
|
|
30
ts/routes/image-occlusion/toast-utils.svelte.ts
Normal file
30
ts/routes/image-occlusion/toast-utils.svelte.ts
Normal file
|
@ -0,0 +1,30 @@
|
|||
import { mount, unmount } from "svelte";
|
||||
import Toast from "./Toast.svelte";
|
||||
import type { ToastProps } from "./types";
|
||||
|
||||
const toastProps: ToastProps = $state({
|
||||
showToast: false,
|
||||
type: "success",
|
||||
message: "",
|
||||
});
|
||||
|
||||
export function initToast(): Toast {
|
||||
return mount(Toast, {
|
||||
target: document.body,
|
||||
props: toastProps,
|
||||
});
|
||||
}
|
||||
|
||||
export function destroyToast(toast: Toast) {
|
||||
unmount(toast);
|
||||
}
|
||||
|
||||
export function showToast(message: string, type: "success" | "error") {
|
||||
toastProps.message = message;
|
||||
toastProps.type = type;
|
||||
toastProps.showToast = true;
|
||||
}
|
||||
|
||||
export function hideToast() {
|
||||
toastProps.showToast = false;
|
||||
}
|
|
@ -9,3 +9,9 @@ export interface Size {
|
|||
export type ConstructorParams<T> = {
|
||||
[P in keyof T]?: T[P];
|
||||
};
|
||||
|
||||
export interface ToastProps {
|
||||
message: string;
|
||||
type: "success" | "error";
|
||||
showToast: boolean;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue