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-11-17 04:49:52 +01:00
|
|
|
import Container from "../components/Container.svelte";
|
|
|
|
import Row from "../components/Row.svelte";
|
2022-02-04 09:36:34 +01:00
|
|
|
import type { Stats } from "../lib/proto";
|
2022-02-27 08:35:07 +01:00
|
|
|
import { Cards, stats as statsService } from "../lib/proto";
|
2021-11-17 04:49:52 +01:00
|
|
|
import CardInfoPlaceholder from "./CardInfoPlaceholder.svelte";
|
2022-02-04 09:36:34 +01:00
|
|
|
import CardStats from "./CardStats.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;
|
2022-02-27 08:35:07 +01:00
|
|
|
const cardStats = await statsService.cardStats(
|
|
|
|
Cards.CardId.create({ cid: requestedCardId }),
|
|
|
|
);
|
2021-11-17 04:49:52 +01:00
|
|
|
|
|
|
|
/* 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>
|
|
|
|
|
2022-01-17 06:04:25 +01:00
|
|
|
<Container breakpoint="md" --gutter-inline="1rem" --gutter-block="0.5rem">
|
2021-11-17 04:49:52 +01:00
|
|
|
{#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>
|