Fix card info not updating (#1957)

Update was not triggered if card id didn't change.
This commit is contained in:
RumovZ 2022-07-12 02:34:48 +02:00 committed by GitHub
parent 8c515e316e
commit cff04a288a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 12 deletions

View file

@ -68,7 +68,7 @@ class CardInfoDialog(QDialog):
def update_card(self, card_id: CardId | None) -> None:
self.web.eval(
f"anki.cardInfoPromise.then((c) => c.$set({{ cardId: {json.dumps(card_id)} }}));"
f"anki.cardInfoPromise.then((c) => c.updateStats({json.dumps(card_id)}));"
)
def reject(self) -> None:

View file

@ -11,14 +11,20 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import CardStats from "./CardStats.svelte";
import Revlog from "./Revlog.svelte";
export let cardId: number | null = null;
export let includeRevlog: boolean = true;
let stats: Stats.CardStatsResponse | null = null;
let revlog: Stats.CardStatsResponse.StatsRevlogEntry[] | null = null;
async function updateStats(cardId: number): Promise<void> {
export async function updateStats(cardId: number | null): Promise<void> {
const requestedCardId = cardId;
if (cardId === null) {
stats = null;
revlog = null;
return;
}
const cardStats = await statsService.cardStats(
Cards.CardId.create({ cid: requestedCardId }),
);
@ -32,13 +38,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
}
}
}
$: if (cardId) {
updateStats(cardId);
} else {
stats = null;
revlog = null;
}
</script>
<Container breakpoint="md" --gutter-inline="1rem" --gutter-block="0.5rem">

View file

@ -21,7 +21,7 @@ export async function setupCardInfo(target: HTMLElement): Promise<CardInfo> {
if (window.location.hash.startsWith("#test")) {
// use #testXXXX where XXXX is card ID to test
const cardId = parseInt(window.location.hash.substr("#test".length), 10);
setupCardInfo(document.body).then((cardInfo: CardInfo): void =>
cardInfo.$set({ cardId }),
setupCardInfo(document.body).then(
(cardInfo: CardInfo): Promise<void> => cardInfo.updateStats(cardId),
);
}