|
| 1 | +<script setup> |
| 2 | +import { ref } from 'vue' |
| 3 | +import { usePage, router } from '@inertiajs/vue3' |
| 4 | +import { platforms, pricings, difficulties } from '@/Helpers/labels' |
| 5 | +import InputText from 'primevue/inputtext' |
| 6 | +import Dropdown from 'primevue/dropdown' |
| 7 | +import MultiSelect from 'primevue/multiselect' |
| 8 | +import Button from 'primevue/button' |
| 9 | +
|
| 10 | +// Get current query params |
| 11 | +const { url } = usePage() |
| 12 | +const query = new URLSearchParams(url.split('?')[1]) |
| 13 | +
|
| 14 | +// Reactive form fields |
| 15 | +const name = ref(query.get('name') || '') |
| 16 | +const description = ref(query.get('description') || '') |
| 17 | +const selectedPlatforms = ref(query.getAll('platforms') || []) |
| 18 | +const selectedDifficulty = ref(query.get('difficulty') || '') |
| 19 | +const selectedPricing = ref(query.get('pricing') || '') |
| 20 | +
|
| 21 | +function search() { |
| 22 | + router.visit(route('resources.index', { |
| 23 | + name: name.value || undefined, |
| 24 | + description: description.value || undefined, |
| 25 | + platforms: selectedPlatforms.value?.length ? selectedPlatforms.value : undefined, |
| 26 | + difficulty: selectedDifficulty.value || undefined, |
| 27 | + pricing: selectedPricing.value || undefined, |
| 28 | + }), { |
| 29 | + preserveState: true, |
| 30 | + preserveScroll: true, |
| 31 | + }) |
| 32 | +} |
| 33 | +</script> |
| 34 | + |
| 35 | +<template> |
| 36 | + <div class="p-4 bg-white rounded-xl shadow-md"> |
| 37 | + <h2 class="text-xl font-semibold mb-4">Search Resources</h2> |
| 38 | + |
| 39 | + <div class="flex flex-wrap gap-4"> |
| 40 | + <!-- Name --> |
| 41 | + <div class="flex-1 min-w-[200px]"> |
| 42 | + <label class="block text-sm font-medium mb-1">Name</label> |
| 43 | + <InputText v-model="name" class="w-full" /> |
| 44 | + </div> |
| 45 | + |
| 46 | + <!-- Description --> |
| 47 | + <div class="flex-1 min-w-[200px]"> |
| 48 | + <label class="block text-sm font-medium mb-1">Description</label> |
| 49 | + <InputText v-model="description" class="w-full" /> |
| 50 | + </div> |
| 51 | + |
| 52 | + <!-- Platforms --> |
| 53 | + <div class="flex-1 min-w-[200px]"> |
| 54 | + <label class="block text-sm font-medium mb-1">Platforms</label> |
| 55 | + <MultiSelect |
| 56 | + v-model="selectedPlatforms" |
| 57 | + :options="platforms" |
| 58 | + optionLabel="label" |
| 59 | + optionValue="value" |
| 60 | + placeholder="All Platforms" |
| 61 | + showClear |
| 62 | + class="w-full" |
| 63 | + /> |
| 64 | + </div> |
| 65 | + |
| 66 | + <!-- Difficulty --> |
| 67 | + <div class="flex-1 min-w-[200px]"> |
| 68 | + <label class="block text-sm font-medium mb-1">Difficulty</label> |
| 69 | + <Dropdown |
| 70 | + v-model="selectedDifficulty" |
| 71 | + :options="difficulties" |
| 72 | + optionLabel="label" |
| 73 | + optionValue="value" |
| 74 | + placeholder="All Difficulties" |
| 75 | + showClear |
| 76 | + class="w-full" |
| 77 | + /> |
| 78 | + </div> |
| 79 | + |
| 80 | + <!-- Pricing --> |
| 81 | + <div class="flex-1 min-w-[200px]"> |
| 82 | + <label class="block text-sm font-medium mb-1">Pricing</label> |
| 83 | + <Dropdown |
| 84 | + v-model="selectedPricing" |
| 85 | + :options="pricings" |
| 86 | + optionLabel="label" |
| 87 | + optionValue="value" |
| 88 | + placeholder="All Pricing" |
| 89 | + showClear |
| 90 | + class="w-full" |
| 91 | + /> |
| 92 | + </div> |
| 93 | + |
| 94 | + <!-- Search Button --> |
| 95 | + <div class="flex items-end"> |
| 96 | + <Button label="Filter" icon="pi pi-search" @click="search" /> |
| 97 | + </div> |
| 98 | + </div> |
| 99 | + </div> |
| 100 | +</template> |
0 commit comments