mirror of
https://github.com/ankitects/anki.git
synced 2025-11-06 12:47:11 -05:00
Added: Untested easeButtonPressed
This commit is contained in:
parent
c76f013b16
commit
44cc5f82e9
3 changed files with 35 additions and 7 deletions
|
|
@ -292,10 +292,11 @@ message NextCardDataRequest {
|
||||||
|
|
||||||
message NextCardDataResponse {
|
message NextCardDataResponse {
|
||||||
message NextCardData {
|
message NextCardData {
|
||||||
string front = 1;
|
int64 card_id = 1;
|
||||||
string back = 2;
|
string front = 2;
|
||||||
|
string back = 3;
|
||||||
|
|
||||||
SchedulingStates states = 3;
|
SchedulingStates states = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
optional NextCardData next_card = 1;
|
optional NextCardData next_card = 1;
|
||||||
|
|
|
||||||
|
|
@ -400,6 +400,7 @@ impl crate::services::SchedulerService for Collection {
|
||||||
|
|
||||||
Ok(NextCardDataResponse {
|
Ok(NextCardDataResponse {
|
||||||
next_card: Some(NextCardData {
|
next_card: Some(NextCardData {
|
||||||
|
card_id: cid.0,
|
||||||
front: [style.clone(), render.question().to_string()].concat(),
|
front: [style.clone(), render.question().to_string()].concat(),
|
||||||
back: [style, render.answer().to_string()].concat(),
|
back: [style, render.answer().to_string()].concat(),
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// 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 { nextCardData } from "@generated/backend";
|
||||||
import { bridgeCommand } from "@tslib/bridgecommand";
|
import { bridgeCommand } from "@tslib/bridgecommand";
|
||||||
import { writable } from "svelte/store";
|
import { writable } from "svelte/store";
|
||||||
|
|
@ -8,7 +11,8 @@ import { writable } from "svelte/store";
|
||||||
export function setupReviewer(iframe: HTMLIFrameElement) {
|
export function setupReviewer(iframe: HTMLIFrameElement) {
|
||||||
const cardClass = writable("");
|
const cardClass = writable("");
|
||||||
let answer_html = "";
|
let answer_html = "";
|
||||||
let _states: SchedulingStates | undefined = undefined;
|
let cardData: NextCardDataResponse_NextCardData | undefined = undefined;
|
||||||
|
let startAnswering = Date.now();
|
||||||
|
|
||||||
function updateHtml(htmlString) {
|
function updateHtml(htmlString) {
|
||||||
iframe.contentWindow?.postMessage({ type: "html", value: htmlString }, "*");
|
iframe.contentWindow?.postMessage({ type: "html", value: htmlString }, "*");
|
||||||
|
|
@ -21,7 +25,7 @@ export function setupReviewer(iframe: HTMLIFrameElement) {
|
||||||
// TODO: "Congratulation screen" logic
|
// TODO: "Congratulation screen" logic
|
||||||
const question = resp.nextCard?.front || "";
|
const question = resp.nextCard?.front || "";
|
||||||
answer_html = resp.nextCard?.back || "";
|
answer_html = resp.nextCard?.back || "";
|
||||||
_states = resp.nextCard?.states;
|
cardData = resp.nextCard;
|
||||||
console.log({ resp });
|
console.log({ resp });
|
||||||
updateHtml(question);
|
updateHtml(question);
|
||||||
}
|
}
|
||||||
|
|
@ -35,6 +39,28 @@ export function setupReviewer(iframe: HTMLIFrameElement) {
|
||||||
showQuestion(null);
|
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);
|
iframe?.addEventListener("load", onReady);
|
||||||
|
|
||||||
addEventListener("message", (e) => {
|
addEventListener("message", (e) => {
|
||||||
|
|
@ -58,5 +84,5 @@ export function setupReviewer(iframe: HTMLIFrameElement) {
|
||||||
globalThis._showQuestion = showQuestion;
|
globalThis._showQuestion = showQuestion;
|
||||||
globalThis._showAnswer = showAnswer;
|
globalThis._showAnswer = showAnswer;
|
||||||
|
|
||||||
return { cardClass };
|
return { cardClass, easeButtonPressed };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue