mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-11 22:40:26 +01:00
Fix cookie jar query
This commit is contained in:
@@ -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 <div>No cookie jar selected</div>;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { CookieJar } from '@yaakapp-internal/models';
|
||||
import { atom, useAtomValue } from 'jotai';
|
||||
|
||||
export const cookieJarsAtom = atom<CookieJar[]>([]);
|
||||
export const cookieJarsAtom = atom<CookieJar[] | undefined>();
|
||||
|
||||
export function useCookieJars() {
|
||||
return useAtomValue(cookieJarsAtom);
|
||||
|
||||
@@ -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],
|
||||
);
|
||||
|
||||
|
||||
@@ -40,9 +40,6 @@ export function useSyncModelStores() {
|
||||
const setEnvironments = useSetAtom(environmentsAtom);
|
||||
|
||||
useListenToTauriEvent<ModelPayload>('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<T extends AnyModel>(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];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user