diff options
| author | Ellie Huxtable <ellie@elliehuxtable.com> | 2024-05-28 16:28:09 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-28 16:28:09 +0100 |
| commit | b49c73de3eded0a39091b24ef638e786500a2d7b (patch) | |
| tree | 1bdfa0d0ea124188e4faa1a04e6ca0eff575c961 /ui/src | |
| parent | fix: save sync time in daemon (#2051) (diff) | |
| download | atuin-b49c73de3eded0a39091b24ef638e786500a2d7b.zip | |
fix(ui): handle being logged out gracefully (#2052)
* fix(ui): handle being logged out gracefully
* use settings.logged_in
Diffstat (limited to 'ui/src')
| -rw-r--r-- | ui/src/pages/Home.tsx | 5 | ||||
| -rw-r--r-- | ui/src/state/models.ts | 2 | ||||
| -rw-r--r-- | ui/src/state/store.ts | 11 |
3 files changed, 14 insertions, 4 deletions
diff --git a/ui/src/pages/Home.tsx b/ui/src/pages/Home.tsx index ce42e0b1..93f2bf93 100644 --- a/ui/src/pages/Home.tsx +++ b/ui/src/pages/Home.tsx @@ -68,7 +68,10 @@ export default function Home() { stats={[ { name: "Last Sync", - stat: formatRelative(homeInfo.lastSyncTime, new Date()), + stat: + (homeInfo.lastSyncTime && + formatRelative(homeInfo.lastSyncTime, new Date())) || + "Never", }, { name: "Total history records", diff --git a/ui/src/state/models.ts b/ui/src/state/models.ts index 193b994d..57db44ae 100644 --- a/ui/src/state/models.ts +++ b/ui/src/state/models.ts @@ -11,7 +11,7 @@ export const DefaultUser: User = { export interface HomeInfo { historyCount: number; recordCount: number; - lastSyncTime: Date; + lastSyncTime: Date | null; } export const DefaultHomeInfo: HomeInfo = { diff --git a/ui/src/state/store.ts b/ui/src/state/store.ts index 56d7b224..5e2570bb 100644 --- a/ui/src/state/store.ts +++ b/ui/src/state/store.ts @@ -77,7 +77,7 @@ export const useStore = create<AtuinState>()((set, get) => ({ homeInfo: { historyCount: res.history_count, recordCount: res.record_count, - lastSyncTime: parseISO(res.last_sync), + lastSyncTime: (res.last_sync && parseISO(res.last_sync)) || null, }, }); }) @@ -88,7 +88,14 @@ export const useStore = create<AtuinState>()((set, get) => ({ refreshUser: async () => { let config = await settings(); - let session = await sessionToken(); + let session; + + try { + session = await sessionToken(); + } catch (e) { + console.log("Not logged in, so not refreshing user"); + return; + } let url = config.sync_address + "/api/v0/me"; let res = await fetch(url, { |
