2024-11-08 16:11:50 +08:00
|
|
|
import type { DebugInfo as DebugInfoTypes, InstalledPluginListResponse, Permissions } from '@/app/components/plugins/types'
|
|
|
|
import { get, post } from './base'
|
2024-11-07 16:52:22 +08:00
|
|
|
import {
|
2024-11-08 16:11:50 +08:00
|
|
|
useMutation,
|
2024-11-07 16:52:22 +08:00
|
|
|
useQueryClient,
|
|
|
|
} from '@tanstack/react-query'
|
|
|
|
|
|
|
|
import {
|
|
|
|
useQuery,
|
|
|
|
} from '@tanstack/react-query'
|
|
|
|
|
|
|
|
const NAME_SPACE = 'plugins'
|
|
|
|
|
|
|
|
const useInstalledPluginListKey = [NAME_SPACE, 'installedPluginList']
|
|
|
|
export const useInstalledPluginList = () => {
|
|
|
|
return useQuery<InstalledPluginListResponse>({
|
|
|
|
queryKey: useInstalledPluginListKey,
|
|
|
|
queryFn: () => get<InstalledPluginListResponse>('/workspaces/current/plugin/list'),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export const useInvalidateInstalledPluginList = () => {
|
|
|
|
const queryClient = useQueryClient()
|
|
|
|
return () => {
|
|
|
|
queryClient.invalidateQueries(
|
|
|
|
{
|
|
|
|
queryKey: useInstalledPluginListKey,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2024-11-08 15:10:06 +08:00
|
|
|
|
|
|
|
export const useDebugKey = () => {
|
|
|
|
return useQuery({
|
|
|
|
queryKey: [NAME_SPACE, 'debugKey'],
|
|
|
|
queryFn: () => get<DebugInfoTypes>('/workspaces/current/plugin/debugging-key'),
|
|
|
|
})
|
|
|
|
}
|
2024-11-08 16:11:50 +08:00
|
|
|
|
|
|
|
const usePermissionsKey = [NAME_SPACE, 'permissions']
|
|
|
|
export const usePermissions = () => {
|
|
|
|
return useQuery({
|
|
|
|
queryKey: usePermissionsKey,
|
|
|
|
queryFn: () => get<Permissions>('/workspaces/current/plugin/permission/fetch'),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export const useInvalidatePermissions = () => {
|
|
|
|
const queryClient = useQueryClient()
|
|
|
|
return () => {
|
|
|
|
queryClient.invalidateQueries(
|
|
|
|
{
|
|
|
|
queryKey: usePermissionsKey,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const useMutationPermissions = ({
|
|
|
|
onSuccess,
|
|
|
|
}: {
|
|
|
|
onSuccess?: () => void
|
|
|
|
}) => {
|
|
|
|
return useMutation({
|
|
|
|
mutationFn: (payload: Permissions) => {
|
|
|
|
return post('/workspaces/current/plugin/permission/change', { body: payload })
|
|
|
|
},
|
|
|
|
onSuccess,
|
|
|
|
})
|
|
|
|
}
|