From 23365d632409e933d95a72705e404a0b0f3f6c6b Mon Sep 17 00:00:00 2001 From: Alexis <35.alexis.pele@gmail.com> Date: Tue, 11 Jun 2024 17:51:50 +0200 Subject: [PATCH] Added filtering of categories --- components/calendar/input/EventCategories.vue | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/components/calendar/input/EventCategories.vue b/components/calendar/input/EventCategories.vue index 5042005..cdd60e1 100644 --- a/components/calendar/input/EventCategories.vue +++ b/components/calendar/input/EventCategories.vue @@ -2,23 +2,13 @@ import { PhCaretDown } from '@phosphor-icons/vue'; import type { Category } from '~/models/Category'; +const isPopoverOpen = ref(false) + const props = defineProps<{ placeholder?: string multiple?: boolean }>() -const model = defineModel() - -const { categories: availableCategories } = useCalendarEvents() - -const isPopoverOpen = ref(false) - -function handleCatSelect() { - if (!props.multiple) { - isPopoverOpen.value = false - } -} - const computedTextValue = computed(() => { if (model.value) { if ("name" in model.value) { @@ -30,6 +20,26 @@ const computedTextValue = computed(() => { return props.placeholder } }) + +const model = defineModel() + +const { categories: availableCategories } = useCalendarEvents() + +const searchTerm = ref('') + +function handleCatSelect() { + if (!props.multiple) { + isPopoverOpen.value = false + } +} + +const filteredCategories = computed(() => + searchTerm.value === '' + ? availableCategories + : availableCategories.filter((category) => { + return category.name.toLowerCase().includes(searchTerm.value.toLowerCase()) + }) +)