diff --git a/frontend/src/renderer/hooks/useTrash.js b/frontend/src/renderer/hooks/useTrash.js new file mode 100644 index 0000000..dad0c2a --- /dev/null +++ b/frontend/src/renderer/hooks/useTrash.js @@ -0,0 +1,36 @@ +import { useState } from 'react'; +import api from '../utils/api'; + +export const useTrash = () => { + const [files, setFiles] = useState([]); + const [loading, setLoading] = useState(false); + + const fetchTrash = async () => { + setLoading(true); + try { + const data = await api.get('/api/trash'); + setFiles(data.files || []); + } finally { + setLoading(false); + } + }; + + const restore = async (id) => { + await api.post(`/api/trash/${id}/restore`); + await fetchTrash(); + }; + + const permanentDelete = async (id) => { + await api.delete(`/api/trash/${id}`); + await fetchTrash(); + }; + + const emptyTrash = async () => { + await api.post('/api/trash/empty'); + setFiles([]); + }; + + return { files, loading, fetchTrash, restore, permanentDelete, emptyTrash }; +}; + +export default useTrash;