diff options
| author | Ellie Huxtable <ellie@elliehuxtable.com> | 2024-05-28 14:54:05 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-28 14:54:05 +0100 |
| commit | fc4dfe4fffce05c91f6766024891bdb39b2a3299 (patch) | |
| tree | a9a0923645a4e6f6047f25db0d2f4f25a984b4b0 /ui/src/state | |
| parent | chore(deps): bump uuid from 1.7.0 to 1.8.0 (#2047) (diff) | |
| download | atuin-fc4dfe4fffce05c91f6766024891bdb39b2a3299.zip | |
feat(ui): use correct username on welcome screen (#2050)
* wip
* fetch and use username
Diffstat (limited to 'ui/src/state')
| -rw-r--r-- | ui/src/state/client.ts | 13 | ||||
| -rw-r--r-- | ui/src/state/models.ts | 40 | ||||
| -rw-r--r-- | ui/src/state/store.ts | 20 |
3 files changed, 73 insertions, 0 deletions
diff --git a/ui/src/state/client.ts b/ui/src/state/client.ts new file mode 100644 index 00000000..f43683c1 --- /dev/null +++ b/ui/src/state/client.ts @@ -0,0 +1,13 @@ +// At some point, I'd like to replace some of the Atuin calls +// with separate state handling here + +import { invoke } from "@tauri-apps/api/core"; +import { Settings } from "@/state/models"; + +export async function sessionToken(): Promise<String> { + return await invoke("session"); +} + +export async function settings(): Promise<Settings> { + return await invoke("config"); +} diff --git a/ui/src/state/models.ts b/ui/src/state/models.ts index b92d64a6..193b994d 100644 --- a/ui/src/state/models.ts +++ b/ui/src/state/models.ts @@ -69,6 +69,46 @@ export interface InspectHistory { other: ShellHistory[]; } +// Not yet complete. Not all types are defined here. +// Gonna hold off until the settings refactoring. +export interface Settings { + auto_sync: boolean; + update_check: boolean; + sync_address: string; + sync_frequency: string; + db_path: string; + record_store_path: string; + key_path: string; + session_path: string; + shell_up_key_binding: boolean; + inline_height: number; + invert: boolean; + show_preview: boolean; + max_preview_height: number; + show_help: boolean; + show_tabs: boolean; + word_chars: string; + scroll_context_lines: number; + history_format: string; + prefers_reduced_motion: boolean; + store_failed: boolean; + secrets_filter: boolean; + workspaces: boolean; + ctrl_n_shortcuts: boolean; + network_connect_timeout: number; + network_timeout: number; + local_timeout: number; + enter_accept: boolean; + smart_sort: boolean; + sync: Sync; +} + +interface Sync { + records: boolean; +} + +// Define other interfaces (Dialect, Timezone, Style, SearchMode, FilterMode, ExitMode, KeymapMode, CursorStyle, WordJumpMode, RegexSet, Stats) accordingly. + export async function inspectCommandHistory( h: ShellHistory, ): Promise<InspectHistory> { diff --git a/ui/src/state/store.ts b/ui/src/state/store.ts index fef1b632..56d7b224 100644 --- a/ui/src/state/store.ts +++ b/ui/src/state/store.ts @@ -1,6 +1,8 @@ import { create } from "zustand"; import { parseISO } from "date-fns"; +import { fetch } from "@tauri-apps/plugin-http"; + import { User, DefaultUser, @@ -9,9 +11,11 @@ import { Alias, ShellHistory, Var, + Settings, } from "./models"; import { invoke } from "@tauri-apps/api/core"; +import { sessionToken, settings } from "./client"; // I'll probs want to slice this up at some point, but for now a // big blobby lump of state is fine. @@ -26,6 +30,7 @@ interface AtuinState { refreshHomeInfo: () => void; refreshAliases: () => void; refreshVars: () => void; + refreshUser: () => void; refreshShellHistory: (query?: string) => void; historyNextPage: (query?: string) => void; } @@ -81,6 +86,21 @@ export const useStore = create<AtuinState>()((set, get) => ({ }); }, + refreshUser: async () => { + let config = await settings(); + let session = await sessionToken(); + let url = config.sync_address + "/api/v0/me"; + + let res = await fetch(url, { + headers: { + Authorization: `Token ${session}`, + }, + }); + let me = await res.json(); + + set({ user: me }); + }, + historyNextPage: (query?: string) => { let history = get().shellHistory; let offset = history.length - 1; |
