Files
opencode-manager/frontend/src/hooks/useDeleteSkill.ts
T
Chris Scott 6e80cdfb8c feat: add skill installer (#279)
* feat: add skill installer with install/uninstall and settings UI

* feat: refactor skill installer with extracted SkillLibraryList component

* feat: simplify SkillsEditor, extract SkillLibraryList

* feat: refactor skill installer components and add github utility
2026-06-17 23:11:29 -04:00

37 lines
1.3 KiB
TypeScript

import { useState } from 'react'
import { useMutation, useQueryClient } from '@tanstack/react-query'
import { toast } from 'sonner'
import { settingsApi } from '@/api/settings'
import { invalidateSkillCaches } from '@/lib/queryInvalidation'
import type { SkillFileInfo } from '@opencode-manager/shared'
export function useDeleteSkill() {
const queryClient = useQueryClient()
const [deleteSkill, setDeleteSkill] = useState<SkillFileInfo | null>(null)
const deleteMutation = useMutation({
mutationFn: ({ name, scope, repoId }: { name: string; scope: SkillFileInfo['scope']; repoId?: number }) =>
settingsApi.deleteSkill(name, scope, repoId),
onSuccess: () => {
invalidateSkillCaches(queryClient)
toast.success('Skill deleted successfully')
},
onError: (error) => {
toast.error(error instanceof Error ? error.message : 'Failed to delete skill')
},
})
const confirmDelete = () => {
if (!deleteSkill) return
deleteMutation.mutate({
name: deleteSkill.name,
scope: deleteSkill.scope,
repoId: deleteSkill.scope === 'project' ? deleteSkill.repoId : undefined,
}, {
onSettled: () => setDeleteSkill(null),
})
}
return { deleteSkill, setDeleteSkill, confirmDelete, isDeleting: deleteMutation.isPending }
}