mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-27 03:41:11 +01:00
Plugin runtime v2 (#62)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useEffect, useMemo } from 'react';
|
||||
import { useActiveWorkspaceId } from './useActiveWorkspaceId';
|
||||
import { useCookieJars } from './useCookieJars';
|
||||
import { useKeyValue } from './useKeyValue';
|
||||
@@ -7,22 +7,30 @@ export function useActiveCookieJar() {
|
||||
const workspaceId = useActiveWorkspaceId();
|
||||
const cookieJars = useCookieJars();
|
||||
|
||||
const kv = useKeyValue<string | null>({
|
||||
const {
|
||||
set: setActiveCookieJarId,
|
||||
value: activeCookieJarId,
|
||||
isLoading: isLoadingActiveCookieJarId,
|
||||
} = useKeyValue<string | null>({
|
||||
namespace: 'global',
|
||||
key: ['activeCookieJar', workspaceId ?? 'n/a'],
|
||||
fallback: null,
|
||||
});
|
||||
|
||||
const activeCookieJar = cookieJars.find((cookieJar) => cookieJar.id === kv.value);
|
||||
const activeCookieJar = useMemo(
|
||||
() => cookieJars.find((cookieJar) => cookieJar.id === activeCookieJarId),
|
||||
[activeCookieJarId, cookieJars],
|
||||
);
|
||||
|
||||
// TODO: Make this not be called so many times (move to GlobalHooks?)
|
||||
useEffect(() => {
|
||||
if (!kv.isLoading && activeCookieJar == null && cookieJars.length > 0) {
|
||||
kv.set(cookieJars[0]?.id ?? null);
|
||||
if (!isLoadingActiveCookieJarId && activeCookieJar == null && cookieJars.length > 0) {
|
||||
setActiveCookieJarId(cookieJars[0]?.id ?? null).catch(console.error);
|
||||
}
|
||||
}, [activeCookieJar, cookieJars, kv]);
|
||||
}, [activeCookieJar, cookieJars, isLoadingActiveCookieJarId, setActiveCookieJarId]);
|
||||
|
||||
return {
|
||||
activeCookieJar: activeCookieJar ?? null,
|
||||
setActiveCookieJarId: kv.set,
|
||||
setActiveCookieJarId: setActiveCookieJarId,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import type { JsonValue } from '@yaakapp/api/lib/gen/serde_json/JsonValue';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
|
||||
export function useFilterResponse({
|
||||
@@ -15,7 +16,8 @@ export function useFilterResponse({
|
||||
return null;
|
||||
}
|
||||
|
||||
return (await invokeCmd('cmd_filter_response', { responseId, filter })) as string | null;
|
||||
const items = (await invokeCmd('cmd_filter_response', { responseId, filter })) as JsonValue[];
|
||||
return JSON.stringify(items, null, 2);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import type { Settings } from '../lib/gen/Settings';
|
||||
import type { Settings } from '../lib/models/Settings';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
|
||||
export function settingsQueryKey() {
|
||||
|
||||
@@ -12,9 +12,7 @@ export function useWorkspaces() {
|
||||
useQuery({
|
||||
queryKey: workspacesQueryKey(),
|
||||
queryFn: async () => {
|
||||
console.log('GETTING WORKSPACES');
|
||||
const workspaces = await invokeCmd('cmd_list_workspaces');
|
||||
console.log('GOT WORKSPACES');
|
||||
return workspaces as Workspace[];
|
||||
},
|
||||
}).data ?? []
|
||||
|
||||
Reference in New Issue
Block a user