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/store.ts | |
| 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/store.ts')
| -rw-r--r-- | ui/src/state/store.ts | 20 |
1 files changed, 20 insertions, 0 deletions
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; |
