From 8cf8c901fea1c4c0c5f61a6c97faf5dee30f7594 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 17 Apr 2021 12:53:59 +1000 Subject: [PATCH] fix parent limit handling We can't calculate it on the backend, as adjusting a config may alter the parent limit. Also fix hidden deck name and missing separator. --- rslib/backend.proto | 3 +-- rslib/src/deckconf/update.rs | 18 +++++---------- ts/deckconfig/ConfigSelector.svelte | 30 +++++++++++++++++-------- ts/deckconfig/DeckConfigPage.svelte | 3 --- ts/deckconfig/NewOptions.svelte | 3 ++- ts/deckconfig/lib.ts | 34 ++++++++++++++++++++++++++++- 6 files changed, 63 insertions(+), 28 deletions(-) diff --git a/rslib/backend.proto b/rslib/backend.proto index 87ed71f1d..e58d5b70e 100644 --- a/rslib/backend.proto +++ b/rslib/backend.proto @@ -903,8 +903,7 @@ message DeckConfigForUpdate { message CurrentDeck { string name = 1; int64 config_id = 2; - uint32 parent_new_limit = 3; - uint32 parent_review_limit = 4; + repeated int64 parent_config_ids = 3; } repeated ConfigWithExtra all_config = 1; diff --git a/rslib/src/deckconf/update.rs b/rslib/src/deckconf/update.rs index 739ffdf7c..98ed1c6a0 100644 --- a/rslib/src/deckconf/update.rs +++ b/rslib/src/deckconf/update.rs @@ -49,20 +49,14 @@ impl Collection { fn get_current_deck_for_update(&mut self, deck: DeckId) -> Result { let deck = self.get_deck(deck)?.ok_or(AnkiError::NotFound)?; - let mut parent_new_limit = u32::MAX; - let mut parent_review_limit = u32::MAX; - for config_id in self.parent_config_ids(&deck)? { - if let Some(config) = self.storage.get_deck_config(config_id)? { - parent_new_limit = parent_new_limit.min(config.inner.new_per_day); - parent_review_limit = parent_review_limit.min(config.inner.reviews_per_day); - } - } - Ok(CurrentDeck { - name: deck.name.clone(), + name: deck.human_name(), config_id: deck.normal()?.config_id, - parent_new_limit, - parent_review_limit, + parent_config_ids: self + .parent_config_ids(&deck)? + .into_iter() + .map(Into::into) + .collect(), }) } diff --git a/ts/deckconfig/ConfigSelector.svelte b/ts/deckconfig/ConfigSelector.svelte index 990add066..a2eea62a0 100644 --- a/ts/deckconfig/ConfigSelector.svelte +++ b/ts/deckconfig/ConfigSelector.svelte @@ -46,19 +46,31 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html padding-right: 0.5em; } } + + .padding { + height: 2.5em; + }
- - +
+
{tr.actionsOptionsFor({ val: state.currentDeck.name })}
- + + + + +
+ +
+ +
diff --git a/ts/deckconfig/DeckConfigPage.svelte b/ts/deckconfig/DeckConfigPage.svelte index 84b181b50..cd7c764bf 100644 --- a/ts/deckconfig/DeckConfigPage.svelte +++ b/ts/deckconfig/DeckConfigPage.svelte @@ -5,7 +5,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
diff --git a/ts/deckconfig/lib.ts b/ts/deckconfig/lib.ts index f9e294a0c..232c92a98 100644 --- a/ts/deckconfig/lib.ts +++ b/ts/deckconfig/lib.ts @@ -26,6 +26,11 @@ export interface ConfigWithCount { useCount: number; } +export interface ParentLimits { + newCards: number; + reviews: number; +} + /// Info for showing the top selector export interface ConfigListEntry { idx: number; @@ -38,12 +43,14 @@ type ConfigInner = pb.BackendProto.DeckConfig.Config; export class DeckConfigState { readonly currentConfig: Writable; readonly configList: Readable; + readonly parentLimits: Readable; readonly currentDeck: pb.BackendProto.DeckConfigForUpdate.CurrentDeck; readonly defaults: ConfigInner; private configs: ConfigWithCount[]; private selectedIdx: number; private configListSetter?: (val: ConfigListEntry[]) => void; + private parentLimitsSetter?: (val: ParentLimits) => void; private removedConfigs: DeckConfigId[] = []; constructor(data: pb.BackendProto.DeckConfigForUpdate) { @@ -64,7 +71,11 @@ export class DeckConfigState { this.currentConfig = writable(this.getCurrentConfig()); this.configList = readable(this.getConfigList(), (set) => { this.configListSetter = set; - return undefined; + return; + }); + this.parentLimits = readable(this.getParentLimits(), (set) => { + this.parentLimitsSetter = set; + return; }); } @@ -144,6 +155,7 @@ export class DeckConfigState { private updateCurrentConfig(): void { this.currentConfig.set(this.getCurrentConfig()); + this.parentLimitsSetter?.(this.getParentLimits()); } private updateConfigList(): void { @@ -170,4 +182,24 @@ export class DeckConfigState { ); return list; } + + private getParentLimits(): ParentLimits { + const parentConfigs = this.configs.filter((c) => + this.currentDeck.parentConfigIds.includes(c.config.id) + ); + const newCards = parentConfigs.reduce( + (previous, current) => + Math.min(previous, current.config.config?.newPerDay ?? 0), + 2 ** 31 + ); + const reviews = parentConfigs.reduce( + (previous, current) => + Math.min(previous, current.config.config?.reviewsPerDay ?? 0), + 2 ** 31 + ); + return { + newCards, + reviews, + }; + } }