anki/ts/congrats/lib.ts
Damien Elmes 070f57fcc5 don't hide learning count on congrats screen when learning is overdue
The v3 scheduler will delay the final card from being shown twice in
a row, but the overdue case was being treated the same as the no-learning
case, leading to the message being hidden.
2021-08-02 15:57:09 +10:00

35 lines
1.1 KiB
TypeScript

// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { Scheduler } from "lib/proto";
import { postRequest } from "lib/postrequest";
import { naturalUnit, unitAmount, unitName } from "lib/time";
import * as tr from "lib/i18n";
export async function getCongratsInfo(): Promise<Scheduler.CongratsInfoResponse> {
return Scheduler.CongratsInfoResponse.decode(
await postRequest("/_anki/congratsInfo", "")
);
}
export function buildNextLearnMsg(info: Scheduler.CongratsInfoResponse): string {
const secsUntil = info.secsUntilNextLearn;
// next learning card not due today?
if (secsUntil >= 86_400) {
return "";
}
const unit = naturalUnit(secsUntil);
const amount = Math.round(unitAmount(unit, secsUntil));
const unitStr = unitName(unit);
const nextLearnDue = tr.schedulingNextLearnDue({
amount,
unit: unitStr,
});
const remaining = tr.schedulingLearnRemaining({
remaining: info.learnRemaining,
});
return `${nextLearnDue} ${remaining}`;
}