Filter check on edit page

This commit is contained in:
2026-08-18 17:45:50 +03:00
parent d3c28179b6
commit 4187344a29
8 changed files with 27 additions and 12 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
use crate::lang::{DeckSettings, INVALID_ID, OrderMode};
use crate::lang::{DeckSettings, OrderMode};
use rusqlite::Connection;
+1 -1
View File
@@ -1,4 +1,4 @@
use crate::lang::{CardStatistics, DeckSettings, INVALID_ID};
use crate::lang::{CardStatistics, DeckSettings};
use rusqlite::Connection;
use std::time::Instant;
+2 -2
View File
@@ -1,5 +1,5 @@
use crate::lang::{INVALID_ID, WordData, WordGroup};
use rusqlite::{Connection, params};
use crate::lang::{WordData, WordGroup};
use rusqlite::{params, Connection};
use std::collections::HashMap;
pub fn add_word(word: &mut WordData, connection: &Connection) {
+1 -1
View File
@@ -2,7 +2,7 @@ use crate::data_provider::words::{delete_group, delete_word, update_group, updat
use crate::dictionary::DictionaryMessage::*;
use crate::dictionary_test::DictionaryQuizState;
use crate::import::ImportState;
use crate::lang::{INVALID_ID, WordData, WordGroup};
use crate::lang::{WordData, WordGroup};
use crate::navigation::Page::{Import, Word};
use crate::navigation::{NavigatedPage, Page};
use crate::styling::*;
+4 -2
View File
@@ -26,7 +26,7 @@ const MAX_HISTORY_LEN_PART: f32 = 0.33;
const MAX_SCORE: u8 = 25;
const FADE_PER_DAY: f32 = 0.95;
#[derive(Clone, PartialEq, Eq, Debug, Hash, Copy)]
pub(crate) struct Id(u32);
pub struct Id(u32);
pub const INVALID_ID: Id = Id(0);
impl FromStr for Id {
type Err = ParseIntError;
@@ -650,9 +650,11 @@ impl DeckSettings {
open_mode: OrderMode::Default,
}
}
pub(crate) fn check_filter(&self) -> bool {
pub fn check_filter(&self) -> bool {
let time = Instant::now();
let engine = Engine::new();
let ast = engine.compile(&self.filter);
println!("Compile time is {:?}", time.elapsed());
ast.is_ok()
}
pub fn get_word_list(&self, state: &AppState) -> Vec<usize> {
+2 -2
View File
@@ -32,10 +32,10 @@ use iced::{Font, window};
use iced::{Subscription, Theme, keyboard};
use iced_core::Size;
use iced_core::window::Position;
use iced_core::window::settings::PlatformSpecific;
use mimalloc::MiMalloc;
use rusqlite::Connection;
#[cfg(target_os = "linux")]
use iced_core::window::settings::PlatformSpecific;
#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;
+14 -2
View File
@@ -9,15 +9,17 @@ use iced::widget::button::danger;
use iced::widget::{button, column, row, scrollable, space, text, text_input};
use iced::{Element, Task};
use iced_core::Length::Fill;
use iced_core::Padding;
use iced_core::{color, Padding, Theme};
use std::sync::{Arc, Mutex};
use std::time::Duration;
use iced::widget::text_input::Catalog;
pub struct RepetitionSettingsState {
set: DeckSettings,
index: usize,
state: Arc<Mutex<AppState>>,
real_delete: bool,
correct_filter: bool,
}
impl RepetitionSettingsState {
@@ -27,11 +29,14 @@ impl RepetitionSettingsState {
let local_state = p1.lock().unwrap();
set = local_state.decks[index].clone();
}
let filter_state = set.check_filter();
RepetitionSettingsState {
index,
set,
state: p1,
real_delete: false,
correct_filter: filter_state,
}
}
}
@@ -65,6 +70,7 @@ impl NavigatedPage<RepetitionSettingsMessage> for RepetitionSettingsState {
}
SetFilter(new) => {
self.set.filter = new;
self.correct_filter = self.set.check_filter();
}
TryFilter => {
let state = self.state.lock().unwrap();
@@ -111,7 +117,13 @@ impl NavigatedPage<RepetitionSettingsMessage> for RepetitionSettingsState {
.spacing(QUARTER_SPACING),
column![
text!("Фильтр"),
text_input("", &self.set.filter).on_input(SetFilter),
text_input("", &self.set.filter).style(|x, status| {
let mut primary = Theme::default()(x, status);
if !self.correct_filter {
primary.border.color = color!(255, 255, 0);
}
primary
}).on_input(SetFilter),
button("Проверить фильтр")
.style(jl_button)
.on_press(TryFilter),