Splitting kana set

This commit is contained in:
micialware committed 2026-08-24 01:22:00 +03:00
1 parent 36e5693564
commit c74a0eb311
25 files changed
+389 -354

No files matched your search

+111
View File
@@ -0,0 +1,111 @@
use crate::data_provider::history::{get_history_of_set, HistoryItem};
use crate::lang::{WordData, INVALID_ID};
use crate::navigation::*;
use crate::styling::*;
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;
use crate::app::AppState;
#[derive(Clone)]
pub struct HistoryState {
list: Vec<HistoryItem>,
words: Vec<WordData>,
}
impl NavigatedPage<HistoryMessage> for HistoryState {
fn navigate(&mut self, message: &HistoryMessage) -> Option<Page> {
match message {
Back => Some(Page::PreviousPage),
}
}
fn navigated(&mut self) {}
fn update(&mut self, _: HistoryMessage) -> Task<RootMessage> {
Task::none()
}
fn view(&self) -> Element<'_, HistoryMessage> {
back_overlay(
iced::widget::row![
horizontal().width(FillPortion(1)),
scrollable(self.history_lines().padding(DEFAULT_SPACING))
.height(Fill)
.width(FillPortion(5)),
horizontal().width(FillPortion(1))
]
.height(Fill)
.width(Fill)
.into(),
Back,
)
}
}
impl HistoryState {
pub fn new(id: crate::lang::Id, state: Arc<Mutex<AppState>>) -> Self {
let state = state.lock();
let history = get_history_of_set(id).unwrap_or_default();
let words = history
.iter()
.map(
|item| match state.dictionary.iter().find(|w| w.id == item.word_id) {
None => WordData {
id,
key: "Удаленное слово".to_string(),
value: "Удаленное слово".to_string(),
tags: "Удаленное слово".to_string(),
additional: Default::default(),
group_id: INVALID_ID,
},
Some(word) => word.clone(),
},
)
.collect();
Self {
list: history,
words,
}
}
fn history_lines(&self) -> Column<'_, HistoryMessage> {
let mut column = Column::new();
for (index, item) in self.list.iter().enumerate() {
column = column.push(
row![
iced::widget::column![
text!("{}", self.words[index].key)
.width(Fill)
.align_x(Center),
text!("{}", self.words[index].value)
.width(Fill)
.align_x(Center),
]
.align_x(Center),
iced::widget::column![
text!("{} ➞ {}", item.before, item.after),
text!(
"{}",
item.timestamp.with_timezone(&Local).format("%d.%m %H:%M")
)
]
.spacing(5)
.align_x(Center)
]
.spacing(5),
);
column = column.push(rule::horizontal(1));
}
column.spacing(5)
}
}
#[derive(Clone)]
pub enum HistoryMessage {
Back,
}