Skip to content

Commit

Permalink
creator toggle on submit/edit tool form
Browse files Browse the repository at this point in the history
  • Loading branch information
GraemeFulton committed Jun 5, 2024
1 parent c24a19f commit f0fadbd
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions components/toolbox/forms/DescriptionExcerptForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,23 @@ const Form = ({ user, postObject, isEditMode }) => {
values.excerpt = exc;
}

//turn postObject.creators array into an array of ids (from each element.id)
let creatorIds = [];
if (postObject?.creators?.length) {
creatorIds = postObject?.creators?.map(creator => creator.id);
}
if (values.isCreator) {
//turn postObject.creators array into an array of ids (from each element.id)

let creatorIds = [];
if (postObject?.creators?.length) {
creatorIds = postObject?.creators?.map(creator => creator.id);
}

//add user id to the array of creator ids if it's not already there
if (!creatorIds.includes(user.id)) {
creatorIds.push(user.id);
}
if(creatorIds.length>0){
values.creators = creatorIds
} else {
// remove user id from the array of creator ids if it's there
if (creatorIds.includes(user.id)) {
creatorIds = creatorIds.filter(id => id !== user.id);
}
}
values.creators = creatorIds;
delete values.isCreator;

async function submit() {
Expand Down

0 comments on commit f0fadbd

Please sign in to comment.