Added character list in search
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<script lang="ts" setup>
|
||||
import { Popover, PopoverTrigger } from '@/components/ui/popover'
|
||||
import type { CalendarEvent } from '@/stores/events'
|
||||
import type { CalendarEvent } from '@/models/Events'
|
||||
import CalendarEventDetails from './CalendarEventDetails.vue'
|
||||
|
||||
defineProps<{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts" setup>
|
||||
import { PopoverContent } from '@/components/ui/popover'
|
||||
import type { CalendarEvent } from '@/models/Events'
|
||||
import { useCalendar } from '@/stores/calendar'
|
||||
import type { CalendarEvent } from '@/stores/events'
|
||||
|
||||
const { getFormattedDateTitle } = useCalendar()
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useCalendar } from '@/stores/calendar'
|
||||
import CalendarMenuToday from './CalendarMenuToday.vue'
|
||||
import CalendarMenuNav from './CalendarMenuNav.vue'
|
||||
import CalendarSwitch from './CalendarSwitch.vue'
|
||||
import CalendarMenuSearch from './CalendarMenuSearch.vue'
|
||||
import CalendarSearch from './search/CalendarSearch.vue'
|
||||
|
||||
const { currentDate } = useCalendar()
|
||||
</script>
|
||||
@@ -31,7 +31,7 @@ const { currentDate } = useCalendar()
|
||||
</div>
|
||||
</div>
|
||||
<div class="md:col-span-3 flex justify-end">
|
||||
<CalendarMenuSearch />
|
||||
<CalendarSearch />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
<script lang="ts" setup>
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
|
||||
import { useCalendar } from '@/stores/calendar'
|
||||
import Button from '../ui/button/Button.vue'
|
||||
import {
|
||||
PhCaretDoubleLeft,
|
||||
PhCaretDoubleRight,
|
||||
PhCaretLeft,
|
||||
PhCaretRight
|
||||
} from '@phosphor-icons/vue'
|
||||
import Button from '../ui/button/Button.vue'
|
||||
|
||||
const { decrementMonth, incrementMonth, decrementYear, incrementYear } = useCalendar()
|
||||
</script>
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref, computed } from 'vue'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Dialog, DialogContent, DialogTrigger } from '@/components/ui/dialog'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { PhMagnifyingGlass } from '@phosphor-icons/vue'
|
||||
import { useCalendarEvents } from '@/stores/events'
|
||||
import CalendarMenuSearchResults from './CalendarMenuSearchResults.vue'
|
||||
import { useMagicKeys, whenever } from '@vueuse/core'
|
||||
|
||||
const { allEvents } = useCalendarEvents()
|
||||
|
||||
const modalOpen = ref(false)
|
||||
|
||||
const searchQuery = ref('')
|
||||
const searchEnough = computed(() => searchQuery.value.length >= 2)
|
||||
const displaySearch = computed(() => searchQuery.value && searchEnough.value)
|
||||
|
||||
const unifier = new RegExp(/[^a-zA-Z0-9\-'']/g)
|
||||
|
||||
const searchResults = computed(() => {
|
||||
return allEvents.filter((event) => {
|
||||
const queryString = new String(searchQuery.value).replace(unifier, '').toLocaleLowerCase()
|
||||
const hitTitle = event.title.replace(unifier, '').toLocaleLowerCase().includes(queryString)
|
||||
const hitDesc = event.description
|
||||
?.replace(unifier, '')
|
||||
.toLocaleLowerCase()
|
||||
.includes(queryString)
|
||||
|
||||
return hitTitle || hitDesc
|
||||
})
|
||||
})
|
||||
|
||||
function resetSearch() {
|
||||
searchQuery.value = ''
|
||||
}
|
||||
|
||||
function openDialog() {
|
||||
modalOpen.value = true
|
||||
}
|
||||
|
||||
function closeDialog() {
|
||||
modalOpen.value = false
|
||||
}
|
||||
|
||||
// Key combos to deploy modal
|
||||
const keys = useMagicKeys()
|
||||
|
||||
whenever(keys.control_period, () => {
|
||||
openDialog()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Dialog v-model:open="modalOpen" @update:open="resetSearch">
|
||||
<DialogTrigger>
|
||||
<Button search-slash>
|
||||
<PhMagnifyingGlass size="20" weight="light" />
|
||||
Recherche avancée
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
|
||||
<DialogContent
|
||||
class="flex flex-col flex-nowrap top-32 -translate-y-0 data-[state=closed]:slide-out-to-top-[2rem] data-[state=open]:slide-in-from-top-[2rem]"
|
||||
:class="{
|
||||
'bottom-16': displaySearch && searchResults.length > 0
|
||||
}"
|
||||
>
|
||||
<div class="relative w-full h-fit">
|
||||
<Input
|
||||
id="search"
|
||||
type="text"
|
||||
placeholder="Rechercher un évènement, un personnage…"
|
||||
class="pl-10 py-6 text-lg"
|
||||
v-model:model-value="searchQuery"
|
||||
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 v-if="displaySearch && searchResults.length > 0" class="overflow-y-auto">
|
||||
<hr class="mb-4" />
|
||||
<CalendarMenuSearchResults :events="searchResults" @jumped-to-date="closeDialog()" />
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</template>
|
||||
@@ -1,49 +0,0 @@
|
||||
<script lang="ts" setup>
|
||||
import type { LeimDate } from '@/models/Date'
|
||||
import { useCalendar } from '@/stores/calendar'
|
||||
import type { CalendarEvent } from '@/stores/events'
|
||||
|
||||
defineProps<{
|
||||
events: CalendarEvent[]
|
||||
}>()
|
||||
|
||||
const emit = defineEmits(['jumpedToDate'])
|
||||
|
||||
const { jumpToDate } = useCalendar()
|
||||
|
||||
function handleJumpToDate(date: LeimDate) {
|
||||
jumpToDate(date)
|
||||
emit('jumpedToDate')
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ul class="grid gap-3">
|
||||
<li v-for="e in events" :key="e.title">
|
||||
<button
|
||||
class="block w-full text-left p-2 rounded-sm"
|
||||
:class="{
|
||||
'bg-slate-600 hover:bg-slate-700': !e.category,
|
||||
'bg-green-700 hover:bg-green-800': e.category === 'birth',
|
||||
'bg-stone-600 hover:bg-stone-800': e.category === 'death',
|
||||
'bg-red-600 hover:bg-red-800': e.category === 'catastrophe',
|
||||
'bg-pink-600 hover:bg-pink-800': e.category === 'natural-disaster',
|
||||
'bg-blue-600 hover:bg-blue-800': e.category === 'legal',
|
||||
'bg-amber-700 hover:bg-amber-800': e.category === 'player'
|
||||
}"
|
||||
@click="handleJumpToDate(e.date)"
|
||||
>
|
||||
<div>
|
||||
{{ e.title }}
|
||||
</div>
|
||||
|
||||
<div v-if="e.description" class="text-sm">
|
||||
<hr class="my-2 border-white opacity-25" />
|
||||
<span class="opacity-75">
|
||||
{{ e.description }}
|
||||
</span>
|
||||
</div>
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
</template>
|
||||
@@ -7,10 +7,10 @@ import {
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger
|
||||
} from '@/components/ui/dropdown-menu'
|
||||
import Button from '../ui/button/Button.vue'
|
||||
import { useCalendar } from '@/stores/calendar'
|
||||
import { computed } from 'vue'
|
||||
import { PhCalendarBlank } from '@phosphor-icons/vue'
|
||||
import { computed } from 'vue'
|
||||
import Button from '../ui/button/Button.vue'
|
||||
|
||||
const { currentConfig, viewTypeOptions, getViewTypeTitle, setViewType } = useCalendar()
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
import type { LeimDate } from '@/models/Date'
|
||||
import { useCalendar } from '@/stores/calendar'
|
||||
import { useCalendarEvents } from '@/stores/events'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { computed } from 'vue'
|
||||
import CalendarEvent from './CalendarEvent.vue'
|
||||
import { storeToRefs } from 'pinia'
|
||||
|
||||
const props = defineProps<{
|
||||
date: LeimDate
|
||||
|
||||
3
src/components/calendar/Search.ts
Normal file
3
src/components/calendar/Search.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export const searchUnifier = new RegExp(/[^a-zA-Z0-9\-'']/g)
|
||||
|
||||
export type SearchMode = 'characters' | 'events' | undefined
|
||||
150
src/components/calendar/search/CalendarSearch.vue
Normal file
150
src/components/calendar/search/CalendarSearch.vue
Normal file
@@ -0,0 +1,150 @@
|
||||
<script lang="ts" setup>
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Dialog, DialogContent, DialogTrigger } from '@/components/ui/dialog'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group'
|
||||
import { useCharacters } from '@/stores/characters'
|
||||
import { useCalendarEvents } from '@/stores/events'
|
||||
import { PhMagnifyingGlass } from '@phosphor-icons/vue'
|
||||
import { useMagicKeys, useStorage, useTimeoutFn, whenever } from '@vueuse/core'
|
||||
import { computed, ref } from 'vue'
|
||||
import { searchUnifier, type SearchMode } from '../Search'
|
||||
import SearchList from './lists/SearchList.vue'
|
||||
import { isCalendarEvent, type CalendarEvent } from '@/models/Events'
|
||||
import { isCharacter, type Character } from '@/models/Characters'
|
||||
|
||||
const { characters } = useCharacters()
|
||||
const { baseEvents } = useCalendarEvents()
|
||||
|
||||
const modalOpen = ref(false)
|
||||
|
||||
const searchQuery = ref('')
|
||||
const searchEnough = computed(() => searchQuery.value.length >= 2)
|
||||
|
||||
const selectedEntity = useStorage('se', undefined as SearchMode)
|
||||
|
||||
const searchResults = computed(() => {
|
||||
let results: (Character | CalendarEvent)[] = []
|
||||
let dataToFilter: Character[] | CalendarEvent[] | (Character | CalendarEvent)[]
|
||||
|
||||
// Assign data to loop over and filter
|
||||
// They are assigned this way for readability
|
||||
if (selectedEntity.value === 'events') {
|
||||
dataToFilter = baseEvents
|
||||
} else if (selectedEntity.value === 'characters') {
|
||||
dataToFilter = characters
|
||||
} else {
|
||||
dataToFilter = [...baseEvents, ...characters]
|
||||
}
|
||||
|
||||
results = dataToFilter.filter((item) => {
|
||||
// Filter calendar events
|
||||
if (isCalendarEvent(item)) {
|
||||
const queryString = new String(searchQuery.value)
|
||||
.replace(searchUnifier, '')
|
||||
.toLocaleLowerCase()
|
||||
|
||||
const hitTitle = item.title
|
||||
.replace(searchUnifier, '')
|
||||
.toLocaleLowerCase()
|
||||
.includes(queryString)
|
||||
const hitDesc = item.description
|
||||
?.replace(searchUnifier, '')
|
||||
.toLocaleLowerCase()
|
||||
.includes(queryString)
|
||||
|
||||
return hitTitle || hitDesc
|
||||
}
|
||||
|
||||
// Filter characters
|
||||
if (isCharacter(item)) {
|
||||
const queryString = new String(searchQuery.value)
|
||||
.replace(searchUnifier, '')
|
||||
.toLocaleLowerCase()
|
||||
|
||||
const hitTitle = item.name
|
||||
.replace(searchUnifier, '')
|
||||
.toLocaleLowerCase()
|
||||
.includes(queryString)
|
||||
|
||||
return hitTitle
|
||||
}
|
||||
})
|
||||
|
||||
return results
|
||||
})
|
||||
|
||||
function resetSearch() {
|
||||
searchQuery.value = ''
|
||||
}
|
||||
|
||||
const resetSearchLazy = useTimeoutFn(() => {
|
||||
resetSearch()
|
||||
}, 300)
|
||||
|
||||
function openDialog() {
|
||||
modalOpen.value = true
|
||||
}
|
||||
|
||||
function closeDialog() {
|
||||
modalOpen.value = false
|
||||
}
|
||||
|
||||
// Key combos to deploy modal
|
||||
const keys = useMagicKeys()
|
||||
|
||||
whenever(keys.control_period, () => {
|
||||
openDialog()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Dialog v-model:open="modalOpen" @update:open="resetSearchLazy.start">
|
||||
<DialogTrigger>
|
||||
<Button search-slash>
|
||||
<PhMagnifyingGlass size="20" weight="light" />
|
||||
Recherche avancée
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
|
||||
<DialogContent
|
||||
class="flex flex-col flex-nowrap top-16 -translate-y-0 data-[state=closed]:slide-out-to-top-[5%] data-[state=open]:slide-in-from-top-[5%]"
|
||||
:class="{
|
||||
'bottom-16': searchResults.length > 0
|
||||
}"
|
||||
>
|
||||
<div class="relative w-full h-fit">
|
||||
<Input
|
||||
id="search"
|
||||
type="text"
|
||||
placeholder="Rechercher le calendrier"
|
||||
class="pl-10 py-6 text-lg"
|
||||
v-model:model-value="searchQuery"
|
||||
autocomplete="off"
|
||||
/>
|
||||
<span class="absolute start-1 inset-y-0 flex items-center justify-center px-2 opacity-50">
|
||||
<PhMagnifyingGlass size="20" />
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<ToggleGroup type="single" class="justify-start" v-model="selectedEntity">
|
||||
<ToggleGroupItem value="events" aria-label="Uniquement les évènements">
|
||||
Évènements
|
||||
</ToggleGroupItem>
|
||||
<ToggleGroupItem value="characters" aria-label="Uniquement les personnages">
|
||||
Personnages
|
||||
</ToggleGroupItem>
|
||||
</ToggleGroup>
|
||||
|
||||
<hr />
|
||||
|
||||
<div v-if="searchResults.length > 0" class="overflow-y-auto">
|
||||
<SearchList
|
||||
:results="searchResults"
|
||||
:current-entity="selectedEntity"
|
||||
@jumped-to-date="closeDialog()"
|
||||
/>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</template>
|
||||
99
src/components/calendar/search/lists/SearchList.vue
Normal file
99
src/components/calendar/search/lists/SearchList.vue
Normal file
@@ -0,0 +1,99 @@
|
||||
<script lang="ts" setup>
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { isCharacter, type Character } from '@/models/Characters'
|
||||
import type { LeimDate } from '@/models/Date'
|
||||
import { isCalendarEvent, type CalendarEvent } from '@/models/Events'
|
||||
import { useCalendar } from '@/stores/calendar'
|
||||
import { computed } from 'vue'
|
||||
import type { SearchMode } from '../../Search'
|
||||
|
||||
const props = defineProps<{
|
||||
results: (Character | CalendarEvent)[]
|
||||
currentEntity: SearchMode
|
||||
}>()
|
||||
|
||||
const emit = defineEmits(['jumpedToDate'])
|
||||
|
||||
const { getFormattedDateTitle, jumpToDate } = useCalendar()
|
||||
|
||||
function handleJumpToDate(date?: LeimDate) {
|
||||
if (!date) return
|
||||
|
||||
jumpToDate(date)
|
||||
emit('jumpedToDate')
|
||||
}
|
||||
|
||||
const searchLimit = 10
|
||||
const activeSearchLimit = computed<number>(() => (!props.currentEntity ? searchLimit : 9999))
|
||||
|
||||
const resultsToDisplay = computed(() => props.results.slice(0, activeSearchLimit.value))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ul class="grid gap-3">
|
||||
<li v-for="r in resultsToDisplay" :key="isCalendarEvent(r) ? r.title : r.name">
|
||||
<button
|
||||
v-if="isCalendarEvent(r)"
|
||||
class="block w-full text-left p-2 rounded-sm"
|
||||
:class="{
|
||||
'bg-slate-600 hover:bg-slate-700': !r.category,
|
||||
'bg-green-700 hover:bg-green-800': r.category === 'birth',
|
||||
'bg-stone-600 hover:bg-stone-800': r.category === 'death',
|
||||
'bg-red-600 hover:bg-red-800': r.category === 'catastrophe',
|
||||
'bg-pink-600 hover:bg-pink-800': r.category === 'natural-disaster',
|
||||
'bg-blue-600 hover:bg-blue-800': r.category === 'legal',
|
||||
'bg-amber-700 hover:bg-amber-800': r.category === 'player'
|
||||
}"
|
||||
@click="handleJumpToDate(r.date)"
|
||||
>
|
||||
<div>
|
||||
{{ r.title }}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span class="opacity-75 italic">{{ getFormattedDateTitle(r.date, true) }}</span>
|
||||
</div>
|
||||
|
||||
<div v-if="r.description" class="text-sm">
|
||||
<hr class="my-2 border-white opacity-25" />
|
||||
<span class="opacity-75">
|
||||
{{ r.description }}
|
||||
</span>
|
||||
</div>
|
||||
</button>
|
||||
|
||||
<div
|
||||
v-else-if="isCharacter(r)"
|
||||
class="block w-full text-left py-2 px-4 border-[1px] border-slate-700 rounded-sm"
|
||||
>
|
||||
<div class="flex items-center gap-6">
|
||||
<div>
|
||||
<div>
|
||||
{{ r.name }}
|
||||
</div>
|
||||
|
||||
<div v-if="r.description" class="text-sm">
|
||||
<hr class="my-2 border-white opacity-25" />
|
||||
<span class="opacity-75">
|
||||
{{ r.description }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<menu class="flex gap-2">
|
||||
<li v-if="r.birth">
|
||||
<Button @click="handleJumpToDate(r.birth)" variant="outline" size="sm">
|
||||
Naissance
|
||||
</Button>
|
||||
</li>
|
||||
<li v-if="r.death">
|
||||
<Button @click="handleJumpToDate(r.death)" variant="outline" size="sm">
|
||||
Décès
|
||||
</Button>
|
||||
</li>
|
||||
</menu>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</template>
|
||||
@@ -1,9 +1,9 @@
|
||||
<script lang="ts" setup>
|
||||
import type { LeimDate } from '@/models/Date'
|
||||
import { useCalendar } from '@/stores/calendar'
|
||||
import { useThrottleFn } from '@vueuse/core'
|
||||
import { computed } from 'vue'
|
||||
import CalendarTile from '../CalendarTile.vue'
|
||||
import { useThrottleFn } from '@vueuse/core'
|
||||
|
||||
const { staticConfig, currentDate, decrementMonth, incrementMonth } = useCalendar()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user