diff --git a/src-web/components/CookieDialog.tsx b/src-web/components/CookieDialog.tsx
index 8311667b..9fc177f4 100644
--- a/src-web/components/CookieDialog.tsx
+++ b/src-web/components/CookieDialog.tsx
@@ -13,7 +13,7 @@ interface Props {
export const CookieDialog = function ({ cookieJarId }: Props) {
const updateCookieJar = useUpdateCookieJar(cookieJarId ?? null);
const cookieJars = useCookieJars();
- const cookieJar = cookieJars.find((c) => c.id === cookieJarId);
+ const cookieJar = cookieJars?.find((c) => c.id === cookieJarId);
if (cookieJar == null) {
return
No cookie jar selected
;
diff --git a/src-web/components/CookieDropdown.tsx b/src-web/components/CookieDropdown.tsx
index 603f4d85..5843bbb3 100644
--- a/src-web/components/CookieDropdown.tsx
+++ b/src-web/components/CookieDropdown.tsx
@@ -12,7 +12,7 @@ import { InlineCode } from './core/InlineCode';
import { useDialog } from './DialogContext';
export function CookieDropdown() {
- const cookieJars = useCookieJars();
+ const cookieJars = useCookieJars() ?? [];
const [activeCookieJar, setActiveCookieJarId] = useActiveCookieJar();
const updateCookieJar = useUpdateCookieJar(activeCookieJar?.id ?? null);
const deleteCookieJar = useDeleteCookieJar(activeCookieJar ?? null);
diff --git a/src-web/hooks/useActiveCookieJar.ts b/src-web/hooks/useActiveCookieJar.ts
index 81152a24..2535e5d3 100644
--- a/src-web/hooks/useActiveCookieJar.ts
+++ b/src-web/hooks/useActiveCookieJar.ts
@@ -9,7 +9,7 @@ export function useActiveCookieJar() {
const cookieJars = useCookieJars();
const activeCookieJar = useMemo(() => {
- return cookieJars.find((cookieJar) => cookieJar.id === activeCookieJarId) ?? null;
+ return cookieJars?.find((cookieJar) => cookieJar.id === activeCookieJarId) ?? null;
}, [activeCookieJarId, cookieJars]);
return [activeCookieJar ?? null, setActiveCookieJarId] as const;
@@ -19,6 +19,7 @@ export function useEnsureActiveCookieJar() {
const cookieJars = useCookieJars();
const [activeCookieJarId, setActiveCookieJarId] = useActiveCookieJarId();
useEffect(() => {
+ if (cookieJars == null) return; // Hasn't loaded yet
if (cookieJars.find((j) => j.id === activeCookieJarId)) {
return; // There's an active jar
}
diff --git a/src-web/hooks/useCookieJars.ts b/src-web/hooks/useCookieJars.ts
index 2e9fbf2d..612e8c0f 100644
--- a/src-web/hooks/useCookieJars.ts
+++ b/src-web/hooks/useCookieJars.ts
@@ -1,7 +1,7 @@
import type { CookieJar } from '@yaakapp-internal/models';
import { atom, useAtomValue } from 'jotai';
-export const cookieJarsAtom = atom([]);
+export const cookieJarsAtom = atom();
export function useCookieJars() {
return useAtomValue(cookieJarsAtom);
diff --git a/src-web/hooks/useRecentCookieJars.ts b/src-web/hooks/useRecentCookieJars.ts
index 00a97668..36cdf9a6 100644
--- a/src-web/hooks/useRecentCookieJars.ts
+++ b/src-web/hooks/useRecentCookieJars.ts
@@ -31,7 +31,7 @@ export function useRecentCookieJars() {
}, [activeCookieJarId]);
const onlyValidIds = useMemo(
- () => kv.value?.filter((id) => cookieJars.some((e) => e.id === id)) ?? [],
+ () => kv.value?.filter((id) => cookieJars?.some((e) => e.id === id)) ?? [],
[kv.value, cookieJars],
);
diff --git a/src-web/hooks/useSyncModelStores.ts b/src-web/hooks/useSyncModelStores.ts
index 7cb99196..237ffb5d 100644
--- a/src-web/hooks/useSyncModelStores.ts
+++ b/src-web/hooks/useSyncModelStores.ts
@@ -40,9 +40,6 @@ export function useSyncModelStores() {
const setEnvironments = useSetAtom(environmentsAtom);
useListenToTauriEvent('upserted_model', ({ payload }) => {
- if (payload.model.model !== 'key_value') {
- console.log('Upserted model', payload.model);
- }
const { model, windowLabel } = payload;
const queryKey =
model.model === 'grpc_event'
@@ -129,10 +126,10 @@ export function useSyncModelStores() {
}
function updateModelList(model: T, pushToFront: boolean) {
- return (current: T[]): T[] => {
- const index = current.findIndex((v) => modelsEq(v, model)) ?? -1;
+ return (current: T[] | undefined): T[] => {
+ const index = current?.findIndex((v) => modelsEq(v, model)) ?? -1;
if (index >= 0) {
- return [...current.slice(0, index), model, ...current.slice(index + 1)];
+ return [...(current ?? []).slice(0, index), model, ...(current ?? []).slice(index + 1)];
} else {
return pushToFront ? [model, ...(current ?? [])] : [...(current ?? []), model];
}