Skip to content

Commit

Permalink
Trash mutation actually works as intended
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff McMillen authored and Jeff McMillen committed Dec 5, 2024
1 parent d3de63f commit 754f583
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,29 +174,17 @@ const DataFilesToolbar = ({ scheme, api }) => {
}
};

const trashCallback = useCallback(() => {
const filteredSelected = selectedFiles.filter(
(f) => status[f.system + f.path] !== 'SUCCESS'
);
trash({
filteredSelected, reloadPage
});



// dispatch({
// type: 'DATA_FILES_TRASH',
// payload: {
// src: filteredSelected,
// homeDir: selectedSystem?.homeDir || '',
// reloadCallback: reloadPage,
// },
// });
}, [selectedFiles, selectedSystem, reloadPage]);
const homeDir = selectedSystem?.homeDir;



// const { status: trashStatus } = useTrash();
const trashCallback = useCallback(() => {
trash({
destSystem: selectedSystem.system,
homeDir: homeDir,
callback: reloadPage,
});
},
[selectedFiles, reloadPage, status]
);

const empty = () => {
dispatch({
Expand Down Expand Up @@ -282,7 +270,7 @@ const DataFilesToolbar = ({ scheme, api }) => {
<ToolbarButton
text={!inTrash ? 'Trash' : 'Empty'}
iconName="trash"
onClick={!inTrash ? trash : empty}
onClick={!inTrash ? trashCallback : empty}
disabled={!inTrash ? !canTrash : !canEmpty}
className={!inTrash ? '' : 'is-empty'}
/>
Expand Down
31 changes: 13 additions & 18 deletions client/src/hooks/datafiles/mutations/useTrash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useSelector, useDispatch, shallowEqual } from 'react-redux';
import { useMutation } from '@tanstack/react-query';
import { useSelectedFiles } from 'hooks/datafiles';
import Cookies from 'js-cookie';
import { apiClient } from 'utils/apiClient';

export async function trashUtil({
api,
Expand All @@ -17,19 +16,12 @@ export async function trashUtil({
path: string;
homeDir: string;
}) {
// const body = {
// homeDir: homeDir
// };
console.log(homeDir);
const url = `/api/datafiles/${api}/trash/${scheme}/${system}/${path}/`;
// const request = await apiClient.put(url, {
// const request = await apiClient.put(url, body, {
// headers: {
// 'X-CSRFToken': Cookies.get('csrftoken'),
// 'X-CSRFToken': Cookies.get('csrftoken' || ''),
// },
// withCredentials: true,
// body: JSON.stringify({
// homeDir: homeDir,
// }),
// });
const request = await fetch(url, {
method: 'PUT',
Expand All @@ -53,9 +45,10 @@ function useTrash() {
shallowEqual
);

const { api, scheme, homeDir } = useSelector(
const { api, scheme } = useSelector(
(state: any) => state.files.params.FilesListing
);

const setStatus = (newStatus: any) => {
dispatch({
type: 'DATA_FILES_SET_OPERATION_STATUS',
Expand All @@ -66,11 +59,13 @@ function useTrash() {
const { mutateAsync } = useMutation({ mutationFn: trashUtil });

const trash = ({
selection,
// callback,
destSystem,
homeDir,
callback,
}: {
selection: any;
// callback: any;
destSystem: string;
homeDir: any;
callback: any;
}) => {
const filteredSelected = selected.filter(
(f: any) => status[f.id] !== 'SUCCESS'
Expand All @@ -89,7 +84,7 @@ function useTrash() {
{
api: api,
scheme: scheme,
system: file.system,
system: destSystem,
path: file.path,
homeDir: homeDir,
},
Expand All @@ -106,10 +101,10 @@ function useTrash() {
dispatch({
type: 'ADD_TOAST',
payload: {
message: `${selection} moved to Trash`,
message: `File moved to Trash`,
},
});
// callback;
callback();
},
onError: () => {
dispatch({
Expand Down

0 comments on commit 754f583

Please sign in to comment.