Skip to content

Commit 0af71af

Browse files
committed
[Launcher] Improve api key handling + reload button
1 parent be1342e commit 0af71af

File tree

5 files changed

+66
-54
lines changed

5 files changed

+66
-54
lines changed

apps/launcher/src/lib/command/main.svelte

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import * as Command from "@repo/ui/components/command";
33
import { Separator } from "@repo/ui/components/separator";
44
import { Shortcut } from "@repo/ui/components/shortcut";
5-
import { Stash, Unplug } from "@repo/ui/icons";
5+
import { RotateCcw, Stash, Unplug } from "@repo/ui/icons";
66
import { onMount } from "svelte";
77
import { getCommandMenuContext } from "./context";
88
import { apiKey, groups, loading, saves } from "$lib/stores";
@@ -13,6 +13,7 @@
1313
import { siteConfig } from "@repo/constants";
1414
import { Badge } from "@repo/ui/components/badge";
1515
import { get, writable } from "svelte/store";
16+
import { getItems } from "$lib/queries";
1617
1718
const { cmdPressed, commandPages, handleItemSelect, searchValue, searchInput, changePage, getCurrentPage, availablePages, resetPages } = getCommandMenuContext();
1819
@@ -130,9 +131,13 @@
130131
<Stash class="me-2 shrink-0" />
131132
Open Stashlist
132133
</Command.Item>
133-
<Command.Item onSelect={() => changePage(availablePages.connect)} value="Connect your stashes">
134+
<Command.Item onSelect={() => getItems()} value="Reload items stashes">
135+
<RotateCcw class="me-2 shrink-0" />
136+
Reload stashes
137+
</Command.Item>
138+
<Command.Item onSelect={() => changePage(availablePages.connect)} value="Connect your account stashes">
134139
<Unplug class="me-2 shrink-0" />
135-
Connect your stashes
140+
Connect your account
136141
{#if $apiKey}
137142
<Badge class="ml-auto">Connected</Badge>
138143
{/if}

apps/launcher/src/lib/command/pages/connect.svelte

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import { get } from "svelte/store";
88
import { apiKey } from "$lib/stores";
99
import { toast } from "@repo/ui/components/sonner";
10+
import { invalidateAll } from "$app/navigation";
11+
import { getItems } from "$lib/queries";
1012
1113
let apiKeyFormError = '';
1214
@@ -53,6 +55,7 @@
5355
apiKey.set($searchValue);
5456
apiKeyFormError = '';
5557
toast.success('API key connected!');
58+
getItems();
5659
setTimeout(() => {
5760
goPageBack();
5861
}, 50);

apps/launcher/src/lib/queries.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { groups, loading, saves } from "./stores";
2+
import { getRecord } from "./stronghold";
3+
import { dev } from "$app/environment";
4+
import { fetch } from '@tauri-apps/plugin-http';
5+
6+
export async function getItems() {
7+
loading.set(true);
8+
const getData = async (url: string) => {
9+
const response = await fetch(url,
10+
{
11+
method: 'GET',
12+
headers: {
13+
'X-Api-Key': await getRecord('api-key'),
14+
}
15+
}
16+
);
17+
18+
if (!response.ok) {
19+
console.error(response.statusText, response);
20+
loading.set(false);
21+
return;
22+
}
23+
24+
let result;
25+
26+
if (dev) {
27+
result = await response.text();
28+
result = JSON.parse(result);
29+
} else {
30+
result = await response.json();
31+
}
32+
33+
return result;
34+
}
35+
36+
let savesData: any;
37+
let groupsData: any;
38+
if (dev) {
39+
savesData = await getData('/saves.json');
40+
groupsData = await getData('/groups.json');
41+
} else {
42+
savesData = await getData('https://www.stashlist.app/api/saves');
43+
groupsData = await getData('https://www.stashlist.app/api/groups');
44+
}
45+
46+
saves.set(savesData?.saves);
47+
groups.set(groupsData);
48+
49+
loading.set(false);
50+
}

apps/launcher/src/routes/+layout.svelte

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
55
import { onMount } from 'svelte';
66
import { getRecord, initStronghold } from '$lib/stronghold';
7-
import { apiKey, currentPage, groups, loading, saves } from '$lib/stores';
7+
import { apiKey, currentPage } from '$lib/stores';
88
import { listen } from '@tauri-apps/api/event';
99
import { setCommandMenuContext, getCommandMenuContext } from "$lib/command/context";
1010
import { Toaster } from '@repo/ui/components/sonner';
11-
import { dev } from "$app/environment";
12-
import { fetch } from '@tauri-apps/plugin-http';
11+
import { getItems } from '$lib/queries';
1312
1413
type Payload = 'opened' | 'closed';
1514
@@ -25,7 +24,7 @@
2524
removeTrapFocusListeners = trapFocus();
2625
const unlisten = listenForEvents();
2726
document.addEventListener('keydown', onKeydown);
28-
27+
2928
(async () => {
3029
await initStronghold();
3130
const apiKeyFromStronghold = await getRecord('api-key');
@@ -111,52 +110,6 @@
111110
}
112111
}
113112
114-
async function getItems() {
115-
loading.set(true);
116-
const getData = async (url: string) => {
117-
const response = await fetch(url,
118-
{
119-
method: 'GET',
120-
headers: {
121-
'X-Api-Key': await getRecord('api-key'),
122-
}
123-
}
124-
);
125-
126-
if (!response.ok) {
127-
console.error(response.statusText, response);
128-
loading.set(false);
129-
return;
130-
}
131-
132-
let result;
133-
134-
if (dev) {
135-
result = await response.text();
136-
result = JSON.parse(result);
137-
} else {
138-
result = await response.json();
139-
}
140-
141-
return result;
142-
}
143-
144-
let savesData: any;
145-
let groupsData: any;
146-
if (dev) {
147-
savesData = await getData('/saves.json');
148-
groupsData = await getData('/groups.json');
149-
} else {
150-
savesData = await getData('https://www.stashlist.app/api/saves');
151-
groupsData = await getData('https://www.stashlist.app/api/groups');
152-
}
153-
154-
saves.set(savesData?.saves);
155-
groups.set(groupsData);
156-
157-
loading.set(false);
158-
}
159-
160113
</script>
161114

162115
<Toaster offset={16} duration={1300} position="bottom-center" />

packages/ui/icons/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Icon as LucideIcon } from "lucide-svelte";
22

3-
import { Inbox, Monitor, Plus, FolderPlus, Folder, Check, Bookmark, Compass, LogOut, Pencil, Trash2, X, Sun, Moon, MoreHorizontal, Trash, CircleDashed, Loader, LayoutGrid, StretchHorizontal, ChevronsUpDown, LayoutDashboard, Copy, GripVertical, Tv, Info, Space, Folders, Eye, EyeOff, ChevronLeft, Unplug, Search } from "lucide-svelte";
3+
import { Inbox, Monitor, Plus, FolderPlus, Folder, Check, Bookmark, Compass, LogOut, Pencil, Trash2, X, Sun, Moon, MoreHorizontal, Trash, CircleDashed, Loader, LayoutGrid, StretchHorizontal, ChevronsUpDown, LayoutDashboard, Copy, GripVertical, Tv, Info, Space, Folders, Eye, EyeOff, ChevronLeft, Unplug, Search, RotateCcw } from "lucide-svelte";
44

55
import GitHub from "./github.svelte";
66
import Google from "./google.svelte";
@@ -47,4 +47,5 @@ export {
4747
Search,
4848
Eye,
4949
EyeOff,
50+
RotateCcw,
5051
}

0 commit comments

Comments
 (0)