2021-10-14 11:22:47 +02:00
|
|
|
<!--
|
|
|
|
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";
|
2021-10-14 11:22:47 +02:00
|
|
|
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;
|
|
|
|
|
2021-10-17 21:23:11 +02:00
|
|
|
let stats: Stats.CardStatsResponse | undefined;
|
2021-10-17 20:29:32 +02:00
|
|
|
|
2021-10-17 21:08:19 +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 21:08:19 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2021-10-14 11:22:47 +02:00
|
|
|
</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}
|
2021-10-14 11:22:47 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.container {
|
2021-10-14 10:49:40 +02:00
|
|
|
max-width: 40em;
|
2021-10-14 11:22:47 +02:00
|
|
|
}
|
2021-10-17 20:29:32 +02:00
|
|
|
|
|
|
|
.placeholder {
|
|
|
|
text-align: center;
|
|
|
|
}
|
2021-10-14 11:22:47 +02:00
|
|
|
</style>
|