Cleaned / JSDoc for calendar search
This commit is contained in:
@@ -1,33 +1,27 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import {
|
import {
|
||||||
|
characterCategories,
|
||||||
isCharacter,
|
isCharacter,
|
||||||
type Character,
|
type Character,
|
||||||
characterCategories,
|
|
||||||
type CharacterCategory
|
type CharacterCategory
|
||||||
} from '@/models/Characters'
|
} from '@/models/Characters'
|
||||||
import type { LeimDateOrder } from '@/models/Date'
|
import type { LeimDateOrder } from '@/models/Date'
|
||||||
import {
|
import {
|
||||||
|
calendarEventCategories,
|
||||||
isCalendarEvent,
|
isCalendarEvent,
|
||||||
type CalendarEvent,
|
type CalendarEvent,
|
||||||
calendarEventCategories,
|
|
||||||
type CalendarEventCategory
|
type CalendarEventCategory
|
||||||
} from '@/models/Events'
|
} from '@/models/Events'
|
||||||
import { capitalize } from '@/utils/Strings'
|
|
||||||
import { useCharacters } from '@/stores/CharacterStore'
|
import { useCharacters } from '@/stores/CharacterStore'
|
||||||
import { useCalendarEvents } from '@/stores/EventStore'
|
import { useCalendarEvents } from '@/stores/EventStore'
|
||||||
|
import { capitalize } from '@/utils/Strings'
|
||||||
import { useMagicKeys, useStorage, whenever } from '@vueuse/core'
|
import { useMagicKeys, useStorage, whenever } from '@vueuse/core'
|
||||||
import { computed, ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import { searchUnifier, type SearchMode } from '../Search'
|
import { searchUnifier, type SearchMode } from '../Search'
|
||||||
|
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { CommandEmpty, CommandGroup, CommandItem, CommandList } from '@/components/ui/command'
|
import { CommandEmpty, CommandGroup, CommandItem, CommandList } from '@/components/ui/command'
|
||||||
import {
|
import { Dialog, DialogContent, DialogDescription, DialogTitle } from '@/components/ui/dialog'
|
||||||
Dialog,
|
|
||||||
DialogContent,
|
|
||||||
DialogDescription,
|
|
||||||
DialogTitle,
|
|
||||||
DialogTrigger
|
|
||||||
} from '@/components/ui/dialog'
|
|
||||||
import { Input } from '@/components/ui/input'
|
import { Input } from '@/components/ui/input'
|
||||||
import {
|
import {
|
||||||
Pagination,
|
Pagination,
|
||||||
@@ -87,6 +81,9 @@ const itemsPerPage: number = 20
|
|||||||
const startOfList = computed<number>(() => (currentPage.value - 1) * itemsPerPage)
|
const startOfList = computed<number>(() => (currentPage.value - 1) * itemsPerPage)
|
||||||
const endOfList = computed<number>(() => startOfList.value + itemsPerPage)
|
const endOfList = computed<number>(() => startOfList.value + itemsPerPage)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets the pagination
|
||||||
|
*/
|
||||||
function resetPage() {
|
function resetPage() {
|
||||||
currentPage.value = 1
|
currentPage.value = 1
|
||||||
}
|
}
|
||||||
@@ -186,20 +183,32 @@ const searchResults = computed<(Character | CalendarEvent)[]>(() => {
|
|||||||
return results
|
return results
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the search query, resets the pagination and removes all selected categories
|
||||||
|
*/
|
||||||
function resetSearch() {
|
function resetSearch() {
|
||||||
searchQuery.value = ''
|
searchQuery.value = ''
|
||||||
resetPage()
|
resetPage()
|
||||||
selectedCategories.value = []
|
selectedCategories.value = []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens the search dialog
|
||||||
|
*/
|
||||||
function openDialog() {
|
function openDialog() {
|
||||||
modalOpen.value = true
|
modalOpen.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the search dialog
|
||||||
|
*/
|
||||||
function closeDialog() {
|
function closeDialog() {
|
||||||
modalOpen.value = false
|
modalOpen.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Switches the selectedEntity
|
||||||
|
*/
|
||||||
function handleEntitySwitch() {
|
function handleEntitySwitch() {
|
||||||
resetPage()
|
resetPage()
|
||||||
selectedCategories.value = []
|
selectedCategories.value = []
|
||||||
@@ -212,7 +221,7 @@ whenever(keys.control_period, () => {
|
|||||||
openDialog()
|
openDialog()
|
||||||
})
|
})
|
||||||
|
|
||||||
// Categories
|
// Compute categories based on current selectedEntity
|
||||||
const currentCategories = computed(() => {
|
const currentCategories = computed(() => {
|
||||||
if (selectedEntity.value === 'characters') {
|
if (selectedEntity.value === 'characters') {
|
||||||
return [...characterCategories]
|
return [...characterCategories]
|
||||||
@@ -225,17 +234,22 @@ const selectedCategories = ref<(CharacterCategory | CalendarEventCategory)[]>([]
|
|||||||
const categoryFilterOpened = ref<boolean>(false)
|
const categoryFilterOpened = ref<boolean>(false)
|
||||||
const searchCategory = ref<string>('')
|
const searchCategory = ref<string>('')
|
||||||
|
|
||||||
const filteredFrameworks = computed(() =>
|
const filteredCategories = computed(() =>
|
||||||
currentCategories.value.filter((i) => !selectedCategories.value.includes(i))
|
currentCategories.value.filter((i) => !selectedCategories.value.includes(i))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the category selections from the TagInput component
|
||||||
|
*
|
||||||
|
* @param e Radix Change Event
|
||||||
|
*/
|
||||||
function handleCategorySelect(e: any) {
|
function handleCategorySelect(e: any) {
|
||||||
if (typeof e.detail.value === 'string') {
|
if (typeof e.detail.value === 'string') {
|
||||||
searchCategory.value = ''
|
searchCategory.value = ''
|
||||||
selectedCategories.value.push(e.detail.value)
|
selectedCategories.value.push(e.detail.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filteredFrameworks.value.length === 0) {
|
if (filteredCategories.value.length === 0) {
|
||||||
categoryFilterOpened.value = false
|
categoryFilterOpened.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -325,7 +339,7 @@ function handleCategorySelect(e: any) {
|
|||||||
<CommandEmpty />
|
<CommandEmpty />
|
||||||
<CommandGroup>
|
<CommandGroup>
|
||||||
<CommandItem
|
<CommandItem
|
||||||
v-for="framework in filteredFrameworks"
|
v-for="framework in filteredCategories"
|
||||||
:key="framework"
|
:key="framework"
|
||||||
:value="framework"
|
:value="framework"
|
||||||
@select.prevent="handleCategorySelect"
|
@select.prevent="handleCategorySelect"
|
||||||
|
|||||||
Reference in New Issue
Block a user