diff --git a/components/calendar/search/CalendarSearch.vue b/components/calendar/search/CalendarSearch.vue index 63c37ea..26682cf 100644 --- a/components/calendar/search/CalendarSearch.vue +++ b/components/calendar/search/CalendarSearch.vue @@ -13,12 +13,13 @@ import { useMagicKeys, useScroll, useStorage, whenever } from "@vueuse/core" import { computed, ref, watch } from "vue" import { searchUnifier, type SearchMode } from "../SearchMode" -import { PhClockClockwise, PhClockCounterClockwise, PhMagnifyingGlass } from "@phosphor-icons/vue" +import { PhCaretDown, PhClockClockwise, PhClockCounterClockwise, PhMagnifyingGlass } from "@phosphor-icons/vue" import { ComboboxAnchor, ComboboxInput, ComboboxPortal, ComboboxRoot, + ComboboxTrigger, VisuallyHidden } from "radix-vue" @@ -113,7 +114,7 @@ const searchResults = computed<(Character | CalendarEvent)[]>(() => { } hitCategories = selectedCategories.value.every((selectedCat) => { - return allCategories.includes(selectedCat as Category) + return allCategories.findIndex((c) => c.name === selectedCat.name) !== -1 }) return (hitTitle || hitDesc) && hitCategories @@ -203,28 +204,44 @@ watch([currentPage, selectedEntity], () => { }) // Compute categories based on current selectedEntity -const currentCategories = computed(() => { - return [] -}) +const { data: resCategories } = await useFetch("/api/calendars/categories/query") +const currentCategories = ref(resCategories.value?.data as Category[]) const selectedCategories = ref<(Category)[]>([]) const categoryFilterOpened = ref(false) const searchCategory = ref("") -const filteredCategories = computed(() => - currentCategories.value.filter((i) => !selectedCategories.value.includes(i)) -) +const filteredCategories = computed(() => { + if (!currentCategories.value) return [] + return currentCategories.value.filter((i) => !selectedCategories.value.includes(i)) +}) + +const categoryInput = ref(null) +const { focused: categoryInputFocused } = useFocus(categoryInput) + +watch(categoryInputFocused, (isFocused) => { + categoryFilterOpened.value = isFocused +}) /** * Handles the category selections from the TagInput component * * @param e Radix Change Event */ -function handleCategorySelect(e: (Category)) { - if (typeof e === "string") { - searchCategory.value = "" - selectedCategories.value.push(e) +function handleCategorySelect(e: Category) { + searchCategory.value = "" + selectedCategories.value.push(e) + + if (filteredCategories.value.length === 0) { + categoryFilterOpened.value = false } +} + +/** + * Removes a category from selection from the TagInput component + */ +function handleCategoryUnselect(e: Category) { + selectedCategories.value.splice(selectedCategories.value.findIndex(sc => sc.name === e.name), 1) if (filteredCategories.value.length === 0) { categoryFilterOpened.value = false @@ -265,7 +282,7 @@ function handleCategorySelect(e: (Category)) { -
+
{{ $t('entity.calendar.event.namePlural') }} - + +
-
- -
+
+ +
- - +
@@ -295,18 +312,22 @@ function handleCategorySelect(e: (Category)) { v-model="selectedCategories" v-model:open="categoryFilterOpened" v-model:searchTerm="searchCategory" - class="w-full" + class="grow flex items-center gap-y-1 pr-2" > + + + + - {{ capitalize(cat) }} + {{ capitalize(cat.name) }}