1
0
Fork 0
mirror of https://framagit.org/framasoft/mobilizon.git synced 2024-12-21 23:44:30 +00:00

Refactor TagInput.vue

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-09-07 17:52:56 +02:00
parent 291a788438
commit 9c7a4f0079
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773

View file

@ -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);
}
}
</script>