mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-24 10:21:15 +01:00
Dynamic plugins (#68)
This commit is contained in:
@@ -14,9 +14,11 @@ export function useActiveWorkspaceChangedToast() {
|
||||
|
||||
setId(activeWorkspace?.id ?? null);
|
||||
|
||||
// Don't notify on first load
|
||||
// Don't notify on the first load
|
||||
if (id === null) return;
|
||||
|
||||
console.log('HELLO?', activeWorkspace?.id, id, window.location);
|
||||
|
||||
toast.show({
|
||||
id: 'workspace-changed',
|
||||
timeout: 3000,
|
||||
|
||||
13
src-web/hooks/useCreatePlugin.ts
Normal file
13
src-web/hooks/useCreatePlugin.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
|
||||
export function useCreatePlugin() {
|
||||
return useMutation<void, unknown, string>({
|
||||
mutationKey: ['create_plugin'],
|
||||
mutationFn: async (directory: string) => {
|
||||
await invokeCmd('cmd_create_plugin', { directory });
|
||||
},
|
||||
onSettled: () => trackEvent('plugin', 'create'),
|
||||
});
|
||||
}
|
||||
13
src-web/hooks/usePluginInfo.ts
Normal file
13
src-web/hooks/usePluginInfo.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import type { BootResponse } from '@yaakapp/api';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
|
||||
export function usePluginInfo(id: string) {
|
||||
return useQuery({
|
||||
queryKey: ['plugin_info', id],
|
||||
queryFn: async () => {
|
||||
const info = (await invokeCmd('cmd_plugin_info', { id })) as BootResponse;
|
||||
return info;
|
||||
},
|
||||
});
|
||||
}
|
||||
23
src-web/hooks/usePlugins.ts
Normal file
23
src-web/hooks/usePlugins.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import type { Plugin } from '@yaakapp/api';
|
||||
import { atom, useAtomValue, useSetAtom } from 'jotai';
|
||||
import { minPromiseMillis } from '../lib/minPromiseMillis';
|
||||
import { listPlugins } from '../lib/store';
|
||||
|
||||
const plugins = await listPlugins();
|
||||
export const pluginsAtom = atom<Plugin[]>(plugins);
|
||||
|
||||
export function usePlugins() {
|
||||
return useAtomValue(pluginsAtom);
|
||||
}
|
||||
|
||||
export function useRefreshPlugins() {
|
||||
const setPlugins = useSetAtom(pluginsAtom);
|
||||
return useMutation({
|
||||
mutationKey: ['refresh_plugins'],
|
||||
mutationFn: async () => {
|
||||
const plugins = await minPromiseMillis(listPlugins());
|
||||
setPlugins(plugins);
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user