Skip to content

Commit

Permalink
fix: Replace setDoc with addDoc for adding new items as we are not up…
Browse files Browse the repository at this point in the history
…dating existing items

- Delete comments referring to previous console.log usage
  • Loading branch information
marshjaja committed Aug 24, 2024
1 parent 6686de0 commit 765164b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/api/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
doc,
onSnapshot,
updateDoc,
addDoc,
} from 'firebase/firestore';
import { useEffect, useState } from 'react';
import { db } from './config';
Expand Down Expand Up @@ -127,6 +128,8 @@ export async function createList(userId, userEmail, listName) {
updateDoc(userDocumentRef, {
sharedLists: arrayUnion(listDocRef),
});

return listDocRef.path;
}

/**
Expand Down Expand Up @@ -163,15 +166,12 @@ export async function shareList(listPath, currentUserId, recipientEmail) {
*/
export async function addItem(listPath, { itemName, daysUntilNextPurchase }) {
const listCollectionRef = collection(db, listPath, 'items');
// TODO: Replace this call to console.log with the appropriate
// Firebase function, so this information is sent to your database!
const newItemEntry = doc(listCollectionRef);
return setDoc(newItemEntry, {
return addDoc(listCollectionRef, {
dateCreated: new Date(),
// NOTE: This is null because the item has just been created.
// We'll use updateItem to put a Date here when the item is purchased!
dateLastPurchased: null,
dateNextPurchased: getFutureDate(parseInt(daysUntilNextPurchase)),
dateNextPurchased: getFutureDate(daysUntilNextPurchase),
name: itemName,
totalPurchases: 0,
});
Expand Down

0 comments on commit 765164b

Please sign in to comment.