From 754ddeaa8d3e3e4f3efc93d5bb22c68c31bb5c36 Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Mon, 6 May 2024 08:11:47 +0100 Subject: feat(ui): scroll history infinitely (#1999) * wip, history scrolls right! * wip * virtual scroll fucking worksssss * paging works :) * scroll search results now too --- ui/backend/src/main.rs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'ui/backend/src/main.rs') diff --git a/ui/backend/src/main.rs b/ui/backend/src/main.rs index fe6271b8..ce248d61 100644 --- a/ui/backend/src/main.rs +++ b/ui/backend/src/main.rs @@ -13,6 +13,7 @@ mod store; use atuin_client::{ encryption, history::HISTORY_TAG, record::sqlite_store::SqliteStore, record::store::Store, }; +use atuin_history::stats; use db::{GlobalStats, HistoryDB, UIHistory}; use dotfiles::aliases::aliases; @@ -25,25 +26,30 @@ struct HomeInfo { } #[tauri::command] -async fn list() -> Result, String> { +async fn list(offset: Option) -> Result, String> { let settings = Settings::new().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 history = db.list(Some(100), false).await?; + let history = db + .list(Some(offset.unwrap_or(0)), Some(100)) + .await? + .into_iter() + .map(|h| h.into()) + .collect(); Ok(history) } #[tauri::command] -async fn search(query: String) -> Result, String> { +async fn search(query: String, offset: Option) -> Result, String> { let settings = Settings::new().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 history = db.search(query.as_str()).await?; + let history = db.search(offset, query.as_str()).await?; Ok(history) } @@ -54,11 +60,21 @@ async fn global_stats() -> Result { let db_path = PathBuf::from(settings.db_path.as_str()); let db = HistoryDB::new(db_path, settings.local_timeout).await?; - let stats = db.global_stats().await?; + let mut stats = db.global_stats().await?; + + let history = db.list(None, None).await?; + let history_stats = stats::compute(&settings, &history, 10, 1); + + stats.stats = history_stats; Ok(stats) } +#[tauri::command] +async fn config() -> Result { + Settings::new().map_err(|e| e.to_string()) +} + #[tauri::command] async fn home_info() -> Result { let settings = Settings::new().map_err(|e| e.to_string())?; @@ -115,6 +131,7 @@ fn main() { global_stats, aliases, home_info, + config, dotfiles::aliases::import_aliases, dotfiles::aliases::delete_alias, dotfiles::aliases::set_alias, @@ -122,6 +139,7 @@ fn main() { dotfiles::vars::delete_var, dotfiles::vars::set_var, ]) + .plugin(tauri_plugin_sql::Builder::default().build()) .run(tauri::generate_context!()) .expect("error while running tauri application"); } -- cgit v1.3.1