This commit is contained in:
2026-05-05 12:06:17 +03:00
parent 9cb034066e
commit 99991a67a7
9 changed files with 17 additions and 42 deletions
-22
View File
@@ -39,28 +39,6 @@ pub fn add_stat(stat: &mut CardStatistics, connection: &Connection) {
stat.id = index;
}
pub fn update_stat(stat: &mut CardStatistics, connection: &Connection){
if stat.id == 0 {
add_stat(stat, &connection);
}
else {
connection
.execute(
"UPDATE card_stats SET word_id = ?1, set_id = ?2, score = ?3, last_opened = ?4 WHERE id = ?5",
(
&stat.word_id,
&stat.set_id,
&stat.score,
&stat.last_open,
&stat.id
),
)
.unwrap_or_else(|e| {println!("{}", e); 0});
}
}
pub fn update_stat_score(stat: &CardStatistics, connection: &Connection){
connection
.execute(
+1 -2
View File
@@ -1,9 +1,8 @@
use crate::dictionary::app_data_dir;
use rodio::Decoder;
use reqwest::Client;
use sha2::{Digest, Sha256};
use std::fs::File;
use std::io::BufReader;
use reqwest::Client;
pub async fn get_voice(text: &str) -> BufReader<File> {
let mut path = app_data_dir();
+2 -2
View File
@@ -124,13 +124,13 @@ pub fn load_words(connection: &Connection) -> Vec<WordData> {
.unwrap();
let word_iter = stmt
.query_map([], |row| {
let addinionals: String = row.get(4)?;
let additional: String = row.get(4)?;
Ok(WordData {
id: row.get(0)?,
key: row.get(1)?,
value: row.get(2)?,
tags: row.get(3)?,
additional: serde_json::from_str::<HashMap<String, String>>(&addinionals).unwrap(),
additional: serde_json::from_str::<HashMap<String, String>>(&additional).unwrap(),
group_id: row.get(5)?,
})
})
+1 -1
View File
@@ -397,7 +397,7 @@ impl CardSet {
}
fn history_len(&self) -> usize {
return min(MAX_HISTORY_LEN, (self.set.len() as f32 * MAX_HISTORY_LEN_PART) as usize);
min(MAX_HISTORY_LEN, (self.set.len() as f32 * MAX_HISTORY_LEN_PART) as usize)
}
pub fn len(&self) -> usize {
+3 -3
View File
@@ -151,10 +151,10 @@ impl ScreenState {
fn handle_keyboard(&mut self, message: Event) -> Task<RootMessage> {
let page = self.stack.last_mut().unwrap();
return match page {
match page {
Repetition(page) => page.press(&message),
_ => Task::none(),
};
}
}
}
@@ -206,7 +206,7 @@ trait NavigatedPage<T> {
}
pub trait KeyPressedPage {
fn press(&mut self, message: &keyboard::Event) -> Task<RootMessage>;
fn press(&mut self, message: &Event) -> Task<RootMessage>;
}
/*pub fn danger_button(x: &Theme, status: Status) -> Style{
+5 -5
View File
@@ -1,6 +1,6 @@
pub mod randomizer {
use crate::randomizer::randomizer::RandomizerMessage::{Back, Start};
use crate::randomizer::randomizer::RandomizerMessage::{Back, Start, Edit};
use crate::{NavigatedPage, Page, RootMessage};
use iced::widget::{button, container, text_editor};
use iced::Task;
@@ -21,7 +21,7 @@ pub mod randomizer {
impl NavigatedPage<RandomizerMessage> for RandomizerState {
fn navigate(&self, message: &RandomizerMessage) -> Option<Page> {
if let RandomizerMessage::Back = message {
if let Back = message {
return Some(Page::PreviousPage);
}
None
@@ -41,11 +41,11 @@ pub mod randomizer {
pub fn update(&mut self, message: RandomizerMessage) -> Task<RootMessage> {
match message {
RandomizerMessage::Edit(action) => {
Edit(action) => {
self.text.perform(action);
self.list = self.text.text().split("\n").map(|s| s.to_string()).collect();
},
RandomizerMessage::Start => {
Start => {
self.list.shuffle(&mut rand::rng());
self.text = text_editor::Content::with_text(self.list.join("\n").as_str());
}
@@ -58,7 +58,7 @@ pub mod randomizer {
container(
iced::widget::column![
button("Назад").on_press(Back),
text_editor(&self.text).on_action(RandomizerMessage::Edit
text_editor(&self.text).on_action(Edit
).width(400).height(400).placeholder("Каждый элемент с новой строки"),
button("Перемешать").on_press(Start),
]
+2 -4
View File
@@ -15,7 +15,6 @@ use tokio::task::spawn_blocking;
pub struct RepetitionState {
pub settings: CardSetSettings,
pub set: CardSet,
pub state: Arc<Mutex<AppState>>,
current_word: WordData,
current_statistic: CardStatistics,
open: bool,
@@ -43,7 +42,6 @@ impl RepetitionState {
RepetitionState {
settings: set,
set: card_set,
state,
current_word: word,
current_statistic: stat,
open: false,
@@ -86,7 +84,7 @@ impl RepetitionState {
self.answer(WordOpenMode::None)
} else {
self.open = true;
return Task::none();
Task::none()
}
}
@@ -223,7 +221,7 @@ impl RepetitionState {
}
impl KeyPressedPage for RepetitionState {
fn press(&mut self, message: &keyboard::Event) -> iced::Task<RootMessage> {
fn press(&mut self, message: &keyboard::Event) -> Task<RootMessage> {
if let keyboard::Event::KeyPressed {
key: _,
modified_key: _,
+1 -1
View File
@@ -287,6 +287,6 @@ impl CardSetSettings {
}
pub fn require_speech(&self) -> bool {
return self.forward == "speech" || self.backward == "speech"
self.forward == "speech" || self.backward == "speech"
}
}
+2 -2
View File
@@ -110,10 +110,10 @@ impl WordState {
}
fn get_view_for_more(&self, value: (&String, &String)) -> Element<'_, WordMessage> {
return match value.0.as_str() {
match value.0.as_str() {
"reading" => self.reading_field(value),
_ => space().into(),
};
}
}
fn reading_field(&self, value: (&String, &String)) -> Element<'_, WordMessage> {