generated from the-collab-lab/smart-shopping-list
-
Notifications
You must be signed in to change notification settings - Fork 3
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 #34 from the-collab-lab/ju-vi-delete-list
Ju vi delete list
- Loading branch information
Showing
3 changed files
with
75 additions
and
1 deletion.
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,16 +1,44 @@ | ||
import { useNavigate } from 'react-router-dom'; | ||
import './SingleList.css'; | ||
import { deleteList } from '../api/firebase'; | ||
|
||
export function SingleList({ name, path, setListPath }) { | ||
export function SingleList({ userEmail, name, path, setListPath, userId }) { | ||
const navigate = useNavigate(); | ||
function handleClick() { | ||
setListPath(path); | ||
navigate(`/list/${path}`); | ||
} | ||
|
||
function handleDelete(user, email, listPath, listName) { | ||
if (listPath.includes(user)) { | ||
if ( | ||
window.confirm( | ||
`Do you really want to delete ${listName.toUpperCase()} list?`, | ||
) | ||
) { | ||
deleteList(user, email, listPath, listName); | ||
} | ||
return; | ||
} | ||
if ( | ||
window.confirm( | ||
`Do you really want to stop using ${listName.toUpperCase()} list?`, | ||
) | ||
) { | ||
deleteList(user, email, listPath, listName); | ||
} | ||
return; | ||
} | ||
|
||
return ( | ||
<li className="SingleList"> | ||
<button onClick={handleClick}>{name}</button> | ||
<button | ||
className="List__delete-button" | ||
onClick={() => handleDelete(userId, userEmail, path, name)} | ||
> | ||
Delete List | ||
</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