-
Notifications
You must be signed in to change notification settings - Fork 32
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
Edit protest flow v3 #142
Edit protest flow v3 #142
Conversation
…edit-protest-flow-v2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, added some minor comments
.collection('users') | ||
.doc(user.uid) | ||
.update({ | ||
edits: [...new Set([...(user.edits || []), protestId])], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to push the new protestsId into the edits list, I would use the following - https://firebase.google.com/docs/reference/js/firebase.firestore.FieldValue#arrayunion
It has been done similarly here -
Line 350 in 5cf936c
'roles.leader': firebase.firestore.FieldValue.arrayUnion(userId), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each specified element that doesn't already exist in the array will be added to the end.
According to the docs we don't need to use a Set
to keep the array unique in firestore.
edits.push({ id: doc.id, ...doc.data() }); | ||
}); | ||
|
||
console.log('edits in function', edits); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log('edits in function', edits); |
@@ -203,7 +193,7 @@ export default function ProtestPage({ user }) { | |||
|
|||
const { coordinates, id } = protest; | |||
|
|||
const canEdit = isAdmin(user) || isLeader(user, protest); | |||
const canEdit = !!user && (user?.edits?.length || 0) < 5; //isAdmin(user) || isLeader(user, protest); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that it's not relevant specifically to here, and that it's not critical. But the name "edits" doesn't explain that this is an array of unique protest Ids, and one might think that those are individual edits.
It worth either change the name of this property to something like edited_protests
or add a comment about who can edit, so this logic will be a bit clearer.
No description provided.