mirror of
https://github.com/ankitects/anki.git
synced 2025-12-10 21:36:55 -05:00
Fix card info not updating (#1957)
Update was not triggered if card id didn't change.
This commit is contained in:
parent
8c515e316e
commit
cff04a288a
3 changed files with 11 additions and 12 deletions
|
|
@ -68,7 +68,7 @@ class CardInfoDialog(QDialog):
|
||||||
|
|
||||||
def update_card(self, card_id: CardId | None) -> None:
|
def update_card(self, card_id: CardId | None) -> None:
|
||||||
self.web.eval(
|
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:
|
def reject(self) -> None:
|
||||||
|
|
|
||||||
|
|
@ -11,14 +11,20 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
import CardStats from "./CardStats.svelte";
|
import CardStats from "./CardStats.svelte";
|
||||||
import Revlog from "./Revlog.svelte";
|
import Revlog from "./Revlog.svelte";
|
||||||
|
|
||||||
export let cardId: number | null = null;
|
|
||||||
export let includeRevlog: boolean = true;
|
export let includeRevlog: boolean = true;
|
||||||
|
|
||||||
let stats: Stats.CardStatsResponse | null = null;
|
let stats: Stats.CardStatsResponse | null = null;
|
||||||
let revlog: Stats.CardStatsResponse.StatsRevlogEntry[] | 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;
|
const requestedCardId = cardId;
|
||||||
|
|
||||||
|
if (cardId === null) {
|
||||||
|
stats = null;
|
||||||
|
revlog = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const cardStats = await statsService.cardStats(
|
const cardStats = await statsService.cardStats(
|
||||||
Cards.CardId.create({ cid: requestedCardId }),
|
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>
|
</script>
|
||||||
|
|
||||||
<Container breakpoint="md" --gutter-inline="1rem" --gutter-block="0.5rem">
|
<Container breakpoint="md" --gutter-inline="1rem" --gutter-block="0.5rem">
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ export async function setupCardInfo(target: HTMLElement): Promise<CardInfo> {
|
||||||
if (window.location.hash.startsWith("#test")) {
|
if (window.location.hash.startsWith("#test")) {
|
||||||
// use #testXXXX where XXXX is card ID to test
|
// use #testXXXX where XXXX is card ID to test
|
||||||
const cardId = parseInt(window.location.hash.substr("#test".length), 10);
|
const cardId = parseInt(window.location.hash.substr("#test".length), 10);
|
||||||
setupCardInfo(document.body).then((cardInfo: CardInfo): void =>
|
setupCardInfo(document.body).then(
|
||||||
cardInfo.$set({ cardId }),
|
(cardInfo: CardInfo): Promise<void> => cardInfo.updateStats(cardId),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue