Import page base
This commit is contained in:
+20
-16
@@ -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::lang::{WordData, WordGroup};
|
||||
use crate::navigation::Page::Word;
|
||||
use crate::navigation::Page::{Import, Word};
|
||||
use crate::navigation::{NavigatedPage, Page};
|
||||
use crate::styling::*;
|
||||
use crate::word::WordState;
|
||||
@@ -22,6 +22,8 @@ use std::ops::Add;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::{Duration, Instant};
|
||||
use iced_core::Length::Fill;
|
||||
use crate::import::ImportState;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct DictionaryState {
|
||||
@@ -59,6 +61,7 @@ pub enum DictionaryMessage {
|
||||
DeleteGroup,
|
||||
ChangeDirection,
|
||||
TrySave(usize),
|
||||
ToImport
|
||||
}
|
||||
|
||||
impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
||||
@@ -97,11 +100,13 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
||||
return Some(Word(WordState::new(word, *index, self.state.clone())));
|
||||
}
|
||||
}
|
||||
if let ToImport = message {
|
||||
return Some(Import(ImportState::new(self.state.clone())))
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn navigated(&mut self) {
|
||||
}
|
||||
fn navigated(&mut self) {}
|
||||
|
||||
fn update(&mut self, message: DictionaryMessage) -> Task<RootMessage> {
|
||||
match message {
|
||||
@@ -245,24 +250,28 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
||||
self.save_word(word_index);
|
||||
}
|
||||
}
|
||||
ToImport => {}
|
||||
}
|
||||
|
||||
Task::none()
|
||||
}
|
||||
|
||||
|
||||
fn view(&self) -> iced::Element<'_, DictionaryMessage> {
|
||||
back_overlay(
|
||||
row![
|
||||
iced::widget::column![
|
||||
self.groups_panel(),
|
||||
row![horizontal().width(8), self.words_list(),],
|
||||
button("Добавить слово").style(jl_button).on_press(NewWord),
|
||||
row![button("Добавить слово").style(jl_button).on_press(NewWord),
|
||||
horizontal().width(Fill),
|
||||
button("Импорт").style(jl_button).on_press(ToImport),
|
||||
]
|
||||
]
|
||||
.spacing(5),
|
||||
self.filters(),
|
||||
]
|
||||
.spacing(DEFAULT_SPACING)
|
||||
.into(),
|
||||
.spacing(DEFAULT_SPACING)
|
||||
.into(),
|
||||
Back,
|
||||
)
|
||||
}
|
||||
@@ -308,8 +317,6 @@ impl DictionaryState {
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
|
||||
fn words_list(&self) -> iced::Element<'_, DictionaryMessage> {
|
||||
let time = Instant::now();
|
||||
let mut col = Column::new().width(Length::Fill);
|
||||
@@ -340,13 +347,13 @@ impl DictionaryState {
|
||||
continue;
|
||||
}
|
||||
|
||||
let word_line_data = WordLineState{
|
||||
let word_line_data = WordLineState {
|
||||
is_included: self.include_map[i],
|
||||
key: word.key.clone(),
|
||||
value: word.value.clone(),
|
||||
tags: word.tags.clone(),
|
||||
id: word.id,
|
||||
index: i
|
||||
index: i,
|
||||
};
|
||||
|
||||
let lazy_line = lazy(word_line_data, move |data| {
|
||||
@@ -416,9 +423,6 @@ impl DictionaryState {
|
||||
line
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
col = col.push(lazy_line);
|
||||
}
|
||||
|
||||
@@ -592,11 +596,11 @@ pub fn app_data_dir() -> PathBuf {
|
||||
}
|
||||
|
||||
#[derive(Hash, PartialEq, Eq)]
|
||||
struct WordLineState{
|
||||
struct WordLineState {
|
||||
is_included: bool,
|
||||
key: String,
|
||||
value: String,
|
||||
tags: String,
|
||||
id: u32,
|
||||
index: usize,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user