From 3e5e8154237defbe6234dfb172c548cca06e4f4e Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Fri, 3 May 2024 14:03:07 +0100 Subject: scroll search results now too --- crates/atuin-common/src/shell.rs | 2 +- ui/backend/src/db.rs | 20 +++++++++++--------- ui/backend/src/main.rs | 10 +++++----- ui/src/components/HistorySearch.tsx | 12 ++++++------ ui/src/pages/History.tsx | 13 ++++++++++--- ui/src/state/store.ts | 12 +++++------- 6 files changed, 38 insertions(+), 31 deletions(-) diff --git a/crates/atuin-common/src/shell.rs b/crates/atuin-common/src/shell.rs index 9726ce4d..afdccea7 100644 --- a/crates/atuin-common/src/shell.rs +++ b/crates/atuin-common/src/shell.rs @@ -116,7 +116,7 @@ impl Shell { let shell = self.to_string(); let output = Command::new(shell) - .arg("-c") + .arg("-ic") .args(args) .output() .map_err(|e| ShellError::ExecError(e.to_string()))?; diff --git a/ui/backend/src/db.rs b/ui/backend/src/db.rs index 2b9dd095..7e29302a 100644 --- a/ui/backend/src/db.rs +++ b/ui/backend/src/db.rs @@ -98,16 +98,17 @@ impl HistoryDB { Ok(Self(sqlite)) } - pub async fn list(&self, end: u64, limit: Option) -> Result, String> { + pub async fn list( + &self, + offset: Option, + limit: Option, + ) -> Result, String> { let query = if let Some(limit) = limit { - sqlx::query( - "select * from history where timestamp < ?1 order by timestamp desc limit ?2", - ) - .bind(end as i64) - .bind(limit as i64) + sqlx::query("select * from history order by timestamp desc limit ?1 offset ?2") + .bind(limit as i64) + .bind(offset.unwrap_or(0) as i64) } else { - sqlx::query("select * from history where timestamp < ?1 order by timestamp desc") - .bind(end as i64) + sqlx::query("select * from history order by timestamp desc") }; let history: Vec = query @@ -137,7 +138,7 @@ impl HistoryDB { Ok(history) } - pub async fn search(&self, query: &str) -> Result, String> { + pub async fn search(&self, offset: Option, query: &str) -> Result, String> { let context = Context { session: "".to_string(), cwd: "".to_string(), @@ -148,6 +149,7 @@ impl HistoryDB { let filters = OptFilters { limit: Some(200), + offset: offset.map(|offset| offset as i64), ..OptFilters::default() }; diff --git a/ui/backend/src/main.rs b/ui/backend/src/main.rs index 6a92df1c..ce248d61 100644 --- a/ui/backend/src/main.rs +++ b/ui/backend/src/main.rs @@ -26,14 +26,14 @@ struct HomeInfo { } #[tauri::command] -async fn list(minTimestamp: Option) -> 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(minTimestamp.unwrap_or(time::OffsetDateTime::now_utc().unix_timestamp_nanos() as u64), Some(100)) + .list(Some(offset.unwrap_or(0)), Some(100)) .await? .into_iter() .map(|h| h.into()) @@ -43,13 +43,13 @@ async fn list(minTimestamp: Option) -> Result, String> { } #[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) } @@ -62,7 +62,7 @@ async fn global_stats() -> Result { let mut stats = db.global_stats().await?; - let history = db.list(0, None).await?; + let history = db.list(None, None).await?; let history_stats = stats::compute(&settings, &history, 10, 1); stats.stats = history_stats; diff --git a/ui/src/components/HistorySearch.tsx b/ui/src/components/HistorySearch.tsx index 08bed2a8..b3c8492a 100644 --- a/ui/src/components/HistorySearch.tsx +++ b/ui/src/components/HistorySearch.tsx @@ -3,12 +3,12 @@ import { ArrowPathIcon } from "@heroicons/react/24/outline"; import { MagnifyingGlassIcon } from "@heroicons/react/20/solid"; interface HistorySearchProps { - refresh: (query: string) => void; + query: string; + refresh: () => void; + setQuery: (query: string) => void; } export default function HistorySearch(props: HistorySearchProps) { - let [searchQuery, setSearchQuery] = useState(""); - return (
{ - setSearchQuery(query.target.value); - props.refresh(query.target.value); + props.setQuery(query.target.value); + props.refresh(); }} />
@@ -45,7 +45,7 @@ export default function HistorySearch(props: HistorySearchProps) { type="button" className="-m-2.5 p-2.5 text-gray-400 hover:text-gray-500" onClick={() => { - props.refresh(searchQuery); + props.refresh(); }} >