Fixing some bugs
This commit is contained in:
1 parent
d59776d713
commit
5d305affd3
2 files changed
+78
-55
No files matched your search
+46
-50
@@ -1,58 +1,46 @@
|
||||
use crate::app::AppState;
|
||||
use crate::data::entities::{EntityHandle, WordData};
|
||||
use crate::navigation::Page::PreviousPage;
|
||||
use crate::navigation::{NavigatedPage, Page, RootMessage};
|
||||
use crate::data::repositories::Repository;
|
||||
use crate::pages::word::WordMessage::*;
|
||||
use crate::styling::*;
|
||||
use iced::widget::button::danger;
|
||||
use iced::widget::{button, column, row, rule, scrollable, space, text, text_input};
|
||||
use iced::{Element, Fill, Task};
|
||||
use crate::data::repositories::Repository;
|
||||
use crate::jl_button;
|
||||
use iced::widget::space::horizontal;
|
||||
use iced::widget::{button, column, row, rule, scrollable, text, text_input};
|
||||
use iced::{Element, Fill};
|
||||
|
||||
pub struct WordEditor {
|
||||
pub struct WordEditor<Message> {
|
||||
state: AppState,
|
||||
handle: EntityHandle<WordData>,
|
||||
on_delete: Option<Message>,
|
||||
on_edit: Option<Message>,
|
||||
}
|
||||
|
||||
impl WordEditor {
|
||||
pub(crate) fn update(&mut self, message: WordMessage) {
|
||||
// match message {
|
||||
// Back => {}
|
||||
// Save => {
|
||||
// let mut state = self.state.lock();
|
||||
// state.dictionary[self.index] = self.word.clone();
|
||||
//
|
||||
// if let Err(err) = update_word(&mut self.word, &state.connection) {
|
||||
// return push_error_task!(err);
|
||||
// }
|
||||
// return Task::done(RootMessage::Word(Back));
|
||||
// }
|
||||
// Delete => {
|
||||
// let mut state = self.state.lock();
|
||||
// state.dictionary.remove(self.index);
|
||||
// if let Err(err) = delete_word(&self.word, &state.connection) {
|
||||
// return push_error_task!(err);
|
||||
// }
|
||||
// return Task::done(RootMessage::Word(Back));
|
||||
// }
|
||||
// SetTags(n) => self.word.tags = n,
|
||||
// SetKey(n) => {
|
||||
// self.word.key = n;
|
||||
// }
|
||||
// SetValue(n) => {
|
||||
// self.word.value = n;
|
||||
// }
|
||||
// SetAdditional(key, value) => {
|
||||
// self.word.additional.insert(key, value.clone());
|
||||
// }
|
||||
// AddAdditional(key) => {
|
||||
// self.word.additional.insert(key, "".to_string());
|
||||
// }
|
||||
// RemoveAdditional(key) => {
|
||||
// self.word.additional.remove(key.as_str());
|
||||
// }
|
||||
// }
|
||||
impl<Message> WordEditor<Message> {
|
||||
pub(crate) fn update(&mut self, message: WordMessage) -> Option<Message> {
|
||||
let dictionary = &mut self.state.dictionary.write();
|
||||
let word = dictionary.get_mut(&mut self.handle).unwrap();
|
||||
match message {
|
||||
Delete => {
|
||||
return self.on_delete.take();
|
||||
}
|
||||
SetTags(n) => word.tags = n,
|
||||
SetKey(n) => {
|
||||
word.key = n;
|
||||
}
|
||||
SetValue(n) => {
|
||||
word.value = n;
|
||||
}
|
||||
SetAdditional(key, value) => {
|
||||
word.additional.insert(key, value.clone());
|
||||
}
|
||||
AddAdditional(key) => {
|
||||
word.additional.insert(key, "".to_string());
|
||||
}
|
||||
RemoveAdditional(key) => {
|
||||
word.additional.remove(key.as_str());
|
||||
}
|
||||
}
|
||||
self.on_edit.take()
|
||||
}
|
||||
|
||||
pub(crate) fn view(&self) -> Element<'_, WordMessage> {
|
||||
@@ -108,7 +96,7 @@ impl WordEditor {
|
||||
column![
|
||||
col.spacing(DEFAULT_SPACING / 2.0).width(Fill).height(Fill),
|
||||
row![
|
||||
jl_button!("Сохранить").on_press(Save),
|
||||
horizontal().width(Fill),
|
||||
button("Удалить").style(danger).on_press(Delete),
|
||||
]
|
||||
.spacing(DEFAULT_SPACING)
|
||||
@@ -120,13 +108,22 @@ impl WordEditor {
|
||||
}
|
||||
}
|
||||
|
||||
impl WordEditor {
|
||||
impl<Message> WordEditor<Message> {
|
||||
pub fn new(handle: EntityHandle<WordData>, state: AppState) -> Self {
|
||||
Self { state, handle }
|
||||
Self { state, handle, on_delete: None, on_edit: None }
|
||||
}
|
||||
|
||||
pub fn on_delete(mut self, message: Message) -> Self {
|
||||
self.on_delete = Some(message);
|
||||
self
|
||||
}
|
||||
pub fn on_edit(mut self, message: Message) -> Self {
|
||||
self.on_edit = Some(message);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl WordEditor {
|
||||
impl<Message> WordEditor<Message> {
|
||||
fn get_view_for_more(&self, value: (&String, &String)) -> Element<'_, WordMessage> {
|
||||
match value.0.as_str() {
|
||||
"reading" => self.reading_field(value.1),
|
||||
@@ -170,7 +167,6 @@ impl WordEditor {
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum WordMessage {
|
||||
Save,
|
||||
Delete,
|
||||
SetTags(String),
|
||||
SetKey(String),
|
||||
|
||||
Reference in new issue
Block a user