mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-23 17:28:29 +02:00
Fix cookie jar query
This commit is contained in:
@@ -13,7 +13,7 @@ interface Props {
|
|||||||
export const CookieDialog = function ({ cookieJarId }: Props) {
|
export const CookieDialog = function ({ cookieJarId }: Props) {
|
||||||
const updateCookieJar = useUpdateCookieJar(cookieJarId ?? null);
|
const updateCookieJar = useUpdateCookieJar(cookieJarId ?? null);
|
||||||
const cookieJars = useCookieJars();
|
const cookieJars = useCookieJars();
|
||||||
const cookieJar = cookieJars.find((c) => c.id === cookieJarId);
|
const cookieJar = cookieJars?.find((c) => c.id === cookieJarId);
|
||||||
|
|
||||||
if (cookieJar == null) {
|
if (cookieJar == null) {
|
||||||
return <div>No cookie jar selected</div>;
|
return <div>No cookie jar selected</div>;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import { InlineCode } from './core/InlineCode';
|
|||||||
import { useDialog } from './DialogContext';
|
import { useDialog } from './DialogContext';
|
||||||
|
|
||||||
export function CookieDropdown() {
|
export function CookieDropdown() {
|
||||||
const cookieJars = useCookieJars();
|
const cookieJars = useCookieJars() ?? [];
|
||||||
const [activeCookieJar, setActiveCookieJarId] = useActiveCookieJar();
|
const [activeCookieJar, setActiveCookieJarId] = useActiveCookieJar();
|
||||||
const updateCookieJar = useUpdateCookieJar(activeCookieJar?.id ?? null);
|
const updateCookieJar = useUpdateCookieJar(activeCookieJar?.id ?? null);
|
||||||
const deleteCookieJar = useDeleteCookieJar(activeCookieJar ?? null);
|
const deleteCookieJar = useDeleteCookieJar(activeCookieJar ?? null);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export function useActiveCookieJar() {
|
|||||||
const cookieJars = useCookieJars();
|
const cookieJars = useCookieJars();
|
||||||
|
|
||||||
const activeCookieJar = useMemo(() => {
|
const activeCookieJar = useMemo(() => {
|
||||||
return cookieJars.find((cookieJar) => cookieJar.id === activeCookieJarId) ?? null;
|
return cookieJars?.find((cookieJar) => cookieJar.id === activeCookieJarId) ?? null;
|
||||||
}, [activeCookieJarId, cookieJars]);
|
}, [activeCookieJarId, cookieJars]);
|
||||||
|
|
||||||
return [activeCookieJar ?? null, setActiveCookieJarId] as const;
|
return [activeCookieJar ?? null, setActiveCookieJarId] as const;
|
||||||
@@ -19,6 +19,7 @@ export function useEnsureActiveCookieJar() {
|
|||||||
const cookieJars = useCookieJars();
|
const cookieJars = useCookieJars();
|
||||||
const [activeCookieJarId, setActiveCookieJarId] = useActiveCookieJarId();
|
const [activeCookieJarId, setActiveCookieJarId] = useActiveCookieJarId();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (cookieJars == null) return; // Hasn't loaded yet
|
||||||
if (cookieJars.find((j) => j.id === activeCookieJarId)) {
|
if (cookieJars.find((j) => j.id === activeCookieJarId)) {
|
||||||
return; // There's an active jar
|
return; // There's an active jar
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { CookieJar } from '@yaakapp-internal/models';
|
import type { CookieJar } from '@yaakapp-internal/models';
|
||||||
import { atom, useAtomValue } from 'jotai';
|
import { atom, useAtomValue } from 'jotai';
|
||||||
|
|
||||||
export const cookieJarsAtom = atom<CookieJar[]>([]);
|
export const cookieJarsAtom = atom<CookieJar[] | undefined>();
|
||||||
|
|
||||||
export function useCookieJars() {
|
export function useCookieJars() {
|
||||||
return useAtomValue(cookieJarsAtom);
|
return useAtomValue(cookieJarsAtom);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export function useRecentCookieJars() {
|
|||||||
}, [activeCookieJarId]);
|
}, [activeCookieJarId]);
|
||||||
|
|
||||||
const onlyValidIds = useMemo(
|
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],
|
[kv.value, cookieJars],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -40,9 +40,6 @@ export function useSyncModelStores() {
|
|||||||
const setEnvironments = useSetAtom(environmentsAtom);
|
const setEnvironments = useSetAtom(environmentsAtom);
|
||||||
|
|
||||||
useListenToTauriEvent<ModelPayload>('upserted_model', ({ payload }) => {
|
useListenToTauriEvent<ModelPayload>('upserted_model', ({ payload }) => {
|
||||||
if (payload.model.model !== 'key_value') {
|
|
||||||
console.log('Upserted model', payload.model);
|
|
||||||
}
|
|
||||||
const { model, windowLabel } = payload;
|
const { model, windowLabel } = payload;
|
||||||
const queryKey =
|
const queryKey =
|
||||||
model.model === 'grpc_event'
|
model.model === 'grpc_event'
|
||||||
@@ -129,10 +126,10 @@ export function useSyncModelStores() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateModelList<T extends AnyModel>(model: T, pushToFront: boolean) {
|
function updateModelList<T extends AnyModel>(model: T, pushToFront: boolean) {
|
||||||
return (current: T[]): T[] => {
|
return (current: T[] | undefined): T[] => {
|
||||||
const index = current.findIndex((v) => modelsEq(v, model)) ?? -1;
|
const index = current?.findIndex((v) => modelsEq(v, model)) ?? -1;
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
return [...current.slice(0, index), model, ...current.slice(index + 1)];
|
return [...(current ?? []).slice(0, index), model, ...(current ?? []).slice(index + 1)];
|
||||||
} else {
|
} else {
|
||||||
return pushToFront ? [model, ...(current ?? [])] : [...(current ?? []), model];
|
return pushToFront ? [model, ...(current ?? [])] : [...(current ?? []), model];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user