Skip to content

Commit

Permalink
remove contain if block to make UX better
Browse files Browse the repository at this point in the history
  • Loading branch information
warrenchan13 committed Oct 1, 2024
1 parent 7aab0a9 commit 440720e
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/components/ListItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { useState } from 'react';
import './ListItem.css';
import { updateItem, deleteItem } from '../api';
import { calculateDateNextPurchased, ONE_DAY_IN_MILLISECONDS } from '../utils';
import { toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';

const currentDate = new Date();

Expand Down Expand Up @@ -39,19 +41,18 @@ export function ListItem({ item, listPath }) {

await updateItem(listPath, id, { ...updatedItem });
} catch (error) {
alert(`Item was not marked as purchased`, error.message);
toast.error(`Item was not marked as purchased`, error.message);
}
}
};

const handleDeleteItem = async () => {
if (confirm(`Are you sure you want to delete this item?`)) {
try {
await deleteItem(listPath, id);
} catch (error) {
alert('Item was not deleted');
}
try {
await deleteItem(listPath, id);
} catch (error) {
toast.error('Item was not deleted');
}

return;
};

Expand Down

0 comments on commit 440720e

Please sign in to comment.