2020-08-27 13:46:34 +02:00
|
|
|
// Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
|
2021-04-22 19:55:26 +02:00
|
|
|
import pb from "lib/backend_proto";
|
|
|
|
import { postRequest } from "lib/postrequest";
|
|
|
|
import { naturalUnit, unitAmount, unitName } from "lib/time";
|
2021-03-26 11:23:43 +01:00
|
|
|
|
2021-04-22 19:55:26 +02:00
|
|
|
import * as tr from "lib/i18n";
|
2020-08-27 13:46:34 +02:00
|
|
|
|
|
|
|
export async function getCongratsInfo(): Promise<pb.BackendProto.CongratsInfoOut> {
|
|
|
|
return pb.BackendProto.CongratsInfoOut.decode(
|
|
|
|
await postRequest("/_anki/congratsInfo", "")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-03-26 11:23:43 +01:00
|
|
|
export function buildNextLearnMsg(info: pb.BackendProto.CongratsInfoOut): string {
|
2020-08-27 13:46:34 +02:00
|
|
|
const secsUntil = info.secsUntilNextLearn;
|
|
|
|
// next learning card not due (/ until tomorrow)?
|
|
|
|
if (secsUntil == 0 || secsUntil > 86_400) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
const unit = naturalUnit(secsUntil);
|
|
|
|
const amount = Math.round(unitAmount(unit, secsUntil));
|
|
|
|
const unitStr = unitName(unit);
|
2021-03-26 11:23:43 +01:00
|
|
|
const nextLearnDue = tr.schedulingNextLearnDue({
|
2020-08-27 13:46:34 +02:00
|
|
|
amount,
|
|
|
|
unit: unitStr,
|
|
|
|
});
|
2021-03-26 11:23:43 +01:00
|
|
|
const remaining = tr.schedulingLearnRemaining({
|
2020-08-27 13:46:34 +02:00
|
|
|
remaining: info.learnRemaining,
|
|
|
|
});
|
|
|
|
return `${nextLearnDue} ${remaining}`;
|
|
|
|
}
|