From cb19925011d889c513e1bbedc446e399597e38a0 Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Wed, 17 Apr 2024 14:06:05 +0100 Subject: feat(gui): work on home page, sort state (#1956) 1. Start on a home page, can sort onboarding/etc from there 2. Introduce zustand for state management. It's nice! Did a production build and clicked around for a while. Memory usage seems nice and chill. --- atuin-client/src/api_client.rs | 14 +++++++++++++- atuin-client/src/history.rs | 2 +- atuin-client/src/record/sqlite_store.rs | 10 ++++++++++ atuin-client/src/record/store.rs | 1 + 4 files changed, 25 insertions(+), 2 deletions(-) (limited to 'atuin-client/src') diff --git a/atuin-client/src/api_client.rs b/atuin-client/src/api_client.rs index a19e5305..f31a796e 100644 --- a/atuin-client/src/api_client.rs +++ b/atuin-client/src/api_client.rs @@ -11,7 +11,7 @@ use reqwest::{ use atuin_common::{ api::{ AddHistoryRequest, ChangePasswordRequest, CountResponse, DeleteHistoryRequest, - ErrorResponse, LoginRequest, LoginResponse, RegisterResponse, StatusResponse, + ErrorResponse, LoginRequest, LoginResponse, MeResponse, RegisterResponse, StatusResponse, SyncHistoryResponse, }, record::RecordStatus, @@ -234,6 +234,18 @@ impl<'a> Client<'a> { Ok(status) } + pub async fn me(&self) -> Result { + let url = format!("{}/api/v0/me", self.sync_addr); + let url = Url::parse(url.as_str())?; + + let resp = self.client.get(url).send().await?; + let resp = handle_resp_error(resp).await?; + + let status = resp.json::().await?; + + Ok(status) + } + pub async fn get_history( &self, sync_ts: OffsetDateTime, diff --git a/atuin-client/src/history.rs b/atuin-client/src/history.rs index bc74aebd..1b590e88 100644 --- a/atuin-client/src/history.rs +++ b/atuin-client/src/history.rs @@ -18,7 +18,7 @@ mod builder; pub mod store; const HISTORY_VERSION: &str = "v0"; -const HISTORY_TAG: &str = "history"; +pub const HISTORY_TAG: &str = "history"; #[derive(Clone, Debug, Eq, PartialEq, Hash)] pub struct HistoryId(pub String); diff --git a/atuin-client/src/record/sqlite_store.rs b/atuin-client/src/record/sqlite_store.rs index e17893eb..31de311b 100644 --- a/atuin-client/src/record/sqlite_store.rs +++ b/atuin-client/src/record/sqlite_store.rs @@ -180,6 +180,16 @@ impl Store for SqliteStore { self.idx(host, tag, 0).await } + async fn len_all(&self) -> Result { + let res: Result<(i64,), sqlx::Error> = sqlx::query_as("select count(*) from store") + .fetch_one(&self.pool) + .await; + match res { + Err(e) => Err(eyre!("failed to fetch local store len: {}", e)), + Ok(v) => Ok(v.0 as u64), + } + } + async fn len_tag(&self, tag: &str) -> Result { let res: Result<(i64,), sqlx::Error> = sqlx::query_as("select count(*) from store where tag=?1") diff --git a/atuin-client/src/record/store.rs b/atuin-client/src/record/store.rs index 188e18ce..49ca4968 100644 --- a/atuin-client/src/record/store.rs +++ b/atuin-client/src/record/store.rs @@ -25,6 +25,7 @@ pub trait Store { async fn delete(&self, id: RecordId) -> Result<()>; async fn delete_all(&self) -> Result<()>; + async fn len_all(&self) -> Result; async fn len(&self, host: HostId, tag: &str) -> Result; async fn len_tag(&self, tag: &str) -> Result; -- cgit v1.3.1