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
|
|
|
|
|
|
|
|
import { getCardStats } from "./lib";
|
|
|
|
import { setupI18n, ModuleName } from "../lib/i18n";
|
|
|
|
import { checkNightMode } from "../lib/nightmode";
|
|
|
|
|
|
|
|
import CardInfo from "./CardInfo.svelte";
|
|
|
|
|
2021-10-16 23:32:00 +02:00
|
|
|
const _updatingQueue: Promise<void> = Promise.resolve();
|
|
|
|
|
2021-10-14 11:22:47 +02:00
|
|
|
export async function cardInfo(
|
|
|
|
target: HTMLDivElement,
|
|
|
|
cardId: number,
|
|
|
|
includeRevlog: boolean
|
|
|
|
): Promise<CardInfo> {
|
|
|
|
checkNightMode();
|
|
|
|
const [stats] = await Promise.all([
|
|
|
|
getCardStats(cardId),
|
|
|
|
setupI18n({
|
|
|
|
modules: [
|
|
|
|
ModuleName.CARD_STATS,
|
|
|
|
ModuleName.SCHEDULING,
|
|
|
|
ModuleName.STATISTICS,
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
]);
|
|
|
|
if (!includeRevlog) {
|
|
|
|
stats.revlog = [];
|
|
|
|
}
|
|
|
|
return new CardInfo({
|
|
|
|
target,
|
|
|
|
props: { stats },
|
|
|
|
});
|
|
|
|
}
|
2021-10-16 23:32:00 +02:00
|
|
|
|
|
|
|
export async function updateCardInfo(
|
|
|
|
cardInfo: Promise<CardInfo>,
|
|
|
|
cardId: number,
|
|
|
|
includeRevlog: boolean
|
|
|
|
): Promise<void> {
|
|
|
|
_updatingQueue.then(async () => {
|
|
|
|
cardInfo.then(async (cardInfo) => {
|
|
|
|
const stats = await getCardStats(cardId);
|
|
|
|
if (!includeRevlog) {
|
|
|
|
stats.revlog = [];
|
|
|
|
}
|
|
|
|
cardInfo.$set({ stats });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|