Repo integration #15

Merged
micialware merged 35 commits from repo-integration into master 2026-09-09 12:47:42 +03:00
Showing only changes of commit 7e1bb4bc22 - Show all commits
+99 -98
View File
@@ -8,7 +8,7 @@ use crate::push_error;
use crate::push_error_task;
use crate::styling::*;
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 parking_lot::Mutex;
use std::sync::Arc;
@@ -30,107 +30,108 @@ impl NavigatedPage<WordMessage> for WordState {
fn navigated(&mut self) {}
fn update(&mut self, message: WordMessage) -> Task<RootMessage> {
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());
}
}
// 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());
// }
// }
Task::none()
}
fn view(&self) -> Element<'_, WordMessage> {
let mut fast_add = row![];
if !self.word.additional.contains_key("reading") {
fast_add = fast_add.push(
button("Чтение")
.style(button::text)
.on_press(AddAdditional("reading".to_string())),
);
}
if !self.word.additional.contains_key("description") {
fast_add = fast_add.push(
button("Описание")
.style(button::text)
.on_press(AddAdditional("description".to_string())),
);
}
if !self.word.additional.contains_key("context") {
fast_add = fast_add.push(
button("В контексте")
.style(button::text)
.on_press(AddAdditional("context".to_string())),
);
}
let mut col = iced::widget::column![
column![
text!("Ключ"),
text_input("key", &self.word.key).on_input(SetKey),
]
.spacing(QUARTER_SPACING),
column![
text!("Значение"),
text_input("value", &self.word.value).on_input(SetValue),
]
.spacing(QUARTER_SPACING),
column![
text!("Теги"),
text_input("tags", &self.word.tags).on_input(SetTags),
]
.spacing(QUARTER_SPACING),
rule::horizontal(2),
scrollable(fast_add),
];
for more in &self.word.additional {
col = col.push(self.get_view_for_more(more));
}
back_overlay(
column![
col.spacing(DEFAULT_SPACING / 2.0).width(Fill).height(Fill),
row![
button("Сохранить").style(jl_button).on_press(Save),
button("Удалить").style(danger).on_press(Delete),
]
.spacing(DEFAULT_SPACING)
]
.spacing(DEFAULT_SPACING)
.into(),
Back,
)
// let mut fast_add = row![];
// if !self.word.additional.contains_key("reading") {
// fast_add = fast_add.push(
// button("Чтение")
// .style(button::text)
// .on_press(AddAdditional("reading".to_string())),
// );
// }
// if !self.word.additional.contains_key("description") {
// fast_add = fast_add.push(
// button("Описание")
// .style(button::text)
// .on_press(AddAdditional("description".to_string())),
// );
// }
//
// if !self.word.additional.contains_key("context") {
// fast_add = fast_add.push(
// button("В контексте")
// .style(button::text)
// .on_press(AddAdditional("context".to_string())),
// );
// }
//
// let mut col = iced::widget::column![
// column![
// text!("Ключ"),
// text_input("key", &self.word.key).on_input(SetKey),
// ]
// .spacing(QUARTER_SPACING),
// column![
// text!("Значение"),
// text_input("value", &self.word.value).on_input(SetValue),
// ]
// .spacing(QUARTER_SPACING),
// column![
// text!("Теги"),
// text_input("tags", &self.word.tags).on_input(SetTags),
// ]
// .spacing(QUARTER_SPACING),
// rule::horizontal(2),
// scrollable(fast_add),
// ];
//
// for more in &self.word.additional {
// col = col.push(self.get_view_for_more(more));
// }
//
// back_overlay(
// column![
// col.spacing(DEFAULT_SPACING / 2.0).width(Fill).height(Fill),
// row![
// button("Сохранить").style(jl_button).on_press(Save),
// button("Удалить").style(danger).on_press(Delete),
// ]
// .spacing(DEFAULT_SPACING)
// ]
// .spacing(DEFAULT_SPACING)
// .into(),
// Back,
// )
space().into()
}
}