anki/ts/congrats/CongratsPage.svelte

77 lines
2.0 KiB
Svelte
Raw Normal View History

<!--
Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script lang="ts">
refactor protobuf handling for split/import In order to split backend.proto into a more manageable size, the protobuf handling needed to be updated. This took more time than I would have liked, as each language handles protobuf differently: - The Python Protobuf code ignores "package" directives, and relies solely on how the files are laid out on disk. While it would have been nice to keep the generated files in a private subpackage, Protobuf gets confused if the files are located in a location that does not match their original .proto layout, so the old approach of storing them in _backend/ will not work. They now clutter up pylib/anki instead. I'm rather annoyed by that, but alternatives seem to be having to add an extra level to the Protobuf path, making the other languages suffer, or trying to hack around the issue by munging sys.modules. - Protobufjs fails to expose packages if they don't start with a capital letter, despite the fact that lowercase packages are the norm in most languages :-( This required a patch to fix. - Rust was the easiest, as Prost is relatively straightforward compared to Google's tools. The Protobuf files are now stored in /proto/anki, with a separate package for each file. I've split backend.proto into a few files as a test, but the majority of that work is still to come. The Python Protobuf building is a bit of a hack at the moment, hard-coding "proto" as the top level folder, but it seems to get the job done for now. Also changed the workspace name, as there seems to be a number of Bazel repos moving away from the more awkward reverse DNS naming style.
2021-07-10 09:50:18 +02:00
import type { Backend } from "lib/proto";
import { buildNextLearnMsg } from "./lib";
import { bridgeLink } from "lib/bridgecommand";
refactor protobuf handling for split/import In order to split backend.proto into a more manageable size, the protobuf handling needed to be updated. This took more time than I would have liked, as each language handles protobuf differently: - The Python Protobuf code ignores "package" directives, and relies solely on how the files are laid out on disk. While it would have been nice to keep the generated files in a private subpackage, Protobuf gets confused if the files are located in a location that does not match their original .proto layout, so the old approach of storing them in _backend/ will not work. They now clutter up pylib/anki instead. I'm rather annoyed by that, but alternatives seem to be having to add an extra level to the Protobuf path, making the other languages suffer, or trying to hack around the issue by munging sys.modules. - Protobufjs fails to expose packages if they don't start with a capital letter, despite the fact that lowercase packages are the norm in most languages :-( This required a patch to fix. - Rust was the easiest, as Prost is relatively straightforward compared to Google's tools. The Protobuf files are now stored in /proto/anki, with a separate package for each file. I've split backend.proto into a few files as a test, but the majority of that work is still to come. The Python Protobuf building is a bit of a hack at the moment, hard-coding "proto" as the top level folder, but it seems to get the job done for now. Also changed the workspace name, as there seems to be a number of Bazel repos moving away from the more awkward reverse DNS naming style.
2021-07-10 09:50:18 +02:00
export let info: Backend.CongratsInfoResponse;
import * as tr from "lib/i18n";
const congrats = tr.schedulingCongratulationsFinished();
const nextLearnMsg = buildNextLearnMsg(info);
const today_reviews = tr.schedulingTodayReviewLimitReached();
const today_new = tr.schedulingTodayNewLimitReached();
const unburyThem = bridgeLink("unbury", tr.schedulingUnburyThem());
const buriedMsg = tr.schedulingBuriedCardsFound({ unburyThem });
const customStudy = bridgeLink("customStudy", tr.schedulingCustomStudy());
const customStudyMsg = tr.schedulingHowToCustomStudy({
customStudy,
});
</script>
<div class="congrats-outer">
<div class="congrats-inner">
<h3>{congrats}</h3>
<p>{nextLearnMsg}</p>
{#if info.reviewRemaining}
<p>{today_reviews}</p>
{/if}
{#if info.newRemaining}
<p>{today_new}</p>
{/if}
{#if info.bridgeCommandsSupported}
{#if info.haveSchedBuried || info.haveUserBuried}
<p>
{@html buriedMsg}
</p>
{/if}
{#if !info.isFilteredDeck}
<p>
{@html customStudyMsg}
</p>
{/if}
{/if}
{#if info.deckDescription}
<div class="description">
{@html info.deckDescription}
</div>
{/if}
</div>
</div>
<style>
.congrats-outer {
display: flex;
justify-content: center;
}
.congrats-inner {
max-width: 30em;
}
.description {
border: 1px solid var(--border);
padding: 1em;
}
</style>