前端: 添加useTrash回收站钩子

This commit is contained in:
Frontend Developer 2026-03-10 09:39:04 +00:00
parent 23ca5df4a7
commit c8394816a4

View File

@ -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;