if learning step crossed day boundary, reflect that on the answer button

This commit is contained in:
Damien Elmes 2021-02-22 21:16:22 +10:00
parent 08c5fe474a
commit e1e552ff93
2 changed files with 50 additions and 27 deletions

View file

@ -34,7 +34,7 @@ use crate::{
new::NewCardSortOrder,
parse_due_date_str,
states::NextCardStates,
timespan::{answer_button_time, answer_button_time_collapsible, time_span},
timespan::{answer_button_time, time_span},
},
search::{
concatenate_searches, parse_search, replace_search_node, write_nodes, BoolSeparator, Node,
@ -678,32 +678,9 @@ impl BackendService for Backend {
}
fn describe_next_states(&self, input: pb::NextCardStates) -> BackendResult<pb::StringList> {
let collapse_time = self.with_col(|col| Ok(col.learn_ahead_secs()))?;
let choices: NextCardStates = input.into();
Ok(vec![
answer_button_time_collapsible(
choices.again.interval_kind().as_seconds(),
collapse_time,
&self.i18n,
),
answer_button_time_collapsible(
choices.hard.interval_kind().as_seconds(),
collapse_time,
&self.i18n,
),
answer_button_time_collapsible(
choices.good.interval_kind().as_seconds(),
collapse_time,
&self.i18n,
),
answer_button_time_collapsible(
choices.easy.interval_kind().as_seconds(),
collapse_time,
&self.i18n,
),
]
.into())
let states: NextCardStates = input.into();
self.with_col(|col| col.describe_next_states(states))
.map(Into::into)
}
fn answer_card(&self, input: pb::AnswerCardIn) -> BackendResult<pb::Empty> {

View file

@ -17,6 +17,7 @@ use super::{
NextCardStates, NormalState, PreviewState, RelearnState, ReschedulingFilterState,
ReviewState, StateContext,
},
timespan::answer_button_time_collapsible,
};
#[derive(Copy, Clone)]
@ -422,6 +423,51 @@ impl RevlogEntryPartial {
}
impl Collection {
pub fn describe_next_states(&self, choices: NextCardStates) -> Result<Vec<String>> {
let collapse_time = self.learn_ahead_secs();
let now = TimestampSecs::now();
let timing = self.timing_for_timestamp(now)?;
let secs_until_rollover = (timing.next_day_at - now.0).max(0) as u32;
Ok(vec![
answer_button_time_collapsible(
choices
.again
.interval_kind()
.maybe_as_days(secs_until_rollover)
.as_seconds(),
collapse_time,
&self.i18n,
),
answer_button_time_collapsible(
choices
.hard
.interval_kind()
.maybe_as_days(secs_until_rollover)
.as_seconds(),
collapse_time,
&self.i18n,
),
answer_button_time_collapsible(
choices
.good
.interval_kind()
.maybe_as_days(secs_until_rollover)
.as_seconds(),
collapse_time,
&self.i18n,
),
answer_button_time_collapsible(
choices
.easy
.interval_kind()
.maybe_as_days(secs_until_rollover)
.as_seconds(),
collapse_time,
&self.i18n,
),
])
}
pub fn answer_card(&mut self, answer: &CardAnswer) -> Result<()> {
self.transact(None, |col| col.answer_card_inner(answer))
}