diff --git a/ftl/core/card-stats.ftl b/ftl/core/card-stats.ftl
index f6dc983c6..82a0dbee2 100644
--- a/ftl/core/card-stats.ftl
+++ b/ftl/core/card-stats.ftl
@@ -22,6 +22,7 @@ card-stats-review-log-type-review = Review
card-stats-review-log-type-relearn = Relearn
card-stats-review-log-type-filtered = Filtered
card-stats-review-log-type-manual = Manual
+card-stats-no-card = (No card to display.)
## Window Titles
diff --git a/qt/aqt/browser/card_info.py b/qt/aqt/browser/card_info.py
index 59429a232..6addffb05 100644
--- a/qt/aqt/browser/card_info.py
+++ b/qt/aqt/browser/card_info.py
@@ -64,11 +64,13 @@ class CardInfoDialog(QDialog):
self.setLayout(layout)
self.web.eval(
- f"let cardInfo = anki.cardInfo(document.getElementById('main'), {card_id}, true);"
+ "let cardInfo = anki.cardInfo(document.getElementById('main'));\n" \
+ "cardInfo.then((c) => c.$set({ includeRevlog: true }));"
)
+ self.update_card(card_id)
def update_card(self, card_id: CardId) -> None:
- self.web.eval(f"anki.updateCardInfo(cardInfo, {card_id}, true);")
+ self.web.eval(f"cardInfo.then((c) => c.$set({{ cardId: {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 c6ba56fa9..c17643f9f 100644
--- a/ts/card-info/CardInfo.svelte
+++ b/ts/card-info/CardInfo.svelte
@@ -3,17 +3,39 @@ Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
-
-
+ {#if stats}
+
+ {#if includeRevlog}
+
+ {/if}
+ {:else}
+ {tr.cardStatsNoCard()}
+ {/if}
@@ -21,4 +43,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
.container {
max-width: 40em;
}
+
+ .placeholder {
+ text-align: center;
+ }
diff --git a/ts/card-info/index.ts b/ts/card-info/index.ts
index db972562c..2473c285f 100644
--- a/ts/card-info/index.ts
+++ b/ts/card-info/index.ts
@@ -1,51 +1,15 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-import { getCardStats } from "./lib";
import { setupI18n, ModuleName } from "../lib/i18n";
import { checkNightMode } from "../lib/nightmode";
import CardInfo from "./CardInfo.svelte";
-const _updatingQueue: Promise = Promise.resolve();
-
-export async function cardInfo(
- target: HTMLDivElement,
- cardId: number,
- includeRevlog: boolean
-): Promise {
+export async function cardInfo(target: HTMLDivElement): Promise {
checkNightMode();
- const [stats] = await Promise.all([
- getCardStats(cardId),
- setupI18n({
- modules: [
- ModuleName.CARD_STATS,
- ModuleName.SCHEDULING,
- ModuleName.STATISTICS,
- ],
- }),
- ]);
- if (!includeRevlog) {
- stats.revlog = [];
- }
- return new CardInfo({
- target,
- props: { stats },
- });
-}
-
-export async function updateCardInfo(
- cardInfo: Promise,
- cardId: number,
- includeRevlog: boolean
-): Promise {
- _updatingQueue.then(async () => {
- cardInfo.then(async (cardInfo) => {
- const stats = await getCardStats(cardId);
- if (!includeRevlog) {
- stats.revlog = [];
- }
- cardInfo.$set({ stats });
- });
+ await setupI18n({
+ modules: [ModuleName.CARD_STATS, ModuleName.SCHEDULING, ModuleName.STATISTICS],
});
+ return new CardInfo({ target });
}