add town filter

This commit is contained in:
padreug 2025-02-03 00:05:25 +01:00
parent ce61630350
commit 2b5fdb9e57
2 changed files with 35 additions and 7 deletions

View file

@ -6,11 +6,13 @@ import { Button } from '@/components/ui/button'
defineProps<{ defineProps<{
category: string category: string
search: string search: string
town: string
}>() }>()
const emit = defineEmits<{ const emit = defineEmits<{
'update:category': [value: string] 'update:category': [value: string]
'update:search': [value: string] 'update:search': [value: string]
'update:town': [value: string]
}>() }>()
const categories = [ const categories = [
@ -23,6 +25,16 @@ const categories = [
{ id: 'lancha', label: 'Lanchas' }, { id: 'lancha', label: 'Lanchas' },
{ id: 'other', label: 'Other' } { id: 'other', label: 'Other' }
] ]
const towns = [
{ id: 'all', label: 'All Towns' },
{ id: 'San Marcos', label: 'San Marcos' },
{ id: 'Tzununa', label: 'Tzununa' },
{ id: 'San Pablo', label: 'San Pablo' },
{ id: 'San Pedro', label: 'San Pedro' },
{ id: 'Panajachel', label: 'Panajachel' },
{ id: 'Jaibalito', label: 'Jaibalito' }
]
</script> </script>
<template> <template>
@ -36,6 +48,7 @@ const categories = [
class="pl-10" placeholder="Search..." /> class="pl-10" placeholder="Search..." />
</div> </div>
<div class="flex flex-col md:flex-row gap-2">
<!-- Category Filter --> <!-- Category Filter -->
<div class="flex gap-2 overflow-x-auto pb-2 md:pb-0"> <div class="flex gap-2 overflow-x-auto pb-2 md:pb-0">
<Button v-for="cat in categories" :key="cat.id" @click="emit('update:category', cat.id)" <Button v-for="cat in categories" :key="cat.id" @click="emit('update:category', cat.id)"
@ -43,5 +56,14 @@ const categories = [
{{ cat.label }} {{ cat.label }}
</Button> </Button>
</div> </div>
<!-- Town Filter -->
<div class="flex gap-2 overflow-x-auto pb-2 md:pb-0">
<Button v-for="t in towns" :key="t.id" @click="emit('update:town', t.id)"
:variant="town === t.id ? 'default' : 'secondary'" size="sm" class="rounded-full">
{{ t.label }}
</Button>
</div>
</div>
</div> </div>
</template> </template>

View file

@ -6,6 +6,7 @@ import { type DirectoryItem } from '@/types/directory'
import DirectoryFilter from './DirectoryFilter.vue' import DirectoryFilter from './DirectoryFilter.vue'
const selectedCategory = ref<string>('all') const selectedCategory = ref<string>('all')
const selectedTown = ref<string>('all')
const searchQuery = ref('') const searchQuery = ref('')
const props = defineProps<{ const props = defineProps<{
@ -42,6 +43,11 @@ const filteredItems = computed(() => {
results = results.filter(item => item.category === selectedCategory.value) results = results.filter(item => item.category === selectedCategory.value)
} }
// Apply town filter
if (selectedTown.value !== 'all') {
results = results.filter(item => item.town === selectedTown.value)
}
return results return results
}) })
</script> </script>
@ -50,7 +56,7 @@ const filteredItems = computed(() => {
<div class="container mx-auto px-4 py-8"> <div class="container mx-auto px-4 py-8">
<!-- Filters --> <!-- Filters -->
<div class="mb-8 space-y-4 md:space-y-0 md:flex md:items-center md:justify-between"> <div class="mb-8 space-y-4 md:space-y-0 md:flex md:items-center md:justify-between">
<DirectoryFilter v-model:category="selectedCategory" v-model:search="searchQuery" /> <DirectoryFilter v-model:category="selectedCategory" v-model:search="searchQuery" v-model:town="selectedTown" />
</div> </div>
<!-- Grid --> <!-- Grid -->