Rewrite history page
This commit is contained in:
1 parent
f19a6f64c3
commit
532640058e
11 files changed
+201
-230
No files matched your search
+33
-31
@@ -1,22 +1,20 @@
|
||||
use crate::app::AppState;
|
||||
use crate::data::INVALID_ID;
|
||||
use crate::data::entities::{HistoryItem, WordData};
|
||||
use crate::data_provider::history::get_history_of_set;
|
||||
use crate::data::entities::{HistoryNote, WordData};
|
||||
use crate::data::repositories::Repository;
|
||||
use crate::navigation::*;
|
||||
use crate::styling::*;
|
||||
use HistoryMessage::Back;
|
||||
use chrono::Local;
|
||||
use iced::alignment::Horizontal::Center;
|
||||
use iced::widget::space::horizontal;
|
||||
use iced::widget::*;
|
||||
use iced::{Element, Fill, FillPortion, Task};
|
||||
use parking_lot::Mutex;
|
||||
use std::sync::Arc;
|
||||
use HistoryMessage::Back;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct HistoryState {
|
||||
list: Vec<HistoryItem>,
|
||||
words: Vec<WordData>,
|
||||
list: Vec<(WordData, HistoryNote)>,
|
||||
pub state: AppState,
|
||||
}
|
||||
|
||||
impl NavigatedPage<HistoryMessage> for HistoryState {
|
||||
@@ -39,9 +37,9 @@ impl NavigatedPage<HistoryMessage> for HistoryState {
|
||||
.width(FillPortion(5)),
|
||||
horizontal().width(FillPortion(1))
|
||||
]
|
||||
.height(Fill)
|
||||
.width(Fill)
|
||||
.into(),
|
||||
.height(Fill)
|
||||
.width(Fill)
|
||||
.into(),
|
||||
Back,
|
||||
)
|
||||
}
|
||||
@@ -49,56 +47,60 @@ impl NavigatedPage<HistoryMessage> for HistoryState {
|
||||
|
||||
impl HistoryState {
|
||||
pub fn new(id: crate::data::Id, state: AppState) -> Self {
|
||||
let state = state.lock();
|
||||
let history = get_history_of_set(id).unwrap_or_default();
|
||||
let dict = &state.dictionary.read();
|
||||
let history_repo = &mut state.history.write();
|
||||
history_repo.init().expect("TODO: panic message");
|
||||
let id = id.clone();
|
||||
let mut history = history_repo.query(Arc::new(move |h| h.set_id == id));
|
||||
let words = history
|
||||
.iter()
|
||||
.iter(history_repo)
|
||||
.map(
|
||||
|item| match state.dictionary.iter().find(|w| w.id == item.word_id) {
|
||||
None => WordData {
|
||||
id,
|
||||
|item| {let handle = dict.handle_by_id(item.word_id);
|
||||
let word = dict.get_static(handle).unwrap_or(WordData {
|
||||
id: Default::default(),
|
||||
group_id: Default::default(),
|
||||
key: "Удаленное слово".to_string(),
|
||||
value: "Удаленное слово".to_string(),
|
||||
tags: "Удаленное слово".to_string(),
|
||||
value: "".to_string(),
|
||||
tags: "".to_string(),
|
||||
additional: Default::default(),
|
||||
group_id: INVALID_ID,
|
||||
},
|
||||
Some(word) => word.clone(),
|
||||
},
|
||||
});
|
||||
(word, item.clone())
|
||||
}
|
||||
)
|
||||
.collect();
|
||||
|
||||
Self {
|
||||
list: history,
|
||||
words,
|
||||
list: words,
|
||||
state: state.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
fn history_lines(&self) -> Column<'_, HistoryMessage> {
|
||||
let mut column = Column::new();
|
||||
for (index, item) in self.list.iter().enumerate() {
|
||||
for (index, item) in &self.list {
|
||||
|
||||
let activity = item;
|
||||
column = column.push(
|
||||
row![
|
||||
iced::widget::column![
|
||||
text!("{}", self.words[index].key)
|
||||
text!("{}", index.key)
|
||||
.width(Fill)
|
||||
.align_x(Center),
|
||||
text!("{}", self.words[index].value)
|
||||
text!("{}", index.value)
|
||||
.width(Fill)
|
||||
.align_x(Center),
|
||||
]
|
||||
.align_x(Center),
|
||||
iced::widget::column![
|
||||
text!("{} ➞ {}", item.before, item.after),
|
||||
text!("{} ➞ {}", activity.before, activity.after),
|
||||
text!(
|
||||
"{}",
|
||||
item.timestamp.with_timezone(&Local).format("%d.%m %H:%M")
|
||||
activity.timestamp.with_timezone(&Local).format("%d.%m %H:%M")
|
||||
)
|
||||
]
|
||||
.spacing(5)
|
||||
.align_x(Center)
|
||||
]
|
||||
.spacing(5),
|
||||
.spacing(5),
|
||||
);
|
||||
column = column.push(rule::horizontal(1));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user