anki/ts/card-info/CardInfo.svelte

52 lines
1.3 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;
2021-10-17 20:29:32 +02:00
$: if (cardId === undefined) {
stats = undefined;
} else {
const sentCardId = cardId;
getCardStats(sentCardId).then((s) => {
/* Skip if another update has been triggered in the meantime. */
if (sentCardId === cardId) {
2021-10-17 20:29:32 +02:00
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>