Rewrite fully second db table into result

This commit is contained in:
micialware committed 2026-08-24 18:16:41 +03:00
1 parent 06bf9138c0
commit 8841a51897
11 files changed
+127 -74

No files matched your search

+13 -9
View File
@@ -4,15 +4,16 @@ use crate::data_provider::card_sets::{delete_set, update_deck};
use crate::data_provider::card_stats::{delete_stats, load_stats_of_deck};
use crate::navigation::Page::PreviousPage;
use crate::navigation::{NavigatedPage, Page, RootMessage};
use crate::notification::NotificationRequest;
use crate::notification::NotificationData;
use crate::pages::repetition_settings::RepetitionSettingsMessage::*;
use crate::styling::*;
use crate::{push_error, push_error_task};
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::{color, Padding, Theme};
use iced_core::{Padding, Theme, color};
use parking_lot::Mutex;
use std::sync::Arc;
use std::time::Duration;
@@ -62,10 +63,12 @@ impl NavigatedPage<RepetitionSettingsMessage> for RepetitionSettingsState {
Save => {
let mut state = self.state.lock();
if let Err(e) = update_deck(&mut self.set, &state.connection) {
return Task::done(RootMessage::PushNotification(NotificationRequest::Error(e)));
return push_error_task!(e)
}
if self.filter_changed {
update_deck_stats(&self.set, &state);
if self.filter_changed
&& let Err(e) = update_deck_stats(&self.set, &state)
{
return push_error_task!(e)
}
state.decks[self.index] = self.set.clone();
}
@@ -98,7 +101,7 @@ impl NavigatedPage<RepetitionSettingsMessage> for RepetitionSettingsState {
}
let mut state = self.state.lock();
if let Err(e) = delete_set(&self.set, &state.connection) {
return Task::done(RootMessage::PushNotification(NotificationRequest::Error(e)));
return push_error_task!(e);
}
state.decks.remove(self.index);
@@ -176,8 +179,8 @@ impl NavigatedPage<RepetitionSettingsMessage> for RepetitionSettingsState {
}
}
fn update_deck_stats(deck: &DeckSettings, state: &AppState) {
let mut db_stats = load_stats_of_deck(deck, &state.connection);
fn update_deck_stats(deck: &DeckSettings, state: &AppState) -> Result<(), NotificationData> {
let mut db_stats = load_stats_of_deck(deck, &state.connection).expect("Wrong db operation");
let filtered_words = deck.get_word_list(state);
filtered_words.iter().for_each(|word| {
let word_id = state.dictionary[*word].id;
@@ -186,7 +189,8 @@ fn update_deck_stats(deck: &DeckSettings, state: &AppState) {
}
});
delete_stats(db_stats.as_slice(), &state.connection);
delete_stats(db_stats.as_slice(), &state.connection)?;
Ok(())
}
impl RepetitionSettingsState {