Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete a single list from shopping lists #51

Merged
merged 6 commits into from
Oct 2, 2024

Conversation

EmmaBin
Copy link
Collaborator

@EmmaBin EmmaBin commented Oct 1, 2024

Description

Users are able to delete an entire list from their collection from the home page by the click of a Delete button.
The selected list will be deleted from two locations in the database:

  • Users Collection:

From the document associated with the user's email, specifically in the sharedLists array.

  • Signed in user's Collection:

From the document representing the shopping lists for that user.

I learned that understanding the Firebase data structure would be crucial for completing this ticket. Initially, I could only delete items from the users' shopping lists, but I wasn't able to remove them from the sharedLists array associated with the users. While the UI updated successfully and one part of the database changed, refreshing the page caused all the deleted shopping lists to reappear. This happened because, upon refresh, the app fetches data from the sharedLists array using useShoppingList. By reviewing the parent component code and tracing where the data was coming from, I was finally able to debug the issue and complete this ticket.

Related Issue

closes #47

Acceptance Criteria

  • Next to each list button, there is a Delete button
  • Button will remove that list collection from Firebase.
  • Consider message / alert handling: "Are you sure you want to delete this list?" Y/N.

Type of Changes

Use one or more labels to help your team understand the nature of the change(s) you’re proposing. E.g., bug fix or enhancement are common ones.
feature enhancement

Updates

After

Screenshot 2024-10-01 at 11 52 45 AM
Screenshot 2024-10-01 at 11 52 56 AM

Testing Steps / QA Criteria

  1. Navigate to the branch: eb-delete-list-from-collection-issue-27.
  2. Delete a shopping list: Remove a shopping list from the shopping lists section. The list should disappear from the Home page.
  3. Verify in Firebase: Go to the Firebase database and check that the deleted list has been removed from the sharedLists array and the corresponding document (as shown in the screenshot).

@EmmaBin EmmaBin self-assigned this Oct 1, 2024
Copy link
Collaborator

@sar-mko sar-mko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great, could see the change on the home page and Firebase!

Something I noticed out of curiosity of what happens to lists that were shared, is that It wouldn't remove from other user's sharedList. I'm assuming because in this case we want to look through the current user's list and wanting to delete it for that user. I think this can definitely be a future issue, just wanted to put it out there!

if (window.confirm(`Are you sure you want to delete ${list.name}?`)) {
await deleteList(userEmail, list.path);
const updatedData = data.filter(
(eachList) => eachList.path !== list.path,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool idea using filter to find the list path!

@arandel1
Copy link
Collaborator

arandel1 commented Oct 2, 2024

Works great! I noticed a console.log message -- that can be removed before merged. Otherwise, nice job! -AR

Copy link

github-actions bot commented Oct 2, 2024

Visit the preview URL for this PR (updated for commit d172510):

https://tcl-76-smart-shopping-list--pr51-eb-delete-list-from-a6w8hq53.web.app

(expires Wed, 09 Oct 2024 05:19:50 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 512b1a88be8ae05fd3e727b99332819df760271d

@EmmaBin EmmaBin merged commit 75f72f8 into main Oct 2, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

27. As a user, I want to be able to delete a list from my collection
3 participants