Added: Untested easeButtonPressed

This commit is contained in:
Luc Mcgrady 2025-10-04 18:02:21 +01:00
parent c76f013b16
commit 44cc5f82e9
No known key found for this signature in database
GPG key ID: 4F3D7A0B17CC3D9C
3 changed files with 35 additions and 7 deletions

View file

@ -292,10 +292,11 @@ message NextCardDataRequest {
message NextCardDataResponse {
message NextCardData {
string front = 1;
string back = 2;
int64 card_id = 1;
string front = 2;
string back = 3;
SchedulingStates states = 3;
SchedulingStates states = 4;
}
optional NextCardData next_card = 1;

View file

@ -400,6 +400,7 @@ impl crate::services::SchedulerService for Collection {
Ok(NextCardDataResponse {
next_card: Some(NextCardData {
card_id: cid.0,
front: [style.clone(), render.question().to_string()].concat(),
back: [style, render.answer().to_string()].concat(),

View file

@ -1,6 +1,9 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import type { CardAnswer, SchedulingStates } from "@generated/anki/scheduler_pb";
import {
CardAnswer,
type NextCardDataResponse_NextCardData,
} from "@generated/anki/scheduler_pb";
import { nextCardData } from "@generated/backend";
import { bridgeCommand } from "@tslib/bridgecommand";
import { writable } from "svelte/store";
@ -8,7 +11,8 @@ import { writable } from "svelte/store";
export function setupReviewer(iframe: HTMLIFrameElement) {
const cardClass = writable("");
let answer_html = "";
let _states: SchedulingStates | undefined = undefined;
let cardData: NextCardDataResponse_NextCardData | undefined = undefined;
let startAnswering = Date.now();
function updateHtml(htmlString) {
iframe.contentWindow?.postMessage({ type: "html", value: htmlString }, "*");
@ -21,7 +25,7 @@ export function setupReviewer(iframe: HTMLIFrameElement) {
// TODO: "Congratulation screen" logic
const question = resp.nextCard?.front || "";
answer_html = resp.nextCard?.back || "";
_states = resp.nextCard?.states;
cardData = resp.nextCard;
console.log({ resp });
updateHtml(question);
}
@ -35,6 +39,28 @@ export function setupReviewer(iframe: HTMLIFrameElement) {
showQuestion(null);
}
function easeButtonPressed(rating: number) {
const states = cardData!.states!;
let newState = ({
[1]: states.again!,
[2]: states.hard!,
[3]: states.good!,
[4]: states.easy!,
})[rating]!;
showQuestion(
new CardAnswer({
rating: rating,
currentState: states!.current!,
newState,
cardId: cardData!.cardId,
answeredAtMillis: BigInt(Date.now()),
millisecondsTaken: Date.now() - startAnswering,
}),
);
}
iframe?.addEventListener("load", onReady);
addEventListener("message", (e) => {
@ -58,5 +84,5 @@ export function setupReviewer(iframe: HTMLIFrameElement) {
globalThis._showQuestion = showQuestion;
globalThis._showAnswer = showAnswer;
return { cardClass };
return { cardClass, easeButtonPressed };
}