From 8eed005db6d2e3209ab9626c1c91ef9613857e38 Mon Sep 17 00:00:00 2001 From: RumovZ Date: Mon, 18 Oct 2021 09:11:00 +0200 Subject: [PATCH] Use `null` for unset cardId --- qt/aqt/browser/card_info.py | 6 ++++-- ts/card-info/CardInfo.svelte | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/qt/aqt/browser/card_info.py b/qt/aqt/browser/card_info.py index 08def5750..61bdd2274 100644 --- a/qt/aqt/browser/card_info.py +++ b/qt/aqt/browser/card_info.py @@ -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: diff --git a/ts/card-info/CardInfo.svelte b/ts/card-info/CardInfo.svelte index 6dec99e15..5ec718efb 100644 --- a/ts/card-info/CardInfo.svelte +++ b/ts/card-info/CardInfo.svelte @@ -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;