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 18:38:28 +02:00
|
|
|
import type { Stats } from "../lib/proto";
|
2021-10-17 20:29:32 +02:00
|
|
|
import { getCardStats } from "./lib";
|
2021-11-17 04:49:52 +01:00
|
|
|
import Container from "../components/Container.svelte";
|
|
|
|
import Row from "../components/Row.svelte";
|
2021-10-17 18:38:28 +02:00
|
|
|
import CardStats from "./CardStats.svelte";
|
2021-11-17 04:49:52 +01:00
|
|
|
import CardInfoPlaceholder from "./CardInfoPlaceholder.svelte";
|
2021-10-14 11:22:47 +02:00
|
|
|
import Revlog from "./Revlog.svelte";
|
|
|
|
|
2021-10-18 09:11:00 +02:00
|
|
|
export let cardId: number | null = null;
|
2021-10-18 09:04:49 +02:00
|
|
|
export let includeRevlog: boolean = true;
|
2021-10-17 20:29:32 +02:00
|
|
|
|
2021-10-18 09:29:33 +02:00
|
|
|
let stats: Stats.CardStatsResponse | null = null;
|
2021-11-17 04:49:52 +01:00
|
|
|
let revlog: Stats.CardStatsResponse.StatsRevlogEntry[] | null = null;
|
2021-10-17 20:29:32 +02:00
|
|
|
|
2021-11-17 04:49:52 +01:00
|
|
|
async function updateStats(cardId: number): Promise<void> {
|
2021-10-18 09:12:10 +02:00
|
|
|
const requestedCardId = cardId;
|
2021-11-17 04:49:52 +01:00
|
|
|
const cardStats = await getCardStats(requestedCardId);
|
|
|
|
|
|
|
|
/* Skip if another update has been triggered in the meantime. */
|
|
|
|
if (requestedCardId === cardId) {
|
|
|
|
stats = cardStats;
|
|
|
|
|
|
|
|
if (includeRevlog) {
|
|
|
|
revlog = stats.revlog as Stats.CardStatsResponse.StatsRevlogEntry[];
|
2021-10-17 21:08:19 +02:00
|
|
|
}
|
2021-11-17 04:49:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$: if (cardId) {
|
|
|
|
updateStats(cardId);
|
|
|
|
} else {
|
|
|
|
stats = null;
|
|
|
|
revlog = null;
|
2021-10-17 22:06:44 +02:00
|
|
|
}
|
2021-10-14 11:22:47 +02:00
|
|
|
</script>
|
|
|
|
|
2021-11-17 04:49:52 +01:00
|
|
|
<Container breakpoint="md" --gutter-inline="0.25rem" --gutter-block="0.5rem">
|
|
|
|
{#if stats}
|
|
|
|
<Row>
|
2021-10-17 20:29:32 +02:00
|
|
|
<CardStats {stats} />
|
2021-11-17 04:49:52 +01:00
|
|
|
</Row>
|
2021-10-17 20:29:32 +02:00
|
|
|
|
2021-11-17 04:49:52 +01:00
|
|
|
{#if revlog}
|
|
|
|
<Row>
|
|
|
|
<Revlog {revlog} />
|
|
|
|
</Row>
|
|
|
|
{/if}
|
|
|
|
{:else}
|
|
|
|
<CardInfoPlaceholder />
|
|
|
|
{/if}
|
|
|
|
</Container>
|