Fix congrats screen not refreshing (#3594)

This commit is contained in:
Abdo 2024-11-24 13:52:56 +03:00 committed by GitHub
parent 9a013d8601
commit 2cd6b1c3b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 13 deletions

View file

@ -4,6 +4,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script lang="ts">
import type { CongratsInfoResponse } from "@generated/anki/scheduler_pb";
import { congratsInfo } from "@generated/backend";
import * as tr from "@generated/ftl";
import { bridgeLink } from "@tslib/bridgecommand";
@ -11,8 +12,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import Container from "$lib/components/Container.svelte";
import { buildNextLearnMsg } from "./lib";
import { onMount } from "svelte";
export let info: CongratsInfoResponse;
export let refreshPeriodically = true;
const congrats = tr.schedulingCongratulationsFinished();
let nextLearnMsg: string;
@ -26,6 +29,18 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
const customStudyMsg = tr.schedulingHowToCustomStudy({
customStudy,
});
onMount(() => {
if (refreshPeriodically) {
setInterval(async () => {
try {
info = await congratsInfo({});
} catch {
console.log("congrats fetch failed");
}
}, 60000);
}
});
</script>
<Container --gutter-block="1rem" --gutter-inline="2px" breakpoint="sm">

View file

@ -20,21 +20,9 @@ export async function setupCongrats(): Promise<CongratsPage> {
const page = new CongratsPage({
// use #congrats if it exists, otherwise entire body
target: customMountPoint ?? document.body,
props: { info },
props: { info, refreshPeriodically: !customMountPoint },
});
// refresh automatically if a custom area not provided
if (!customMountPoint) {
setInterval(async () => {
try {
const info = await congratsInfo({});
page.$set({ info });
} catch {
console.log("congrats fetch failed");
}
}, 60000);
}
return page;
}