Skip to content

Commit

Permalink
feat(post): add a tag when clicked and remove it if it was selected
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroAkbal committed Jun 15, 2023
1 parent b9eedaa commit 8ace077
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components/posts/post/Post.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}>()
const emit = defineEmits<{
clickTag: [tag: Tag]
clickTag: [tag: string]
}>()
const userSettings = useUserSettings()
Expand Down
16 changes: 15 additions & 1 deletion pages/posts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,21 @@
}
async function onPostClickTag(tag: string) {
await reflectChangesInUrl({ page: null, tags: [new Tag({ name: tag })], filters: null })
let newTags = undefined
const filteredSelectedTags = selectedTags.value.filter((selectedTag) => selectedTag.name !== tag)
// If the tag was not found, add it
if (filteredSelectedTags.length === selectedTags.value.length) {
newTags = [...selectedTags.value, new Tag({ name: tag })]
}
// If the tag was found, remove it
else {
newTags = filteredSelectedTags
}
await reflectChangesInUrl({ page: null, tags: newTags, filters: null })
await refreshInitialPosts()
}
Expand Down

0 comments on commit 8ace077

Please sign in to comment.