master
Tymon 1 year ago
parent cb812ca5e4
commit 2cf0bebdb7

@ -1,4 +1,7 @@
use std::{sync::mpsc::{self, Receiver, Sender}, time::Duration};
use std::{
sync::mpsc::{self, Receiver, Sender},
time::Duration,
};
use chrono::Local;
use eframe::{
@ -131,35 +134,31 @@ impl eframe::App for App {
ScrollArea::vertical()
.id_source("history_scroll")
.show(ui, |ui| {
Grid::new("history_grid").num_columns(1).show(
ui,
|ui| {
for entry in &self.history {
let response = ui
.horizontal(|ui| {
ui.label(&entry.selected_ai);
ui.label(
entry
.date
.format("%Y-%m-%d %H:%M:%S")
.to_string(),
)
})
.response;
let clickable =
ui.allocate_rect(response.rect, Sense::click());
if clickable.clicked() {
self.open_history_entry = Some(entry.clone());
}
ui.end_row()
Grid::new("history_grid").num_columns(1).show(ui, |ui| {
for entry in &self.history {
let response = ui
.horizontal(|ui| {
ui.label(&entry.selected_ai);
ui.label(
entry
.date
.format("%Y-%m-%d %H:%M:%S")
.to_string(),
)
})
.response;
let clickable =
ui.allocate_rect(response.rect, Sense::click());
if clickable.clicked() {
self.open_history_entry = Some(entry.clone());
}
},
);
});
ui.end_row()
}
});
});
}
});
@ -199,8 +198,12 @@ impl eframe::App for App {
ui.with_layout(Layout::right_to_left(Align::Max), |ui| {
ui.add_visible_ui(CONFIG.app.history_dir.is_some(), |ui| {
if ui.button("History").clicked() {
// add proper error handling
self.history = read_all_history().unwrap();
match read_all_history() {
Ok(history) => self.history = history,
Err(error) => {
self.toasts.error(error.to_string());
}
}
self.history_open = true;
}

@ -1,4 +1,4 @@
use anyhow::Result;
use anyhow::{Result, Context};
use chrono::{DateTime, Local};
use serde::{Deserialize, Serialize};
use std::fs;
@ -38,7 +38,7 @@ pub fn read_all_history() -> Result<Vec<HistoryEntry>> {
let history_dir = CONFIG.app.history_dir.as_ref().unwrap();
let mut entries = vec![];
for dir_entry in fs::read_dir(history_dir)? {
for dir_entry in fs::read_dir(history_dir).context("Failed to read history_dir!")? {
let dir_entry = dir_entry?;
if dir_entry.file_type()?.is_file() {