From f8c963c7d668fc57680f25413f20bc207d4bf64a Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Tue, 23 Jul 2024 13:18:54 +0100 Subject: feat(gui): clean up home page, fix a few bugs (#2304) * wip home screen changes * more * adjust * fixes and things * patch runbook pty check --- ui/backend/src/db.rs | 2 +- ui/backend/src/main.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'ui/backend/src') diff --git a/ui/backend/src/db.rs b/ui/backend/src/db.rs index 56d422ab..b08d8ebe 100644 --- a/ui/backend/src/db.rs +++ b/ui/backend/src/db.rs @@ -36,7 +36,7 @@ pub struct GlobalStats { pub last_30d: u64, } -#[derive(Serialize)] +#[derive(Serialize, Debug)] pub struct UIHistory { pub id: String, /// When the command was run. diff --git a/ui/backend/src/main.rs b/ui/backend/src/main.rs index cff9558a..13e02c98 100644 --- a/ui/backend/src/main.rs +++ b/ui/backend/src/main.rs @@ -30,6 +30,8 @@ struct HomeInfo { pub history_count: u64, pub username: Option, pub last_sync: Option, + pub top_commands: Vec<(String, u64)>, + pub recent_commands: Vec, } #[tauri::command] @@ -138,6 +140,8 @@ async fn home_info() -> Result { let sqlite_store = SqliteStore::new(record_store_path, settings.local_timeout) .await .map_err(|e| e.to_string())?; + let db_path = PathBuf::from(settings.db_path.as_str()); + let db = HistoryDB::new(db_path, settings.local_timeout).await?; let last_sync = Settings::last_sync() .map_err(|e| e.to_string())? @@ -150,12 +154,20 @@ async fn home_info() -> Result { .await .map_err(|e| e.to_string())?; + + let history = db.list(None, None).await?; + let stats = stats::compute(&settings, &history, 10, 1).map_or(vec![], |stats|stats.top[0..5].to_vec()).iter().map(|(commands, count)| (commands.join(" "), *count as u64)).collect(); + let recent = if history.len() > 5 {history[0..5].to_vec()} else {vec![]}; + let recent = recent.into_iter().map(|h|h.into()).collect(); + let info = if !settings.logged_in() { HomeInfo { username: None, last_sync: None, record_count, history_count, + top_commands: stats, + recent_commands: recent, } } else { let client = atuin_client::api_client::Client::new( @@ -176,6 +188,8 @@ async fn home_info() -> Result { last_sync: Some(last_sync.to_string()), record_count, history_count, + top_commands: stats, + recent_commands: recent, } }; -- cgit v1.3.1