fix: prevent duplicate tags on publish form

This commit is contained in:
Sean Yesmunt 2019-07-08 13:17:13 -04:00
parent 8c7bb327d8
commit e5afc29f00
2 changed files with 9 additions and 2 deletions

View file

@ -136,7 +136,14 @@ function PublishForm(props: Props) {
suggestMature
help={__('The better your tags are, the easier it will be for people to discover your content.')}
empty={__('No tags added')}
onSelect={tag => updatePublishForm({ tags: [...tags, tag] })}
onSelect={newTag => {
if (!tags.map(savedTag => savedTag.name).includes(newTag.name)) {
updatePublishForm({ tags: [...tags, newTag] });
} else {
// If it already exists and the user types it in, remove it
updatePublishForm({ tags: tags.filter(tag => tag.name !== newTag.name) });
}
}}
onRemove={clickedTag => {
const newTags = tags.slice().filter(tag => tag.name !== clickedTag.name);
updatePublishForm({ tags: newTags });

View file

@ -532,4 +532,4 @@
"View Your Feed": "View Your Feed",
"View Your Channels": "View Your Channels",
"Unfollow": "Unfollow"
}
}