Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
SophieLab committed Sep 16, 2024
1 parent 01fa325 commit 09d7b20
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/content/series/SeriesActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ const SeriesActions: React.FC<SeriesActionsProps> = ({ series, onActionClick })
color: 'red',
action: () => onActionClick('delete', series)
},
{
label: 'addToDeleteList',
icon: <FaTrash />,
color: 'red',
action: () => onActionClick('addToDeleteList', series)
},
];

const handleClick = (e: React.MouseEvent) => {
Expand Down
13 changes: 13 additions & 0 deletions src/content/series/SeriesRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { useCustomToast } from '../../utils/toastify';
import { Modal, Spinner } from '../../ui';
import Tags from './Tags';
import { exportRessource } from '../../services/export';
import { useDispatch } from 'react-redux';
import { addSeriesToDeleteList } from '../../reducers/DeleteSlice';

interface SeriesRootProps {
studyId: string;
Expand All @@ -25,6 +27,7 @@ const SeriesRoot: React.FC<SeriesRootProps> = ({ studyId }) => {
const [previewMetadata, setPreviewMetadata] = useState<Series | null>(null);

const { confirm } = useConfirm();
const dispatch = useDispatch()
const { toastSuccess, toastError, updateExistingToast } = useCustomToast();

const { data: seriesList, isLoading, refetch: refetchSeries } = useCustomQuery<Series[]>(
Expand Down Expand Up @@ -79,6 +82,13 @@ const SeriesRoot: React.FC<SeriesRootProps> = ({ studyId }) => {
}
};

const handleTestSendRedux = (series: Series) => {
dispatch(addSeriesToDeleteList({
study: null,
series: series,
}))
}


const handleSeriesAction = (action: string, series: Series) => {
switch (action) {
Expand All @@ -97,6 +107,9 @@ const SeriesRoot: React.FC<SeriesRootProps> = ({ studyId }) => {
case 'download':
handleDownloadSeries(series);
break;
case 'addToDeleteList':
handleTestSendRedux(series)
break;
default:
console.log(`Unhandled action: ${action}`);
}
Expand Down
51 changes: 51 additions & 0 deletions src/reducers/DeleteSlice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { PayloadAction, createSlice } from '@reduxjs/toolkit';
import { Series, SeriesMainDicomTags, Study, StudyMainDicomTags } from '../utils/types';

export interface DeleteState {
series: {
[seriesId: string]: {
studyId: string,
seriesId: string,
studyMainDicomTags: StudyMainDicomTags,
seriesMainDicomTags: SeriesMainDicomTags
}
}
}

type DeletePayload = {
study: Study,
series: Series
}

type RemovePayload = {
seriesId: string
}

const initialState: DeleteState = {
series: {},
}

const deleteSlice = createSlice({
name: 'delete',
initialState,
reducers: {
addSeriesToDeleteList: (state, action: PayloadAction<DeletePayload>) => {
const study = action.payload.study;
const series = action.payload.series;

state.series[series.id] = {
studyId: study.id,
seriesId: series.id,
studyMainDicomTags: study.mainDicomTags,
seriesMainDicomTags: series.mainDicomTags
}

},
removeSeriesFromDeleteList: (state, action: PayloadAction<RemovePayload>) => {
const seriesId = action.payload.seriesId;
delete state.series?.[seriesId]
}
}
})
export const { addSeriesToDeleteList, removeSeriesFromDeleteList } = deleteSlice.actions;
export default deleteSlice.reducer;
2 changes: 2 additions & 0 deletions src/store.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@

import { configureStore } from "@reduxjs/toolkit";
import UserSlice from "./reducers/UserSlice";
import DeleteSlice from "./reducers/DeleteSlice";

const store = configureStore({
reducer: {
user: UserSlice,
delete : DeleteSlice
},
devTools: true,
});
Expand Down

0 comments on commit 09d7b20

Please sign in to comment.