Skip to content

Commit

Permalink
Feature Show Reminder before answer (#3064) (#3119)
Browse files Browse the repository at this point in the history
* Feature Question Action Show Reminder (#3064)

Added a option in the deck config that allow the user to choose in
Autoupdate mode between showing a reminder or revealing the card.
Also added my name to the contributors

* Update ftl/core/deck-config.ftl
  • Loading branch information
Loudwig committed Apr 13, 2024
1 parent e486d6b commit d8f2782
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ ijqq <ijqq@protonmail.ch>
AntoineQ1 <https://github.com/AntoineQ1>
jthulhu <https://github.com/jthulhu>
Escape0707 <tothesong@gmail.com>
Loudwig <https://github.com/Loudwig>
Wu Yi-Wei <https://github.com/Ianwu0812>

********************

The text of the 3 clause BSD license follows:
Expand Down
4 changes: 4 additions & 0 deletions ftl/core/deck-config.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ deck-config-seconds-to-show-question = Seconds to show question for
deck-config-seconds-to-show-question-tooltip-2 = When auto advance is activated, the number of seconds to wait before revealing the answer. Set to 0 to disable.
deck-config-seconds-to-show-answer = Seconds to show answer for
deck-config-seconds-to-show-answer-tooltip-2 = When auto advance is activated, the number of seconds to wait before applying the answer action. Set to 0 to disable.
deck-config-question-action-show-answer = Show Answer
deck-config-question-action-show-reminder = Show Reminder
deck-config-question-action = Question action
deck-config-question-action-tool-tip = The action to perform after the question is shown, and time has elapsed.
deck-config-answer-action = Answer action
deck-config-answer-action-tooltip = The action to perform on the current card before automatically advancing to the next one.
deck-config-wait-for-audio-tooltip = Wait for audio to finish before automatically revealing answer or next question
Expand Down
1 change: 1 addition & 0 deletions ftl/core/studying.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ studying-minute =
[one] { $count } minute.
*[other] { $count } minutes.
}
studying-question-time-elapsed = Question time elapsed
studying-answer-time-elapsed = Answer time elapsed
6 changes: 5 additions & 1 deletion proto/anki/deck_config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ message DeckConfig {
ANSWER_ACTION_ANSWER_HARD = 3;
ANSWER_ACTION_SHOW_REMINDER = 4;
}

enum QuestionAction {
QUESTION_ACTION_SHOW_ANSWER = 0;
QUESTION_ACTION_SHOW_REMINDER = 1;
}
repeated float learn_steps = 1;
repeated float relearn_steps = 2;

Expand Down Expand Up @@ -144,6 +147,7 @@ message DeckConfig {
bool stop_timer_on_answer = 38;
float seconds_to_show_question = 41;
float seconds_to_show_answer = 42;
QuestionAction question_action = 36;
AnswerAction answer_action = 43;
bool wait_for_audio = 44;
bool skip_question_when_replaying_answer = 26;
Expand Down
15 changes: 14 additions & 1 deletion qt/aqt/reviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ class AnswerAction(Enum):
SHOW_REMINDER = 4


class QuestionAction(Enum):
SHOW_ANSWER = 0
SHOW_REMINDER = 1


class Reviewer:
def __init__(self, mw: AnkiQt) -> None:
self.mw = mw
Expand Down Expand Up @@ -423,7 +428,15 @@ def _on_show_answer_timeout(self) -> None:
):
self.auto_advance_enabled = False
return
self._showAnswer()
try:
question_action = list(QuestionAction)[conf["questionAction"]]
except IndexError:
question_action = QuestionAction.SHOW_ANSWER

if question_action == QuestionAction.SHOW_ANSWER:
self._showAnswer()
else:
tooltip(tr.studying_question_time_elapsed())

def autoplay(self, card: Card) -> bool:
print("use card.autoplay() instead of reviewer.autoplay(card)")
Expand Down
2 changes: 2 additions & 0 deletions rslib/src/deckconfig/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub use anki_proto::deck_config::deck_config::config::LeechAction;
pub use anki_proto::deck_config::deck_config::config::NewCardGatherPriority;
pub use anki_proto::deck_config::deck_config::config::NewCardInsertOrder;
pub use anki_proto::deck_config::deck_config::config::NewCardSortOrder;
pub use anki_proto::deck_config::deck_config::config::QuestionAction;
pub use anki_proto::deck_config::deck_config::config::ReviewCardOrder;
pub use anki_proto::deck_config::deck_config::config::ReviewMix;
pub use anki_proto::deck_config::deck_config::Config as DeckConfigInner;
Expand Down Expand Up @@ -66,6 +67,7 @@ const DEFAULT_DECK_CONFIG_INNER: DeckConfigInner = DeckConfigInner {
stop_timer_on_answer: false,
seconds_to_show_question: 0.0,
seconds_to_show_answer: 0.0,
question_action: QuestionAction::ShowAnswer as i32,
answer_action: AnswerAction::BuryCard as i32,
wait_for_audio: true,
skip_question_when_replaying_answer: false,
Expand Down
17 changes: 17 additions & 0 deletions rslib/src/deckconfig/schema11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ pub struct DeckConfSchema11 {
#[serde(default)]
seconds_to_show_answer: f32,
#[serde(default)]
question_action: QuestionAction,
#[serde(default)]
answer_action: AnswerAction,
#[serde(default = "wait_for_audio_default")]
wait_for_audio: bool,
Expand All @@ -94,6 +96,14 @@ pub struct DeckConfSchema11 {
#[serde(flatten)]
other: HashMap<String, Value>,
}
#[derive(Serialize_repr, Deserialize_repr, Debug, PartialEq, Eq, Clone)]
#[repr(u8)]
#[derive(Default)]
pub enum QuestionAction {
#[default]
ShowAnswer = 0,
ShowReminder = 1,
}

#[derive(Serialize_repr, Deserialize_repr, Debug, PartialEq, Eq, Clone)]
#[repr(u8)]
Expand Down Expand Up @@ -278,6 +288,7 @@ impl Default for DeckConfSchema11 {
stop_timer_on_answer: false,
seconds_to_show_question: 0.0,
seconds_to_show_answer: 0.0,
question_action: QuestionAction::ShowAnswer,
answer_action: AnswerAction::BuryCard,
wait_for_audio: true,
replayq: true,
Expand Down Expand Up @@ -365,6 +376,7 @@ impl From<DeckConfSchema11> for DeckConfig {
stop_timer_on_answer: c.stop_timer_on_answer,
seconds_to_show_question: c.seconds_to_show_question,
seconds_to_show_answer: c.seconds_to_show_answer,
question_action: c.question_action as i32,
answer_action: c.answer_action as i32,
wait_for_audio: c.wait_for_audio,
skip_question_when_replaying_answer: !c.replayq,
Expand Down Expand Up @@ -431,6 +443,10 @@ impl From<DeckConfig> for DeckConfSchema11 {
4 => AnswerAction::ShowReminder,
_ => AnswerAction::BuryCard,
},
question_action: match i.question_action {
1 => QuestionAction::ShowReminder,
_ => QuestionAction::ShowAnswer,
},
wait_for_audio: i.wait_for_audio,
replayq: !i.skip_question_when_replaying_answer,
dynamic: false,
Expand Down Expand Up @@ -509,6 +525,7 @@ static RESERVED_DECKCONF_KEYS: Set<&'static str> = phf_set! {
"stopTimerOnAnswer",
"secondsToShowQuestion",
"secondsToShowAnswer",
"questionAction",
"answerAction",
"waitForAudio",
"sm2Retention",
Expand Down
20 changes: 19 additions & 1 deletion ts/routes/deck-options/AutoAdvance.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import TitledContainer from "$lib/components/TitledContainer.svelte";
import type { HelpItem } from "$lib/components/types";
import { answerChoices } from "./choices";
import { answerChoices, questionActionChoices } from "./choices";
import type { DeckOptionsState } from "./lib";
import SpinBoxFloatRow from "./SpinBoxFloatRow.svelte";
Expand All @@ -44,6 +44,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
title: tr.deckConfigAnswerAction(),
help: tr.deckConfigAnswerActionTooltip(),
},
questionAction: {
title: tr.deckConfigQuestionAction(),
help: tr.deckConfigQuestionActionToolTip(),
},
};
const helpSections = Object.values(settings) as HelpItem[];
Expand Down Expand Up @@ -130,5 +134,19 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
</SettingTitle>
</EnumSelectorRow>
</Item>
<Item>
<EnumSelectorRow
bind:value={$config.questionAction}
defaultValue={defaults.questionAction}
choices={questionActionChoices()}
>
<SettingTitle
on:click={() =>
openHelpModal(Object.keys(settings).indexOf("questionAction"))}
>
{settings.questionAction.title}
</SettingTitle>
</EnumSelectorRow>
</Item>
</DynamicallySlottable>
</TitledContainer>
13 changes: 13 additions & 0 deletions ts/routes/deck-options/choices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
DeckConfig_Config_NewCardGatherPriority,
DeckConfig_Config_NewCardInsertOrder,
DeckConfig_Config_NewCardSortOrder,
DeckConfig_Config_QuestionAction,
DeckConfig_Config_ReviewCardOrder,
DeckConfig_Config_ReviewMix,
} from "@generated/anki/deck_config_pb";
Expand Down Expand Up @@ -184,3 +185,15 @@ export function answerChoices(): Choice<DeckConfig_Config_AnswerAction>[] {
},
];
}
export function questionActionChoices(): Choice<DeckConfig_Config_QuestionAction>[] {
return [
{
label: tr.deckConfigQuestionActionShowAnswer(),
value: DeckConfig_Config_QuestionAction.SHOW_ANSWER,
},
{
label: tr.deckConfigQuestionActionShowReminder(),
value: DeckConfig_Config_QuestionAction.SHOW_REMINDER,
},
];
}

0 comments on commit d8f2782

Please sign in to comment.