Closed zeeatwork closed 3 years ago
Visit the preview URL for this PR (updated for commit 8a64de8):
https://tcl-23-shopping-list--pr18-za-jc-add-to-shoppin-tukvbk9a.web.app
(expires Sun, 25 Apr 2021 18:16:49 GMT)
🔥 via Firebase Hosting GitHub Action 🌎
Hi! I was able to start the branch up. I am able to switch between Add Item and List views, enter an item, select purchase frequency, and click the Submit button to add item to the Firestore!
I have not been able to get the item I add to the Firestore to show up in the List view. It is showing up in the Firestore. (I added goldfish and coffee beans.) I waited about an hour, and still nothing came through. I also did an npm install
for the heck of it but it did not help.
I've looked around at the code and done some digging in documents, but have not been able to find something where I can offer a helpful solution to try yet. The last thing I started to investigate that may or may not be a dead end has to do with the code in AddItem.js
. In the db.collection
portion, do we need to consider including a .update
?
I am looking at this article about Firebase Cloud Firestore
Example:
// Create an initial document to update.
var frankDocRef = db.collection("users").doc("frank"); frankDocRef.set({ name: "Frank", favorites: { food: "Pizza", color: "Blue", subject: "recess" }, age: 12 });
// To update age and favorite color:
db.collection("users").doc("frank").update({ "age": 13, "favorites.color": "Red" });
I will look more into it later this evening as well.
@jssckbl GREAT CATCH!!!
I believe the issue with not seeing the correct items returned is because we had not updated the following function in List.js:
const [value, loading, error] = useCollection(
db.collection('list').doc('user_2').collection('shopping_items'),
{
snapshotListenOptions: { includeMetadataChanges: true },
},
);
But I just updated it to:
const [value, loading, error] = useCollection(
db.collection('generated_token'),
{
snapshotListenOptions: { includeMetadataChanges: true },
},
);
Specifically db.collection('generated_token')
which matches the format in AddItem.js:
const createListItem = (e) => {
e.preventDefault();
db.collection('generated_token') <---- MATCHING THIS
.add({
item_name: itemName,
purchase_frequency: parseInt(purchaseFrequency),
last_purchased: lastPurchased,
})
.then((documentReference) => {
console.log('document reference ID', documentReference.id);
})
.catch((error) => {
console.log(error.message);
});
};
Now if you re-pull, it should work (hopefully!)
@jssckbl
There's your coffee beans and goldfish!
Description
This PR refactors 2 components: List.js and AddItem.js. The AddItem.js component now allows a user to add items to their personal shopping list. Upon form submission, data is added to our Firestore data structure (to be grouped by user-token at a later date). List.js now shows a list of grocery items and their purchase frequency. The list will only exhibit a single user's items.
During 4/14/21 group study session, we updated the configuration file to reflect updated import statement, and reduced the 'steps' into our shopping list so that each user will have a dedicated db.collection, then a unique token-id'd doc for a shopping list. We also fixed a bug related to our dropdown list's use onBlur vs. onChange. We added a preventDefault call to the same functional component (AddItem.js).
Related Issue
This pull request is related to issue #5
Acceptance Criteria
Type of Changes
Updates
Before
These screenshots show our Firestore Data structure. It's currently a collection called 'list' with a document of users (user_1 is a stand-in for future unique key users). Each user has a subcollection of a shopping list, which contains documents as shopping list items. (will insert visual aid here)
After
After consulting with the team, we've reconfigured our data for a more "shallow" query route. Now, the inital DB Collection is the user's unique token, then a document with a auto-generated id. The document features all shopping list values.
Testing Steps / QA Criteria
To test functionality: