Migration to nuxt 4
Used codemods CLI and reworked most alias'd path that stopped working
This commit is contained in:
461
app/components/calendar/search/CalendarSearch.vue
Normal file
461
app/components/calendar/search/CalendarSearch.vue
Normal file
@@ -0,0 +1,461 @@
|
||||
<script lang="ts" setup>
|
||||
import {
|
||||
isCharacter,
|
||||
type Character,
|
||||
} from "@@/models/Characters"
|
||||
import type { RPGDateOrder } from "@@/models/Date"
|
||||
import {
|
||||
isCalendarEvent,
|
||||
type CalendarEvent,
|
||||
} from "@@/models/CalendarEvent"
|
||||
import { capitalize } from "~/utils/Strings"
|
||||
import { useMagicKeys, useScroll, useStorage, whenever } from "@vueuse/core"
|
||||
import { computed, ref, watch } from "vue"
|
||||
import { searchUnifier, type SearchMode } from "../SearchMode"
|
||||
|
||||
import { PhCaretDown, PhClockClockwise, PhClockCounterClockwise, PhMagnifyingGlass } from "@phosphor-icons/vue"
|
||||
import {
|
||||
ComboboxAnchor,
|
||||
ComboboxInput,
|
||||
ComboboxPortal,
|
||||
ComboboxRoot,
|
||||
ComboboxTrigger,
|
||||
VisuallyHidden
|
||||
} from "radix-vue"
|
||||
|
||||
import SearchList from "./lists/SearchList.vue"
|
||||
import type { Category } from "@@/models/Category"
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const { isAdvancedSearchOpen, allEvents, categories } = storeToRefs(useCalendar())
|
||||
const { characters } = storeToRefs(useCharacters())
|
||||
|
||||
const searchInput = shallowRef<HTMLInputElement>()
|
||||
useFocus(searchInput, { initialValue: true })
|
||||
|
||||
const searchQuery = ref<string>("")
|
||||
// const searchEnough = computed<boolean>(() => searchQuery.value.length >= 2)
|
||||
|
||||
// If the query changes, resets the pagination
|
||||
// This prevents active page to be greater than the search results
|
||||
watch(searchQuery, resetPage)
|
||||
|
||||
const selectedEntity = useStorage("se", "events" as SearchMode)
|
||||
|
||||
// Order
|
||||
const selectedOrder = ref<RPGDateOrder>("asc")
|
||||
function setOrderAsc() {
|
||||
selectedOrder.value = "asc"
|
||||
resetPage()
|
||||
}
|
||||
|
||||
function setOrderDesc() {
|
||||
selectedOrder.value = "desc"
|
||||
resetPage()
|
||||
}
|
||||
|
||||
// Limit
|
||||
const currentPage = ref<number>(1)
|
||||
const itemsPerPage: number = 20
|
||||
const startOfList = computed<number>(() => (currentPage.value - 1) * itemsPerPage)
|
||||
const endOfList = computed<number>(() => startOfList.value + itemsPerPage)
|
||||
|
||||
/**
|
||||
* Resets the pagination
|
||||
*/
|
||||
function resetPage() {
|
||||
currentPage.value = 1
|
||||
}
|
||||
|
||||
const searchResults = computed<(Character | CalendarEvent)[]>(() => {
|
||||
let results: (Character | CalendarEvent)[] = []
|
||||
let dataToFilter: Character[] | CalendarEvent[] | (Character | CalendarEvent)[]
|
||||
const shouldFilterCategories = selectedCategories.value.length > 0
|
||||
|
||||
// Assign data to loop over and filter
|
||||
// They are assigned this way for readability
|
||||
if (selectedEntity.value === "events") {
|
||||
dataToFilter = allEvents.value
|
||||
} else if (selectedEntity.value === "characters") {
|
||||
dataToFilter = characters.value
|
||||
} else {
|
||||
dataToFilter = [...allEvents.value, ...characters.value]
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Refactor the categories logic, basically extract the return out of the ifs, like above
|
||||
*/
|
||||
results = dataToFilter.filter((item) => {
|
||||
// Filter calendar events
|
||||
if (isCalendarEvent(item)) {
|
||||
const queryString = (searchQuery.value as string)
|
||||
.replace(searchUnifier, "")
|
||||
.toLocaleLowerCase()
|
||||
|
||||
const hitTitle = item.title
|
||||
.replace(searchUnifier, "")
|
||||
.toLocaleLowerCase()
|
||||
.includes(queryString)
|
||||
const hitDesc = item.description
|
||||
?.replace(searchUnifier, "")
|
||||
.toLocaleLowerCase()
|
||||
.includes(queryString)
|
||||
|
||||
if (!shouldFilterCategories) {
|
||||
return hitTitle || hitDesc
|
||||
}
|
||||
|
||||
// Handle categories logic
|
||||
let hitCategories: boolean = false
|
||||
const allCategories: Category[] = []
|
||||
|
||||
if (item.category) {
|
||||
allCategories.push(item.category)
|
||||
}
|
||||
|
||||
if (item.secondaryCategories && item.secondaryCategories?.length > 0) {
|
||||
allCategories.push(...item.secondaryCategories)
|
||||
}
|
||||
|
||||
hitCategories = selectedCategories.value.every((selectedCat) => {
|
||||
return allCategories.findIndex((c) => c.name === selectedCat.name) !== -1
|
||||
})
|
||||
|
||||
return (hitTitle || hitDesc) && hitCategories
|
||||
}
|
||||
|
||||
// Filter characters
|
||||
if (isCharacter(item)) {
|
||||
const queryString = (searchQuery.value as string)
|
||||
.replace(searchUnifier, "")
|
||||
.toLocaleLowerCase()
|
||||
|
||||
const hitTitle = item.name
|
||||
.replace(searchUnifier, "")
|
||||
.toLocaleLowerCase()
|
||||
.includes(queryString)
|
||||
|
||||
if (!shouldFilterCategories) {
|
||||
return hitTitle
|
||||
}
|
||||
|
||||
// Handle categories logic
|
||||
let hitCategories: boolean = false
|
||||
const allCategories: Category[] = []
|
||||
|
||||
if (item.category) {
|
||||
allCategories.push(item.category)
|
||||
}
|
||||
|
||||
if (item.secondaryCategories && item.secondaryCategories?.length > 0) {
|
||||
allCategories.push(...item.secondaryCategories)
|
||||
}
|
||||
|
||||
hitCategories = selectedCategories.value.every((selectedCat) => {
|
||||
return allCategories.includes(selectedCat as Category)
|
||||
})
|
||||
|
||||
return hitTitle && hitCategories
|
||||
}
|
||||
})
|
||||
|
||||
return results
|
||||
})
|
||||
|
||||
/**
|
||||
* Removes the search query, resets the pagination and removes all selected categories
|
||||
*/
|
||||
function resetSearch() {
|
||||
searchQuery.value = ""
|
||||
resetPage()
|
||||
selectedCategories.value = []
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the search Uidialog
|
||||
*/
|
||||
function openUiDialog() {
|
||||
isAdvancedSearchOpen.value = true
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the search Uidialog
|
||||
*/
|
||||
function closeUiDialog() {
|
||||
isAdvancedSearchOpen.value = false
|
||||
}
|
||||
|
||||
/**
|
||||
* Switches the selectedEntity
|
||||
*/
|
||||
function handleEntitySwitch() {
|
||||
resetPage()
|
||||
selectedCategories.value = []
|
||||
}
|
||||
|
||||
// Key combos to deploy modal
|
||||
const keys = useMagicKeys()
|
||||
|
||||
whenever(keys.control_period, () => {
|
||||
openUiDialog()
|
||||
})
|
||||
|
||||
const searchResultsRef = ref<HTMLElement | null>(null)
|
||||
const { y: searchResultsY } = useScroll(searchResultsRef)
|
||||
|
||||
watch([currentPage, selectedEntity], () => {
|
||||
searchResultsY.value = 0
|
||||
})
|
||||
|
||||
// Compute categories based on current selectedEntity
|
||||
const currentCategories = computed(() => categories.value)
|
||||
|
||||
const selectedCategories = ref<(Category)[]>([])
|
||||
const categoryFilterOpened = ref<boolean>(false)
|
||||
const searchCategory = ref<string>("")
|
||||
|
||||
const filteredCategories = computed(() => {
|
||||
// Display original data
|
||||
if (!currentCategories.value) return []
|
||||
|
||||
// If current categories are selected, ignore them
|
||||
if (!searchCategory.value) return currentCategories.value.filter((i) => !selectedCategories.value.includes(i))
|
||||
|
||||
// If we also have a query to filter them by, do that
|
||||
return currentCategories.value.filter((i) => {
|
||||
return !selectedCategories.value.includes(i) && i.name.toLocaleLowerCase().includes(searchCategory.value.toLocaleLowerCase())
|
||||
})
|
||||
})
|
||||
|
||||
// Reactivity rules for category searches
|
||||
const categoryInput = ref(null)
|
||||
const categoryInputValue = ref<string>("")
|
||||
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) {
|
||||
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
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<UiDialog v-model:open="isAdvancedSearchOpen" @update:open="resetSearch()">
|
||||
<UiDialogContent
|
||||
class="flex flex-col flex-nowrap top-10 -translate-y-0 data-[state=closed]:slide-out-to-top-[5%] data-[state=open]:slide-in-from-top-[5%] max-md:rounded-none"
|
||||
:class="cn({
|
||||
'max-md:w-full bottom-0 md:bottom-10 top-0 md:top-10': searchResults.length > 0
|
||||
})"
|
||||
>
|
||||
<VisuallyHidden>
|
||||
<UiDialogTitle> {{ $t('entity.advancedSearch.title') }} </UiDialogTitle>
|
||||
</VisuallyHidden>
|
||||
<VisuallyHidden>
|
||||
<UiDialogDescription>
|
||||
{{ $t('entity.advancedSearch.title') }}
|
||||
</UiDialogDescription>
|
||||
</VisuallyHidden>
|
||||
|
||||
<div id="searchForm" class="grid gap-3">
|
||||
<div class="relative w-full h-fit">
|
||||
<UiInput
|
||||
id="search"
|
||||
ref="searchInput"
|
||||
v-model:model-value="searchQuery"
|
||||
type="text"
|
||||
:placeholder="$t('entity.advancedSearch.ctaPlaceholder')"
|
||||
class="pl-10 py-6 text-lg"
|
||||
autocomplete="off"
|
||||
/>
|
||||
<span class="absolute start-1 inset-y-0 flex items-center justify-center px-2 opacity-50">
|
||||
<PhMagnifyingGlass size="20" />
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center justify-between gap-8">
|
||||
<div class="hidden">
|
||||
<UiToggleGroup
|
||||
v-model="selectedEntity"
|
||||
type="single"
|
||||
class="justify-start"
|
||||
@update:model-value="handleEntitySwitch()"
|
||||
>
|
||||
<UiToggleGroupItem value="events" aria-label="Uniquement les évènements">
|
||||
{{ $t('entity.calendar.event.namePlural') }}
|
||||
</UiToggleGroupItem>
|
||||
</UiToggleGroup>
|
||||
</div>
|
||||
|
||||
<div class="grow flex justify-end items-center gap-1">
|
||||
<UiTagsInput class="grow px-0 gap-y-1 md:w-80">
|
||||
<div v-if="selectedCategories.length > 0" class="flex gap-2 flex-wrap items-center px-3">
|
||||
<UiTagsInputItem v-for="cat in selectedCategories" :key="cat.id" :value="cat.name">
|
||||
<button
|
||||
class="bgc px-2 capitalize cursor-pointer"
|
||||
:class="cn(`element-${cat.color}`)"
|
||||
@click="handleCategoryUnselect(cat)"
|
||||
>
|
||||
{{ capitalize(cat.name) }}
|
||||
</button>
|
||||
</UiTagsInputItem>
|
||||
</div>
|
||||
|
||||
<ComboboxRoot
|
||||
v-model="selectedCategories"
|
||||
v-model:open="categoryFilterOpened"
|
||||
v-model:search-term="searchCategory"
|
||||
class="grow flex items-center gap-y-1 pr-2"
|
||||
>
|
||||
<ComboboxAnchor as-child>
|
||||
<ComboboxInput :placeholder="$t('entity.category.namePlural')" as-child>
|
||||
<UiTagsInputInput
|
||||
ref="categoryInput"
|
||||
v-model="categoryInputValue"
|
||||
class="min-w-16 px-3"
|
||||
@keydown.enter.prevent
|
||||
/>
|
||||
</ComboboxInput>
|
||||
</ComboboxAnchor>
|
||||
|
||||
<ComboboxTrigger>
|
||||
<PhCaretDown size="16" />
|
||||
</ComboboxTrigger>
|
||||
|
||||
<ComboboxPortal :to="'#searchForm'">
|
||||
<UiCommandList
|
||||
position="popper"
|
||||
class="w-(--radix-popper-anchor-width) rounded-md mt-2 border bg-popover text-popover-foreground shadow-md outline-hidden data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50"
|
||||
:dismissable="true"
|
||||
>
|
||||
<UiCommandEmpty />
|
||||
<UiCommandGroup>
|
||||
<UiCommandItem
|
||||
v-for="cat in filteredCategories"
|
||||
:key="cat.name"
|
||||
:value="cat"
|
||||
@select.prevent="handleCategorySelect(cat)"
|
||||
>
|
||||
<span
|
||||
class="bgc"
|
||||
:class="cn(`element-${cat.color}`)"
|
||||
>
|
||||
{{ capitalize(cat.name) }}
|
||||
</span>
|
||||
</UiCommandItem>
|
||||
</UiCommandGroup>
|
||||
</UiCommandList>
|
||||
</ComboboxPortal>
|
||||
</ComboboxRoot>
|
||||
</UiTagsInput>
|
||||
|
||||
<UiTooltipProvider :delay-duration="250">
|
||||
<UiTooltip>
|
||||
<UiTooltipTrigger as-child>
|
||||
<UiButton
|
||||
:variant="selectedOrder === 'desc' ? 'secondary' : 'outline'"
|
||||
size="icon"
|
||||
@click="setOrderDesc()"
|
||||
>
|
||||
<PhClockCounterClockwise size="18" />
|
||||
</UiButton>
|
||||
</UiTooltipTrigger>
|
||||
<UiTooltipContent>
|
||||
<p>{{ $t('entity.advancedSearch.older') }}</p>
|
||||
</UiTooltipContent>
|
||||
</UiTooltip>
|
||||
</UiTooltipProvider>
|
||||
|
||||
<UiTooltipProvider :delay-duration="250">
|
||||
<UiTooltip>
|
||||
<UiTooltipTrigger as-child>
|
||||
<UiButton
|
||||
:variant="selectedOrder === 'asc' ? 'secondary' : 'outline'"
|
||||
size="icon"
|
||||
@click="setOrderAsc()"
|
||||
>
|
||||
<PhClockClockwise size="18" />
|
||||
</UiButton>
|
||||
</UiTooltipTrigger>
|
||||
<UiTooltipContent>
|
||||
<p>{{ $t('entity.advancedSearch.newer') }}</p>
|
||||
</UiTooltipContent>
|
||||
</UiTooltip>
|
||||
</UiTooltipProvider>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<div v-if="searchResults.length > 0" ref="searchResultsRef" class="grow overflow-y-auto">
|
||||
<SearchList
|
||||
:results="searchResults"
|
||||
:current-entity="selectedEntity"
|
||||
:order="selectedOrder"
|
||||
:start-at="startOfList"
|
||||
:end-at="endOfList"
|
||||
@jumped-to-date="closeUiDialog()"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end">
|
||||
<UiPagination
|
||||
v-model:page="currentPage"
|
||||
:total="searchResults.length"
|
||||
:items-per-page="itemsPerPage"
|
||||
:sibling-count="2"
|
||||
show-edges
|
||||
:default-page="1"
|
||||
>
|
||||
<UiPaginationList v-slot="{ items }" class="flex items-center gap-1">
|
||||
<UiPaginationFirst />
|
||||
<UiPaginationPrev />
|
||||
|
||||
<template v-for="(item, index) in items">
|
||||
<UiPaginationListItem
|
||||
v-if="item.type === 'page'"
|
||||
:key="index"
|
||||
:value="item.value"
|
||||
as-child
|
||||
>
|
||||
<UiButton
|
||||
class="size-8 md:size-10 p-0"
|
||||
:variant="item.value === currentPage ? 'default' : 'outline'"
|
||||
>
|
||||
{{ item.value }}
|
||||
</UiButton>
|
||||
</UiPaginationListItem>
|
||||
<UiPaginationEllipsis v-else :key="item.type" :index="index" />
|
||||
</template>
|
||||
|
||||
<UiPaginationNext />
|
||||
<UiPaginationLast />
|
||||
</UiPaginationList>
|
||||
</UiPagination>
|
||||
</div>
|
||||
</UiDialogContent>
|
||||
</UiDialog>
|
||||
</template>
|
||||
91
app/components/calendar/search/lists/CharacterCallout.vue
Normal file
91
app/components/calendar/search/lists/CharacterCallout.vue
Normal file
@@ -0,0 +1,91 @@
|
||||
<script lang="ts" setup>
|
||||
import type { Character } from "@@/models/Characters"
|
||||
import type { RPGDate } from "@@/models/Date"
|
||||
import { useCalendar } from "@/stores/CalendarStore"
|
||||
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "~/components/ui/tooltip"
|
||||
import { Button } from "~/components/ui/button"
|
||||
import { PhArrowSquareOut, PhPlant, PhSkull } from "@phosphor-icons/vue"
|
||||
|
||||
const props = defineProps<{
|
||||
character: Character
|
||||
}>()
|
||||
|
||||
defineEmits<{
|
||||
"query:date-jump": [payload: RPGDate]
|
||||
}>()
|
||||
|
||||
const { getFormattedDateTitle } = useCalendar()
|
||||
|
||||
console.log(props.character.birth)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="block w-full text-left py-3 px-4 border-[1px] border-border rounded-sm">
|
||||
<div class="grid gap-2">
|
||||
<div class="flex gap-2">
|
||||
<h2 class="font-bold">
|
||||
{{ character.name }}
|
||||
</h2>
|
||||
<div v-if="character.wiki">
|
||||
<Button variant="link" size="xs" as-child>
|
||||
<a :href="character.wiki" target="_blank">
|
||||
Wiki
|
||||
<PhArrowSquareOut size="16" weight="fill" />
|
||||
</a>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<menu class="flex gap-2 border-[1px] border-border rounded-sm w-fit">
|
||||
<li v-if="character.birth">
|
||||
<TooltipProvider :delay-duration="100">
|
||||
<Tooltip>
|
||||
<TooltipTrigger as-child>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="xs"
|
||||
@click="$emit('query:date-jump', character.birth!)"
|
||||
>
|
||||
<PhPlant size="16" weight="fill" />
|
||||
{{ getFormattedDateTitle(character.birth, true) }}
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent :side="'bottom'" :align="'end'" :align-offset="20">
|
||||
<p>Date de naissance</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
</li>
|
||||
<span v-if="character.birth && character.death">-</span>
|
||||
<li v-if="character.death">
|
||||
<TooltipProvider :delay-duration="100">
|
||||
<Tooltip>
|
||||
<TooltipTrigger as-child>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="xs"
|
||||
@click="$emit('query:date-jump', character.death!)"
|
||||
>
|
||||
<PhSkull size="16" weight="fill" />
|
||||
{{ getFormattedDateTitle(character.death, true) }}
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent :side="'bottom'" :align="'start'" :align-offset="20">
|
||||
<p>Date de décès</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
</li>
|
||||
</menu>
|
||||
|
||||
<hr v-if="character.description" class="border-white opacity-25" >
|
||||
|
||||
<div v-if="character.description" class="text-sm">
|
||||
<span class="opacity-75">
|
||||
{{ character.description }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
121
app/components/calendar/search/lists/EventCallout.vue
Normal file
121
app/components/calendar/search/lists/EventCallout.vue
Normal file
@@ -0,0 +1,121 @@
|
||||
<script lang="ts" setup>
|
||||
import { cn } from "@/lib/utils"
|
||||
import type { RPGDate } from "@@/models/Date"
|
||||
import type { CalendarEvent } from "@@/models/CalendarEvent"
|
||||
|
||||
import { PhArrowSquareOut, PhHourglassMedium, PhAlarm, PhMapPinArea, PhEye } from "@phosphor-icons/vue"
|
||||
|
||||
const props = defineProps<{
|
||||
event: CalendarEvent
|
||||
}>()
|
||||
|
||||
defineEmits<{
|
||||
"query:date-jump": [payload: RPGDate]
|
||||
}>()
|
||||
|
||||
const { getRelativeString, defaultDate, getFormattedDateTitle } = useCalendar()
|
||||
|
||||
const dateDifference: string = getRelativeString(defaultDate, props.event.startDate)
|
||||
const dateDuration = computed<string | null>(() => props.event.endDate ? getRelativeString(props.event.startDate, props.event.endDate, "compact") : null)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<button
|
||||
class="event-callout group relative block w-full text-left py-2 px-3 md:py-3 md:px-4 cursor-pointer transition-colors"
|
||||
:class="cn(
|
||||
event.category ? `element-${event.category.color}` : '',
|
||||
{
|
||||
'pt-4 is-hidden': event.hidden,
|
||||
})"
|
||||
@click="$emit('query:date-jump', event.startDate)"
|
||||
>
|
||||
<div class="flex gap-2 items-center mb-1">
|
||||
<h2 class="font-semibold md:font-bold md:text-lg underline-offset-4 group-hover:underline">
|
||||
{{ event.title }}
|
||||
</h2>
|
||||
<div v-if="event.wiki">
|
||||
<UiButton variant="link" size="xs" as-child class="text-inherit">
|
||||
<a :href="event.wiki" target="_blank">
|
||||
Wiki
|
||||
<PhArrowSquareOut size="16" weight="fill" />
|
||||
</a>
|
||||
</UiButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-2 items-center justify-between mb-2 md:mb-1">
|
||||
<template v-if="!event.endDate">
|
||||
<p class="font-semibold text-sm opacity-75">
|
||||
{{ getFormattedDateTitle(event.startDate, true) }}
|
||||
</p>
|
||||
</template>
|
||||
<template v-else>
|
||||
<p class="font-semibold text-sm opacity-75">
|
||||
{{
|
||||
$t('entity.calendar.date.fromTo',
|
||||
{
|
||||
startDate: getFormattedDateTitle(event.startDate, true),
|
||||
endDate: getFormattedDateTitle(event.endDate, true)
|
||||
}
|
||||
)
|
||||
}}
|
||||
</p>
|
||||
</template>
|
||||
<div v-if="event.hidden" class="flex justify-end">
|
||||
<UiTooltipProvider :delay-duration="250">
|
||||
<UiTooltip>
|
||||
<UiTooltipTrigger as-child>
|
||||
<UiBadge class="flex gap-1">
|
||||
<PhEye size="16" weight="fill" /> {{ $t('entity.calendar.event.isHidden') }}
|
||||
</UiBadge>
|
||||
</UiTooltipTrigger>
|
||||
<UiTooltipContent>
|
||||
<p>
|
||||
{{ $t('entity.calendar.event.hiddenTooltip') }}
|
||||
</p>
|
||||
</UiTooltipContent>
|
||||
</UiTooltip>
|
||||
</UiTooltipProvider>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-1 flex gap-x-2 items-center">
|
||||
<template v-if="event.location">
|
||||
<p class="w-fit text-xs md:text-sm italic opacity-75 flex items-center gap-1">
|
||||
<PhMapPinArea size="16" weight="fill" /> {{ event.location }}
|
||||
</p>
|
||||
</template>
|
||||
<p class="w-fit text-xs md:text-sm italic opacity-75 flex items-center gap-1">
|
||||
<PhAlarm size="16" weight="fill" /> {{ dateDifference }}
|
||||
</p>
|
||||
<template v-if="dateDuration">
|
||||
<p class="w-fit text-xs md:text-sm italic opacity-75 flex items-center gap-1">
|
||||
<PhHourglassMedium size="16" weight="fill" /> {{ $t('entity.calendar.date.while', { duration: dateDuration } )}}
|
||||
</p>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<div v-if="event.category || event.secondaryCategories" class="absolute top-3 right-4">
|
||||
<ul class="flex gap-1">
|
||||
<li v-if="event.category">
|
||||
<UiBadge class="mix-blend-luminosity font-bold bg-gray-300 hover:bg-gray-200 dark:bg-gray-800 dark:hover:bg-gray-600 lowercase" variant="secondary">
|
||||
{{ event.category?.name }}
|
||||
</UiBadge>
|
||||
</li>
|
||||
|
||||
<li v-for="cat in event.secondaryCategories" :key="cat.id">
|
||||
<UiBadge class="mix-blend-luminosity bg-gray-300 hover:bg-gray-200 dark:bg-gray-800 dark:hover:bg-gray-600 lowercase" variant="secondary">
|
||||
{{ cat.name }}
|
||||
</UiBadge>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div v-if="event.description" class="text-xs md:text-sm">
|
||||
<hr class="my-3 md:my-2 border-white opacity-50" >
|
||||
<span class="opacity-75">
|
||||
{{ event.description }}
|
||||
</span>
|
||||
</div>
|
||||
</button>
|
||||
</template>
|
||||
74
app/components/calendar/search/lists/SearchList.vue
Normal file
74
app/components/calendar/search/lists/SearchList.vue
Normal file
@@ -0,0 +1,74 @@
|
||||
<script lang="ts" setup>
|
||||
import { isCharacter, type Character } from "@@/models/Characters"
|
||||
import type { RPGDate, RPGDateOrder } from "@@/models/Date"
|
||||
import { useCalendar } from "@/stores/CalendarStore"
|
||||
import { computed } from "vue"
|
||||
import { isCalendarEvent, type CalendarEvent } from "@@/models/CalendarEvent"
|
||||
import type { SearchMode } from "../../SearchMode"
|
||||
|
||||
import CharacterCallout from "./CharacterCallout.vue"
|
||||
import EventCallout from "./EventCallout.vue"
|
||||
|
||||
const props = defineProps<{
|
||||
results: (Character | CalendarEvent)[]
|
||||
currentEntity: SearchMode
|
||||
order: RPGDateOrder
|
||||
startAt: number
|
||||
endAt: number
|
||||
limit?: number
|
||||
}>()
|
||||
|
||||
const emit = defineEmits(["jumpedToDate"])
|
||||
|
||||
const { jumpToDate, compareDates } = useCalendar()
|
||||
|
||||
function handleJumpToDate(date?: RPGDate) {
|
||||
if (!date) return
|
||||
|
||||
jumpToDate(date)
|
||||
emit("jumpedToDate")
|
||||
}
|
||||
|
||||
// Initial sorting of the results
|
||||
const sortedResults = computed(() => {
|
||||
return [...props.results].sort((a, b) => {
|
||||
let firstDate: RPGDate
|
||||
let secondDate: RPGDate
|
||||
|
||||
if (isCalendarEvent(a)) {
|
||||
firstDate = a.startDate
|
||||
} else if (isCharacter(a) && a.birth) {
|
||||
firstDate = a.birth
|
||||
} else {
|
||||
return 1
|
||||
}
|
||||
|
||||
if (isCalendarEvent(b)) {
|
||||
secondDate = b.startDate
|
||||
} else if (isCharacter(b) && b.birth) {
|
||||
secondDate = b.birth
|
||||
} else {
|
||||
return -1
|
||||
}
|
||||
|
||||
return compareDates(firstDate, secondDate, props.order)
|
||||
})
|
||||
})
|
||||
|
||||
// Page the sorted results
|
||||
const pagedResults = computed(() => sortedResults.value.slice(props.startAt, props.endAt))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ul class="grid gap-3 md:gap-4 pl-4 pr-6 md:pl-8 md:pr-12">
|
||||
<li v-for="r in pagedResults" :key="isCalendarEvent(r) ? r.title : r.name">
|
||||
<EventCallout v-if="isCalendarEvent(r)" :event="r" @query:date-jump="handleJumpToDate" />
|
||||
|
||||
<CharacterCallout
|
||||
v-else-if="isCharacter(r)"
|
||||
:character="r"
|
||||
@query:date-jump="handleJumpToDate"
|
||||
/>
|
||||
</li>
|
||||
</ul>
|
||||
</template>
|
||||
Reference in New Issue
Block a user