generated from the-collab-lab/smart-shopping-list
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from the-collab-lab/el-delete-list
Delete a shopping list
- Loading branch information
Showing
6 changed files
with
71 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,34 @@ | ||
import './SingleList.css'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { deleteList } from '../api'; | ||
|
||
export function SingleList({ name, path, setListPath }) { | ||
export function SingleList({ name, path, setListPath, userId, userEmail }) { | ||
const navigate = useNavigate(); | ||
const isUsersList = userId === path.split('/')[0]; | ||
|
||
function handleClick() { | ||
setListPath(path); | ||
navigate('/list'); | ||
} | ||
|
||
const handleDelete = async (path, userEmail) => { | ||
if (window.confirm(`Do you really want to delete ${name}?`)) { | ||
try { | ||
await deleteList(path, userEmail); | ||
setListPath(null); | ||
} catch (error) { | ||
console.log(error); | ||
alert('Failed to delete the list. Please try again!'); | ||
} | ||
} | ||
}; | ||
|
||
return ( | ||
<li className="SingleList"> | ||
<button onClick={handleClick}>{name}</button> | ||
{isUsersList && ( | ||
<button onClick={() => handleDelete(path, userEmail)}>X</button> | ||
)} | ||
</li> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export * from './ListItem'; | ||
export * from './SingleList'; | ||
export * from './AddItem'; | ||
export * from './AddList'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters