anki/ts/card-info/CardInfo.svelte

51 lines
1.2 KiB
Svelte
Raw Normal View History

<!--
Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script lang="ts">
2021-10-17 20:29:32 +02:00
import * as tr from "../lib/ftl";
2021-10-17 18:38:28 +02:00
import type { Stats } from "../lib/proto";
2021-10-17 20:29:32 +02:00
import { getCardStats } from "./lib";
2021-10-17 18:38:28 +02:00
import CardStats from "./CardStats.svelte";
import Revlog from "./Revlog.svelte";
2021-10-17 20:29:32 +02:00
export let cardId: number | undefined = undefined;
export let includeRevlog: boolean | undefined = undefined;
let stats: Stats.CardStatsResponse | undefined = undefined;
let _updatingQueue: Promise<void> = Promise.resolve();
$: _updatingQueue = _updatingQueue.then(() => {
if (cardId === undefined) {
stats = undefined;
} else {
getCardStats(cardId).then((s) => {
stats = s;
});
}
});
</script>
<div class="container">
<div>
2021-10-17 20:29:32 +02:00
{#if stats}
<CardStats {stats} />
{#if includeRevlog}
<Revlog {stats} />
{/if}
{:else}
<span class="placeholder">{tr.cardStatsNoCard()}</span>
{/if}
</div>
</div>
<style>
.container {
max-width: 40em;
}
2021-10-17 20:29:32 +02:00
.placeholder {
text-align: center;
}
</style>