From e1e552ff9364c05ed3e9ead49cabb9bbb0e163ba Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 22 Feb 2021 21:16:22 +1000 Subject: [PATCH] if learning step crossed day boundary, reflect that on the answer button --- rslib/src/backend/mod.rs | 31 ++++-------------------- rslib/src/sched/answering.rs | 46 ++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 27 deletions(-) diff --git a/rslib/src/backend/mod.rs b/rslib/src/backend/mod.rs index 235018f47..23a57433d 100644 --- a/rslib/src/backend/mod.rs +++ b/rslib/src/backend/mod.rs @@ -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 { - 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 { diff --git a/rslib/src/sched/answering.rs b/rslib/src/sched/answering.rs index 7db20b072..7360968b0 100644 --- a/rslib/src/sched/answering.rs +++ b/rslib/src/sched/answering.rs @@ -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> { + 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)) }