前端: 添加useTrash回收站钩子
This commit is contained in:
parent
23ca5df4a7
commit
c8394816a4
36
frontend/src/renderer/hooks/useTrash.js
Normal file
36
frontend/src/renderer/hooks/useTrash.js
Normal 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;
|
||||||
Loading…
Reference in New Issue
Block a user