Fix deck data collecting

This commit is contained in:
micialware committed 2026-08-20 16:22:38 +03:00
1 parent c5e91b844c
commit 3f43676580
4 files changed
+63 -22

No files matched your search

+22 -2
View File
@@ -1,16 +1,17 @@
use crate::AppState;
use crate::data_provider::card_sets::{delete_set, update_deck};
use crate::data_provider::card_stats::{delete_stats, load_stats_of_deck};
use crate::lang::DeckSettings;
use crate::navigation::Page::PreviousPage;
use crate::navigation::{NavigatedPage, Page, RootMessage};
use crate::repetition_settings::RepetitionSettingsMessage::*;
use crate::styling::*;
use crate::AppState;
use iced::widget::button::danger;
use iced::widget::text_input::Catalog;
use iced::widget::{button, column, row, scrollable, space, text, text_input};
use iced::{Element, Task};
use iced_core::Length::Fill;
use iced_core::{Padding, Theme, color};
use iced_core::{color, Padding, Theme};
use parking_lot::Mutex;
use std::sync::Arc;
use std::time::Duration;
@@ -21,6 +22,7 @@ pub struct RepetitionSettingsState {
state: Arc<Mutex<AppState>>,
real_delete: bool,
correct_filter: bool,
filter_changed: bool,
}
impl RepetitionSettingsState {
@@ -38,6 +40,7 @@ impl RepetitionSettingsState {
state,
real_delete: false,
correct_filter: filter_state,
filter_changed: false,
}
}
}
@@ -58,6 +61,9 @@ impl NavigatedPage<RepetitionSettingsMessage> for RepetitionSettingsState {
Save => {
let mut state = self.state.lock();
update_deck(&mut self.set, &state.connection);
if self.filter_changed {
update_deck_stats(&self.set, &state);
}
state.decks[self.index] = self.set.clone();
}
SetName(new) => {
@@ -72,6 +78,7 @@ impl NavigatedPage<RepetitionSettingsMessage> for RepetitionSettingsState {
SetFilter(new) => {
self.set.filter = new;
self.correct_filter = self.set.check_filter();
self.filter_changed = true;
}
TryFilter => {
let state = self.state.lock();
@@ -163,6 +170,19 @@ impl NavigatedPage<RepetitionSettingsMessage> for RepetitionSettingsState {
}
}
fn update_deck_stats(deck: &DeckSettings, state: &AppState) {
let mut db_stats = load_stats_of_deck(deck, &state.connection);
let filtered_words = deck.get_word_list(state);
filtered_words.iter().for_each(|word| {
let word_id = state.dictionary[*word].id;
if let Some(index) = db_stats.iter().position(|stat| stat.word_id == word_id) {
db_stats.remove(index);
}
});
delete_stats(db_stats.as_slice(), &state.connection);
}
impl RepetitionSettingsState {
fn count_view(&self, set: &DeckSettings) -> Element<'_, RepetitionSettingsMessage> {
if let Some(count) = set.count {