Use null for unset cardId

This commit is contained in:
RumovZ 2021-10-18 09:11:00 +02:00
parent dc4f5adc44
commit 8eed005db6
2 changed files with 6 additions and 4 deletions

View File

@ -3,6 +3,7 @@
from __future__ import annotations
import json
from typing import Callable
import aqt
@ -69,8 +70,9 @@ class CardInfoDialog(QDialog):
self.update_card(card_id)
def update_card(self, card_id: CardId | None) -> None:
val = "undefined" if card_id is None else card_id
self.web.eval(f"cardInfo.then((c) => c.$set({{ cardId: {val} }}));")
self.web.eval(
f"cardInfo.then((c) => c.$set({{ cardId: {json.dumps(card_id)} }}));"
)
def reject(self) -> None:
if self._on_close:

View File

@ -9,12 +9,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import CardStats from "./CardStats.svelte";
import Revlog from "./Revlog.svelte";
export let cardId: number | undefined = undefined;
export let cardId: number | null = null;
export let includeRevlog: boolean = true;
let stats: Stats.CardStatsResponse | undefined;
$: if (cardId === undefined) {
$: if (cardId === null) {
stats = undefined;
} else {
const sentCardId = cardId;