Skip to content

Commit

Permalink
Added the ability to delete a task
Browse files Browse the repository at this point in the history
  • Loading branch information
jonniebigodes committed Nov 3, 2023
1 parent c5c2d6d commit 910607e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/InboxScreen.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export default function InboxScreen({ error }) {
const archiveTask = (archive, id) => {
dispatch({ type: archive ? "ARCHIVE_TASK" : "INBOX_TASK", id });
};
const deleteTask = (id) => {
dispatch({ type: "DELETE_TASK", id });
};

const togglePinTask = (state, id) => {
dispatch({
Expand Down Expand Up @@ -41,6 +44,7 @@ export default function InboxScreen({ error }) {
onArchiveTask={archiveTask}
onTogglePinTask={togglePinTask}
onEditTitle={editTitle}
onDeleteTask={deleteTask}
/>
</div>
);
Expand Down
19 changes: 19 additions & 0 deletions src/InboxScreen.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,22 @@ export const EditTask = {
);
},
};

export const DeleteTask = {
parameters: {
...Default.parameters,
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const getTask = (id) => canvas.findByRole("listitem", { name: id });

const itemToDelete = await getTask("task-1");
const deleteButton = await findByRole(itemToDelete, "button", {
name: "delete",
});

// Click the pin button
await userEvent.click(deleteButton);
await expect(canvas.getAllByRole("listitem").length).toBe(5);
},
};
11 changes: 10 additions & 1 deletion src/components/Task.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export default function Task({
onArchiveTask,
onTogglePinTask,
onEditTitle,
onDeleteTask,
}) {
return (
<div
Expand Down Expand Up @@ -41,7 +42,13 @@ export default function Task({
onChange={(e) => onEditTitle(e.target.value, id)}
/>
</label>

<button
aria-label="delete"
className="delete-button"
onClick={() => onDeleteTask(id)}
>
<span className="icon-trash" />
</button>
{state !== "TASK_ARCHIVED" && (
<button
className="pin-button"
Expand Down Expand Up @@ -73,4 +80,6 @@ Task.propTypes = {
onTogglePinTask: PropTypes.func.isRequired,
/** Event to change the task title */
onEditTitle: PropTypes.func.isRequired,
/** Event to delete the task */
onDeleteTask: PropTypes.func.isRequired,
};
1 change: 1 addition & 0 deletions src/components/Task.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default {
onArchiveTask: { action: "onArchiveTask" },
onTogglePinTask: { action: "onTogglePinTask" },
onEditTitle: { action: "onEditTitle" },
onDeleteTask: { action: "onDeleteTask" },
},
};

Expand Down
3 changes: 3 additions & 0 deletions src/components/TaskList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ export default function TaskList({
onTogglePinTask,
onArchiveTask,
onEditTitle,
onDeleteTask,
}) {
const events = {
onTogglePinTask,
onArchiveTask,
onEditTitle,
onDeleteTask,
};

const LoadingRow = (
Expand Down Expand Up @@ -69,6 +71,7 @@ TaskList.propTypes = {
onTogglePinTask: PropTypes.func.isRequired,
onArchiveTask: PropTypes.func.isRequired,
onEditTitle: PropTypes.func.isRequired,
onDeleteTask: PropTypes.func.isRequired,
};

TaskList.defaultProps = {
Expand Down

0 comments on commit 910607e

Please sign in to comment.