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

Edit protest flow v3 #142

Closed
wants to merge 16 commits into from
Closed

Edit protest flow v3 #142

wants to merge 16 commits into from

Conversation

uriklar
Copy link
Collaborator

@uriklar uriklar commented Oct 14, 2020

No description provided.

Copy link
Contributor

@ranyitz ranyitz left a 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])],
Copy link
Contributor

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 -

'roles.leader': firebase.firestore.FieldValue.arrayUnion(userId),

Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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);
Copy link
Contributor

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.

@guytepper guytepper linked an issue Nov 8, 2020 that may be closed by this pull request
@uriklar uriklar closed this Jul 19, 2022
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.

Track edits in a collection.
2 participants