Added: Timer limit

This commit is contained in:
Luc Mcgrady 2025-11-14 17:46:41 +00:00
parent eccaae3c40
commit 312cbc2fba
No known key found for this signature in database
GPG key ID: 4F3D7A0B17CC3D9C
3 changed files with 33 additions and 12 deletions

View file

@ -313,6 +313,7 @@ message NextCardDataResponse {
bool autoplay = 7;
bool marked = 13;
optional TypedAnswer typed_answer = 12;
uint32 max_time_ms = 14;
repeated card_rendering.AVTag question_av_tags = 8;
repeated card_rendering.AVTag answer_av_tags = 9;

View file

@ -492,6 +492,7 @@ impl crate::services::SchedulerService for Collection {
args: answer.0,
}),
marked,
max_time_ms: deck_config.inner.cap_answer_time_to_secs * 1000,
// Filled by python
front: "".to_string(),

View file

@ -4,21 +4,38 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script lang="ts">
import type { ReviewerState } from "../reviewer";
import { onMount } from "svelte";
import { onDestroy } from "svelte";
export let state: ReviewerState;
let text = "";
let cls = "";
function step() {
text = formatTime(Date.now() - state.beginAnsweringMs);
let time = Date.now() - state.beginAnsweringMs;
const maxTime = state._cardData?.maxTimeMs ?? 0;
if (time >= maxTime) {
time = maxTime;
cls = "overtime";
} else {
cls = "";
}
text = formatTime(time);
}
onMount(() => {
const interval = setInterval(step, 1000);
return () => {
clearInterval(interval);
};
let interval: ReturnType<typeof setInterval> | undefined = undefined;
function startTimer() {
clearInterval(interval);
interval = setInterval(step, 1000);
text = formatTime(0);
cls = "";
console.log("startTimer");
}
state.cardData.subscribe(startTimer);
onDestroy(() => {
clearInterval(interval);
});
step();
@ -30,15 +47,17 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
}
</script>
<span>
<div>
{text}
</div>
</span>
<div class={cls}>
{text}
</div>
<style>
div {
width: 88px;
text-align: center;
}
.overtime {
color: red;
}
</style>