68 lines
1.8 KiB
TypeScript
68 lines
1.8 KiB
TypeScript
|
|
/**
|
||
|
|
* Plugin management hooks: list, install, activate, deactivate, uninstall.
|
||
|
|
*/
|
||
|
|
|
||
|
|
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||
|
|
import { apiGet, apiPost, apiDelete } from './client';
|
||
|
|
|
||
|
|
export interface Plugin {
|
||
|
|
name: string;
|
||
|
|
display_name?: string;
|
||
|
|
description?: string;
|
||
|
|
version?: string;
|
||
|
|
status: 'discovered' | 'installed' | 'active' | 'inactive';
|
||
|
|
installed?: boolean;
|
||
|
|
active?: boolean;
|
||
|
|
}
|
||
|
|
|
||
|
|
export function usePlugins() {
|
||
|
|
return useQuery({
|
||
|
|
queryKey: ['plugins'],
|
||
|
|
queryFn: async () => {
|
||
|
|
const data = await apiGet<any>('/plugins');
|
||
|
|
return data;
|
||
|
|
},
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
export function useInstallPlugin() {
|
||
|
|
const queryClient = useQueryClient();
|
||
|
|
return useMutation({
|
||
|
|
mutationFn: (name: string) => apiPost(`/plugins/${name}/install`),
|
||
|
|
onSuccess: () => {
|
||
|
|
queryClient.invalidateQueries({ queryKey: ['plugins'] });
|
||
|
|
},
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
export function useActivatePlugin() {
|
||
|
|
const queryClient = useQueryClient();
|
||
|
|
return useMutation({
|
||
|
|
mutationFn: (name: string) => apiPost(`/plugins/${name}/activate`),
|
||
|
|
onSuccess: () => {
|
||
|
|
queryClient.invalidateQueries({ queryKey: ['plugins'] });
|
||
|
|
},
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
export function useDeactivatePlugin() {
|
||
|
|
const queryClient = useQueryClient();
|
||
|
|
return useMutation({
|
||
|
|
mutationFn: (name: string) => apiPost(`/plugins/${name}/deactivate`),
|
||
|
|
onSuccess: () => {
|
||
|
|
queryClient.invalidateQueries({ queryKey: ['plugins'] });
|
||
|
|
},
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
export function useUninstallPlugin() {
|
||
|
|
const queryClient = useQueryClient();
|
||
|
|
return useMutation({
|
||
|
|
mutationFn: ({ name, removeData }: { name: string; removeData: boolean }) =>
|
||
|
|
apiDelete(`/plugins/${name}?remove_data=${removeData}`),
|
||
|
|
onSuccess: () => {
|
||
|
|
queryClient.invalidateQueries({ queryKey: ['plugins'] });
|
||
|
|
},
|
||
|
|
});
|
||
|
|
}
|