Skip to content

Commit a42f0e8

Browse files
fix: navbar delete logic to prevent empty deletes (#261)
1 parent b414b99 commit a42f0e8

1 file changed

Lines changed: 26 additions & 13 deletions

File tree

frontend/src/components/HomeComponents/Navbar/navbar-utils.ts

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,36 @@ export const handleLogout = async () => {
5454
};
5555

5656
export const deleteAllTasks = async (props: Props) => {
57-
const loadingToastId = toast.info(
58-
`Deleting all tasks for ${props.email}...`,
59-
{
60-
position: 'bottom-left',
61-
autoClose: false,
62-
hideProgressBar: true,
63-
closeOnClick: false,
64-
pauseOnHover: true,
65-
draggable: true,
66-
}
67-
);
57+
const loadingToastId = toast.info(`Checking tasks for ${props.email}...`, {
58+
position: 'bottom-left',
59+
autoClose: false,
60+
hideProgressBar: true,
61+
closeOnClick: false,
62+
pauseOnHover: true,
63+
draggable: true,
64+
});
6865

6966
try {
67+
// Count tasks first
68+
const taskCount = await db.tasks.where('email').equals(props.email).count();
69+
70+
// If no tasks, show Red toast
71+
if (taskCount === 0) {
72+
toast.update(loadingToastId, {
73+
render: `No tasks to delete for ${props.email}.`,
74+
type: 'error',
75+
autoClose: 3000,
76+
hideProgressBar: false,
77+
closeOnClick: true,
78+
pauseOnHover: true,
79+
draggable: true,
80+
});
81+
return;
82+
}
7083
await db.tasks.where('email').equals(props.email).delete();
7184

7285
toast.update(loadingToastId, {
73-
render: `All tasks for ${props.email} deleted successfully!`,
86+
render: `All ${taskCount} tasks for ${props.email} deleted successfully!`,
7487
type: 'success',
7588
autoClose: 3000,
7689
hideProgressBar: false,
@@ -79,7 +92,7 @@ export const deleteAllTasks = async (props: Props) => {
7992
draggable: true,
8093
});
8194

82-
console.log(`Deleted tasks for email: ${props.email}`);
95+
console.log(`Deleted ${taskCount} tasks for email: ${props.email}`);
8396
} catch (error) {
8497
toast.update(loadingToastId, {
8598
render: `Error deleting tasks for ${props.email}: ${error}`,

0 commit comments

Comments
 (0)