From 9c7a4f007991c2ad28f484acac8d35d79cf7784e Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 7 Sep 2021 17:52:56 +0200 Subject: [PATCH] Refactor TagInput.vue Signed-off-by: Thomas Citharel --- js/src/components/Event/TagInput.vue | 33 +++++++++++++--------------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/js/src/components/Event/TagInput.vue b/js/src/components/Event/TagInput.vue index fcca0be4c..6537e50b8 100644 --- a/js/src/components/Event/TagInput.vue +++ b/js/src/components/Event/TagInput.vue @@ -33,24 +33,7 @@ import get from "lodash/get"; import differenceBy from "lodash/differenceBy"; import { ITag } from "../../types/tag.model"; -@Component({ - computed: { - tagsStrings: { - get() { - return this.$props.value.map((tag: ITag) => tag.title); - }, - set(tagStrings) { - const tagEntities = tagStrings.map((tag: string | ITag) => { - if (typeof tag !== "string") { - return tag; - } - return { title: tag, slug: tag } as ITag; - }); - this.$emit("input", tagEntities); - }, - }, - }, -}) +@Component export default class TagInput extends Vue { @Prop({ required: false, default: () => [] }) data!: ITag[]; @@ -79,5 +62,19 @@ export default class TagInput extends Vue { .indexOf(text.toLowerCase()) >= 0 ); } + + get tagsStrings(): string[] { + return (this.value || []).map((tag: ITag) => tag.title); + } + + set tagsStrings(tagsStrings: string[]) { + const tagEntities = tagsStrings.map((tag: string | ITag) => { + if (typeof tag !== "string") { + return tag; + } + return { title: tag, slug: tag } as ITag; + }); + this.$emit("input", tagEntities); + } }