(onSuccess?: () => void)
| 2 | import { deleteModel } from '../lib/tauri'; |
| 3 | |
| 4 | export function useModelDelete(onSuccess?: () => void) { |
| 5 | const [isDeleting, setIsDeleting] = useState(false); |
| 6 | const [error, setError] = useState<string | null>(null); |
| 7 | |
| 8 | const handleDeleteModel = async (modelName: string) => { |
| 9 | // Show confirmation dialog |
| 10 | const confirmed = window.confirm( |
| 11 | `Are you sure you want to delete ${modelName}? This action cannot be undone.` |
| 12 | ); |
| 13 | |
| 14 | if (!confirmed) { |
| 15 | return; |
| 16 | } |
| 17 | |
| 18 | setIsDeleting(true); |
| 19 | setError(null); |
| 20 | |
| 21 | try { |
| 22 | await deleteModel(modelName); |
| 23 | if (onSuccess) { |
| 24 | onSuccess(); |
| 25 | } |
| 26 | } catch (err) { |
| 27 | const errorMessage = err instanceof Error ? err.message : 'Failed to delete model'; |
| 28 | setError(errorMessage); |
| 29 | console.error('Failed to delete model:', err); |
| 30 | } finally { |
| 31 | setIsDeleting(false); |
| 32 | } |
| 33 | }; |
| 34 | |
| 35 | return { |
| 36 | deleteModel: handleDeleteModel, |
| 37 | isDeleting, |
| 38 | error, |
| 39 | }; |
| 40 | } |
no outgoing calls
no test coverage detected