anki/ts/card-info/CardInfo.svelte

56 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;
}
});
2021-10-17 22:06:44 +02:00
}
</script>
2021-10-17 22:06:44 +02:00
{#if stats}
<div class="container">
<div>
2021-10-17 20:29:32 +02:00
<CardStats {stats} />
{#if includeRevlog}
<Revlog {stats} />
{/if}
2021-10-17 22:06:44 +02:00
</div>
</div>
2021-10-17 22:06:44 +02:00
{:else}
<div class="placeholder">{tr.cardStatsNoCard()}</div>
{/if}
<style>
.container {
max-width: 40em;
}
2021-10-17 20:29:32 +02:00
.placeholder {
2021-10-17 22:06:44 +02:00
margin: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
2021-10-17 20:29:32 +02:00
}
</style>