mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 15:32:23 -04:00
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:
parent
bf6efde785
commit
1c9b5a2e83
6 changed files with 19 additions and 32 deletions
|
@ -7,14 +7,6 @@ package anki.generic;
|
|||
|
||||
message Empty {}
|
||||
|
||||
message OptionalInt32 {
|
||||
sint32 val = 1;
|
||||
}
|
||||
|
||||
message OptionalUInt32 {
|
||||
uint32 val = 1;
|
||||
}
|
||||
|
||||
message Int32 {
|
||||
sint32 val = 1;
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ message Notetype {
|
|||
|
||||
bytes other = 255;
|
||||
}
|
||||
generic.OptionalUInt32 ord = 1;
|
||||
generic.UInt32 ord = 1;
|
||||
string name = 2;
|
||||
Config config = 5;
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ message Notetype {
|
|||
bytes other = 255;
|
||||
}
|
||||
|
||||
generic.OptionalUInt32 ord = 1;
|
||||
generic.UInt32 ord = 1;
|
||||
string name = 2;
|
||||
int64 mtime_secs = 3;
|
||||
sint32 usn = 4;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
use super::{NoteFieldConfig, NoteFieldProto};
|
||||
use crate::{
|
||||
backend_proto::OptionalUInt32,
|
||||
backend_proto::UInt32,
|
||||
error::{AnkiError, Result},
|
||||
};
|
||||
|
||||
|
@ -17,7 +17,7 @@ pub struct NoteField {
|
|||
impl From<NoteField> for NoteFieldProto {
|
||||
fn from(f: NoteField) -> Self {
|
||||
NoteFieldProto {
|
||||
ord: f.ord.map(|n| OptionalUInt32 { val: n }),
|
||||
ord: f.ord.map(|n| UInt32 { val: n }),
|
||||
name: f.name,
|
||||
config: Some(f.config),
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
use super::{CardTemplateConfig, CardTemplateProto};
|
||||
use crate::{
|
||||
backend_proto::OptionalUInt32,
|
||||
backend_proto::UInt32,
|
||||
decks::DeckId,
|
||||
error::{AnkiError, Result},
|
||||
template::ParsedTemplate,
|
||||
|
@ -57,7 +57,7 @@ impl CardTemplate {
|
|||
impl From<CardTemplate> for CardTemplateProto {
|
||||
fn from(t: CardTemplate) -> Self {
|
||||
CardTemplateProto {
|
||||
ord: t.ord.map(|n| OptionalUInt32 { val: n }),
|
||||
ord: t.ord.map(|n| UInt32 { val: n }),
|
||||
mtime_secs: t.mtime_secs.0,
|
||||
usn: t.usn.0,
|
||||
name: t.name,
|
||||
|
|
|
@ -9,9 +9,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
|
||||
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) {
|
||||
case Stats.RevlogEntry.ReviewKind.LEARNING:
|
||||
return "revlog-learn";
|
||||
|
@ -23,7 +23,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
return "";
|
||||
}
|
||||
|
||||
function reviewKindLabel(entry: IStatsRevlogEntry): string {
|
||||
function reviewKindLabel(entry: StatsRevlogEntry): string {
|
||||
switch (entry.reviewKind) {
|
||||
case Stats.RevlogEntry.ReviewKind.LEARNING:
|
||||
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) {
|
||||
return "revlog-ease1";
|
||||
}
|
||||
|
@ -57,23 +57,25 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
takenSecs: string;
|
||||
}
|
||||
|
||||
function revlogRowFromEntry(entry: IStatsRevlogEntry): RevlogRow {
|
||||
const timestamp = new Timestamp(entry.time!);
|
||||
function revlogRowFromEntry(entry: StatsRevlogEntry): RevlogRow {
|
||||
const timestamp = new Timestamp(entry.time);
|
||||
return {
|
||||
date: timestamp.dateString(),
|
||||
time: timestamp.timeString(),
|
||||
reviewKind: reviewKindLabel(entry),
|
||||
reviewKindClass: reviewKindClass(entry),
|
||||
rating: entry.buttonChosen!,
|
||||
rating: entry.buttonChosen,
|
||||
ratingClass: ratingClass(entry),
|
||||
interval: timeSpan(entry.interval!),
|
||||
interval: timeSpan(entry.interval),
|
||||
ease: entry.ease ? `${entry.ease / 10}%` : "",
|
||||
takenSecs: timeSpan(entry.takenSecs!, true),
|
||||
takenSecs: timeSpan(entry.takenSecs, true),
|
||||
};
|
||||
}
|
||||
|
||||
let revlogRows: RevlogRow[];
|
||||
$: revlogRows = stats.revlog.map((entry) => revlogRowFromEntry(entry));
|
||||
$: revlogRows = stats.revlog.map((entry) =>
|
||||
revlogRowFromEntry(entry as StatsRevlogEntry),
|
||||
);
|
||||
</script>
|
||||
|
||||
{#if stats.revlog.length}
|
||||
|
|
|
@ -14,14 +14,7 @@ import Tags = anki.tags;
|
|||
export { Stats, Cards, DeckConfig, Notetypes, Scheduler, Tags };
|
||||
|
||||
export function unwrapOptionalNumber(
|
||||
msg:
|
||||
| Generic.IInt64
|
||||
| Generic.IUInt32
|
||||
| Generic.IInt32
|
||||
| Generic.OptionalInt32
|
||||
| Generic.OptionalUInt32
|
||||
| null
|
||||
| undefined,
|
||||
msg: Generic.IInt64 | Generic.IUInt32 | Generic.IInt32 | null | undefined,
|
||||
): number | undefined {
|
||||
if (msg && msg !== null) {
|
||||
if (msg.val !== null) {
|
||||
|
|
Loading…
Reference in a new issue