Skip to content

Commit 08c4809

Browse files
committed
feat: add erasing operation
1 parent c879179 commit 08c4809

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"react-redux": "^7.2.3",
2727
"react-router-dom": "^5.2.0",
2828
"react-scripts": "4.0.3",
29-
"task.json": "^2.2.0",
29+
"task.json": "^2.2.1",
3030
"task.json-client": "^0.1.4",
3131
"typeface-roboto": "^1.1.13",
3232
"typescript": "^4.2.3",

src/components/TaskList.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
Delete as DeleteIcon,
77
Pencil as PencilIcon,
88
Restore as RestoreIcon,
9-
Check as CheckIcon
9+
Check as CheckIcon,
10+
Close as CloseIcon
1011
} from "mdi-material-ui";
1112
import { TaskType, Task, taskUrgency } from "task.json";
1213
import { DateTime } from "luxon";
@@ -83,6 +84,7 @@ interface CustomToolbarSelectProps {
8384
selectedIds: string[];
8485
taskType: TaskType;
8586
onRemove: (ids: string[]) => void;
87+
onErase: (ids: string[]) => void;
8688
onUndo: (ids: string[]) => void;
8789
onDo: (ids: string[]) => void;
8890
};
@@ -122,6 +124,16 @@ const CustomToolbarSelect = (props: CustomToolbarSelectProps) => {
122124
</IconButton>
123125
</Tooltip>
124126
}
127+
{props.taskType === "removed" &&
128+
<Tooltip title="Erase Tasks">
129+
<IconButton
130+
className={classes.del}
131+
onClick={() => props.onErase(props.selectedIds)}
132+
>
133+
<CloseIcon />
134+
</IconButton>
135+
</Tooltip>
136+
}
125137
</div>
126138
);
127139
};
@@ -130,6 +142,7 @@ interface ActionsProps {
130142
taskType: TaskType;
131143
task: Task;
132144
onRemove: (ids: string[]) => void;
145+
onErase: (ids: string[]) => void;
133146
onUndo: (ids: string[]) => void;
134147
onDo: (ids: string[]) => void;
135148
onEdit: (task: Task) => void;
@@ -182,6 +195,17 @@ const Actions = (props: ActionsProps) => {
182195
</IconButton>
183196
</Tooltip>
184197
}
198+
{props.taskType === "removed" &&
199+
<Tooltip title="Erase">
200+
<IconButton
201+
className={`${classes.del} ${classes.actionButton}`}
202+
size="small"
203+
onClick={() => props.onErase([props.task.id])}
204+
>
205+
<CloseIcon />
206+
</IconButton>
207+
</Tooltip>
208+
}
185209
</>
186210
);
187211
};
@@ -224,6 +248,10 @@ function TaskList(props: Props) {
224248
}
225249
};
226250

251+
const eraseTasks = (ids: string[]) => {
252+
dispatch(rootActions.eraseTasks(ids));
253+
};
254+
227255
const undoTasks = (ids: string[]) => {
228256
if (props.taskType !== "todo") {
229257
dispatch(rootActions.undoTasks({
@@ -268,6 +296,7 @@ function TaskList(props: Props) {
268296
taskType={props.taskType}
269297
selectedIds={ids}
270298
onRemove={removeTasks}
299+
onErase={eraseTasks}
271300
onUndo={undoTasks}
272301
onDo={doTasks}
273302
/>
@@ -366,6 +395,7 @@ function TaskList(props: Props) {
366395
task={tasks[index]}
367396
onEdit={props.onEdit}
368397
onRemove={removeTasks}
398+
onErase={eraseTasks}
369399
onUndo={undoTasks}
370400
onDo={doTasks}
371401
/>

src/store/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { configureStore } from '@reduxjs/toolkit';
22
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
33
import { Notification, Settings } from "../types";
4-
import { initTaskJson, removeTasks, doTasks, undoTasks, Task, TaskJson, TaskType, idToIndex } from "task.json";
4+
import { initTaskJson, removeTasks, eraseTasks, doTasks, undoTasks, Task, TaskJson, TaskType, idToIndex } from "task.json";
55
import { login, syncTasks, uploadTasks, downloadTasks } from "./async-actions";
66
import _ from "lodash";
77
import { HttpError } from 'task.json-client';
@@ -60,6 +60,11 @@ const rootSlice = createSlice({
6060
const indexes = idToIndex(state.taskJson, type, ids);
6161
removeTasks(state.taskJson, type, indexes);
6262
},
63+
eraseTasks(state, action: PayloadAction<string[]>) {
64+
const ids = action.payload;
65+
const indexes = idToIndex(state.taskJson, "removed", ids);
66+
eraseTasks(state.taskJson, indexes);
67+
},
6368
doTasks(state, action: PayloadAction<string[]>) {
6469
const ids = action.payload;
6570
const indexes = idToIndex(state.taskJson, "todo", ids);

0 commit comments

Comments
 (0)