Card info cleanup (#1446)

* Cast proto interface to type ...

... instead of using non-null assertions in Revlog.svelte.

* Remove OptionalInt32 and OptionalUInt32
This commit is contained in:
RumovZ 2021-10-23 03:00:43 +02:00 committed by GitHub
parent bf6efde785
commit 1c9b5a2e83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 32 deletions

View file

@ -7,14 +7,6 @@ package anki.generic;
message Empty {} message Empty {}
message OptionalInt32 {
sint32 val = 1;
}
message OptionalUInt32 {
uint32 val = 1;
}
message Int32 { message Int32 {
sint32 val = 1; sint32 val = 1;
} }

View file

@ -71,7 +71,7 @@ message Notetype {
bytes other = 255; bytes other = 255;
} }
generic.OptionalUInt32 ord = 1; generic.UInt32 ord = 1;
string name = 2; string name = 2;
Config config = 5; Config config = 5;
} }
@ -88,7 +88,7 @@ message Notetype {
bytes other = 255; bytes other = 255;
} }
generic.OptionalUInt32 ord = 1; generic.UInt32 ord = 1;
string name = 2; string name = 2;
int64 mtime_secs = 3; int64 mtime_secs = 3;
sint32 usn = 4; sint32 usn = 4;

View file

@ -3,7 +3,7 @@
use super::{NoteFieldConfig, NoteFieldProto}; use super::{NoteFieldConfig, NoteFieldProto};
use crate::{ use crate::{
backend_proto::OptionalUInt32, backend_proto::UInt32,
error::{AnkiError, Result}, error::{AnkiError, Result},
}; };
@ -17,7 +17,7 @@ pub struct NoteField {
impl From<NoteField> for NoteFieldProto { impl From<NoteField> for NoteFieldProto {
fn from(f: NoteField) -> Self { fn from(f: NoteField) -> Self {
NoteFieldProto { NoteFieldProto {
ord: f.ord.map(|n| OptionalUInt32 { val: n }), ord: f.ord.map(|n| UInt32 { val: n }),
name: f.name, name: f.name,
config: Some(f.config), config: Some(f.config),
} }

View file

@ -3,7 +3,7 @@
use super::{CardTemplateConfig, CardTemplateProto}; use super::{CardTemplateConfig, CardTemplateProto};
use crate::{ use crate::{
backend_proto::OptionalUInt32, backend_proto::UInt32,
decks::DeckId, decks::DeckId,
error::{AnkiError, Result}, error::{AnkiError, Result},
template::ParsedTemplate, template::ParsedTemplate,
@ -57,7 +57,7 @@ impl CardTemplate {
impl From<CardTemplate> for CardTemplateProto { impl From<CardTemplate> for CardTemplateProto {
fn from(t: CardTemplate) -> Self { fn from(t: CardTemplate) -> Self {
CardTemplateProto { CardTemplateProto {
ord: t.ord.map(|n| OptionalUInt32 { val: n }), ord: t.ord.map(|n| UInt32 { val: n }),
mtime_secs: t.mtime_secs.0, mtime_secs: t.mtime_secs.0,
usn: t.usn.0, usn: t.usn.0,
name: t.name, name: t.name,

View file

@ -9,9 +9,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
export let stats: Stats.CardStatsResponse; export let stats: Stats.CardStatsResponse;
type IStatsRevlogEntry = Stats.CardStatsResponse.IStatsRevlogEntry; type StatsRevlogEntry = Stats.CardStatsResponse.StatsRevlogEntry;
function reviewKindClass(entry: IStatsRevlogEntry): string { function reviewKindClass(entry: StatsRevlogEntry): string {
switch (entry.reviewKind) { switch (entry.reviewKind) {
case Stats.RevlogEntry.ReviewKind.LEARNING: case Stats.RevlogEntry.ReviewKind.LEARNING:
return "revlog-learn"; return "revlog-learn";
@ -23,7 +23,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
return ""; return "";
} }
function reviewKindLabel(entry: IStatsRevlogEntry): string { function reviewKindLabel(entry: StatsRevlogEntry): string {
switch (entry.reviewKind) { switch (entry.reviewKind) {
case Stats.RevlogEntry.ReviewKind.LEARNING: case Stats.RevlogEntry.ReviewKind.LEARNING:
return tr2.cardStatsReviewLogTypeLearn(); return tr2.cardStatsReviewLogTypeLearn();
@ -38,7 +38,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
} }
} }
function ratingClass(entry: IStatsRevlogEntry): string { function ratingClass(entry: StatsRevlogEntry): string {
if (entry.buttonChosen === 1) { if (entry.buttonChosen === 1) {
return "revlog-ease1"; return "revlog-ease1";
} }
@ -57,23 +57,25 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
takenSecs: string; takenSecs: string;
} }
function revlogRowFromEntry(entry: IStatsRevlogEntry): RevlogRow { function revlogRowFromEntry(entry: StatsRevlogEntry): RevlogRow {
const timestamp = new Timestamp(entry.time!); const timestamp = new Timestamp(entry.time);
return { return {
date: timestamp.dateString(), date: timestamp.dateString(),
time: timestamp.timeString(), time: timestamp.timeString(),
reviewKind: reviewKindLabel(entry), reviewKind: reviewKindLabel(entry),
reviewKindClass: reviewKindClass(entry), reviewKindClass: reviewKindClass(entry),
rating: entry.buttonChosen!, rating: entry.buttonChosen,
ratingClass: ratingClass(entry), ratingClass: ratingClass(entry),
interval: timeSpan(entry.interval!), interval: timeSpan(entry.interval),
ease: entry.ease ? `${entry.ease / 10}%` : "", ease: entry.ease ? `${entry.ease / 10}%` : "",
takenSecs: timeSpan(entry.takenSecs!, true), takenSecs: timeSpan(entry.takenSecs, true),
}; };
} }
let revlogRows: RevlogRow[]; let revlogRows: RevlogRow[];
$: revlogRows = stats.revlog.map((entry) => revlogRowFromEntry(entry)); $: revlogRows = stats.revlog.map((entry) =>
revlogRowFromEntry(entry as StatsRevlogEntry),
);
</script> </script>
{#if stats.revlog.length} {#if stats.revlog.length}

View file

@ -14,14 +14,7 @@ import Tags = anki.tags;
export { Stats, Cards, DeckConfig, Notetypes, Scheduler, Tags }; export { Stats, Cards, DeckConfig, Notetypes, Scheduler, Tags };
export function unwrapOptionalNumber( export function unwrapOptionalNumber(
msg: msg: Generic.IInt64 | Generic.IUInt32 | Generic.IInt32 | null | undefined,
| Generic.IInt64
| Generic.IUInt32
| Generic.IInt32
| Generic.OptionalInt32
| Generic.OptionalUInt32
| null
| undefined,
): number | undefined { ): number | undefined {
if (msg && msg !== null) { if (msg && msg !== null) {
if (msg.val !== null) { if (msg.val !== null) {