temporal solving word

This commit is contained in:
micialware committed 2026-09-06 23:58:41 +03:00
1 parent 1afb7493f6
commit 7e1bb4bc22
1 file changed
+99 -98
+99 -98
View File
@@ -8,7 +8,7 @@ use crate::push_error;
use crate::push_error_task; use crate::push_error_task;
use crate::styling::*; use crate::styling::*;
use iced::widget::button::danger; use iced::widget::button::danger;
use iced::widget::{button, column, row, rule, scrollable, text, text_input}; use iced::widget::{button, column, row, rule, scrollable, space, text, text_input};
use iced::{Element, Fill, Task}; use iced::{Element, Fill, Task};
use parking_lot::Mutex; use parking_lot::Mutex;
use std::sync::Arc; use std::sync::Arc;
@@ -30,107 +30,108 @@ impl NavigatedPage<WordMessage> for WordState {
fn navigated(&mut self) {} fn navigated(&mut self) {}
fn update(&mut self, message: WordMessage) -> Task<RootMessage> { fn update(&mut self, message: WordMessage) -> Task<RootMessage> {
match message { // match message {
Back => {} // Back => {}
Save => { // Save => {
let mut state = self.state.lock(); // let mut state = self.state.lock();
state.dictionary[self.index] = self.word.clone(); // state.dictionary[self.index] = self.word.clone();
//
if let Err(err) = update_word(&mut self.word, &state.connection) { // if let Err(err) = update_word(&mut self.word, &state.connection) {
return push_error_task!(err); // return push_error_task!(err);
} // }
return Task::done(RootMessage::Word(Back)); // return Task::done(RootMessage::Word(Back));
} // }
Delete => { // Delete => {
let mut state = self.state.lock(); // let mut state = self.state.lock();
state.dictionary.remove(self.index); // state.dictionary.remove(self.index);
if let Err(err) = delete_word(&self.word, &state.connection) { // if let Err(err) = delete_word(&self.word, &state.connection) {
return push_error_task!(err); // return push_error_task!(err);
} // }
return Task::done(RootMessage::Word(Back)); // return Task::done(RootMessage::Word(Back));
} // }
SetTags(n) => self.word.tags = n, // SetTags(n) => self.word.tags = n,
SetKey(n) => { // SetKey(n) => {
self.word.key = n; // self.word.key = n;
} // }
SetValue(n) => { // SetValue(n) => {
self.word.value = n; // self.word.value = n;
} // }
SetAdditional(key, value) => { // SetAdditional(key, value) => {
self.word.additional.insert(key, value.clone()); // self.word.additional.insert(key, value.clone());
} // }
AddAdditional(key) => { // AddAdditional(key) => {
self.word.additional.insert(key, "".to_string()); // self.word.additional.insert(key, "".to_string());
} // }
RemoveAdditional(key) => { // RemoveAdditional(key) => {
self.word.additional.remove(key.as_str()); // self.word.additional.remove(key.as_str());
} // }
} // }
Task::none() Task::none()
} }
fn view(&self) -> Element<'_, WordMessage> { fn view(&self) -> Element<'_, WordMessage> {
let mut fast_add = row![]; // let mut fast_add = row![];
if !self.word.additional.contains_key("reading") { // if !self.word.additional.contains_key("reading") {
fast_add = fast_add.push( // fast_add = fast_add.push(
button("Чтение") // button("Чтение")
.style(button::text) // .style(button::text)
.on_press(AddAdditional("reading".to_string())), // .on_press(AddAdditional("reading".to_string())),
); // );
} // }
if !self.word.additional.contains_key("description") { // if !self.word.additional.contains_key("description") {
fast_add = fast_add.push( // fast_add = fast_add.push(
button("Описание") // button("Описание")
.style(button::text) // .style(button::text)
.on_press(AddAdditional("description".to_string())), // .on_press(AddAdditional("description".to_string())),
); // );
} // }
//
if !self.word.additional.contains_key("context") { // if !self.word.additional.contains_key("context") {
fast_add = fast_add.push( // fast_add = fast_add.push(
button("В контексте") // button("В контексте")
.style(button::text) // .style(button::text)
.on_press(AddAdditional("context".to_string())), // .on_press(AddAdditional("context".to_string())),
); // );
} // }
//
let mut col = iced::widget::column![ // let mut col = iced::widget::column![
column![ // column![
text!("Ключ"), // text!("Ключ"),
text_input("key", &self.word.key).on_input(SetKey), // text_input("key", &self.word.key).on_input(SetKey),
] // ]
.spacing(QUARTER_SPACING), // .spacing(QUARTER_SPACING),
column![ // column![
text!("Значение"), // text!("Значение"),
text_input("value", &self.word.value).on_input(SetValue), // text_input("value", &self.word.value).on_input(SetValue),
] // ]
.spacing(QUARTER_SPACING), // .spacing(QUARTER_SPACING),
column![ // column![
text!("Теги"), // text!("Теги"),
text_input("tags", &self.word.tags).on_input(SetTags), // text_input("tags", &self.word.tags).on_input(SetTags),
] // ]
.spacing(QUARTER_SPACING), // .spacing(QUARTER_SPACING),
rule::horizontal(2), // rule::horizontal(2),
scrollable(fast_add), // scrollable(fast_add),
]; // ];
//
for more in &self.word.additional { // for more in &self.word.additional {
col = col.push(self.get_view_for_more(more)); // col = col.push(self.get_view_for_more(more));
} // }
//
back_overlay( // back_overlay(
column![ // column![
col.spacing(DEFAULT_SPACING / 2.0).width(Fill).height(Fill), // col.spacing(DEFAULT_SPACING / 2.0).width(Fill).height(Fill),
row![ // row![
button("Сохранить").style(jl_button).on_press(Save), // button("Сохранить").style(jl_button).on_press(Save),
button("Удалить").style(danger).on_press(Delete), // button("Удалить").style(danger).on_press(Delete),
] // ]
.spacing(DEFAULT_SPACING) // .spacing(DEFAULT_SPACING)
] // ]
.spacing(DEFAULT_SPACING) // .spacing(DEFAULT_SPACING)
.into(), // .into(),
Back, // Back,
) // )
space().into()
} }
} }