useRestaurantFilters
useRestaurantFilters
Filter state composable for the restaurants listing page. State is held in useState (SSR-safe) and kept in sync with URL query parameters (cuisines, locations, prices, rating, amenities, dietary). The composable pre-fetches a meta dataset (restaurants-meta) to derive the available filter options for the sidebar, and uses a separate lazy async data call (filtered-restaurants) that refreshes whenever the URL is updated.
Filters are AND-combined across groups (e.g. cuisine AND price) and OR-combined within a group (e.g. Italian OR Japanese).
Usage
const {
filteredRestaurants,
totalCount,
pending,
toggleCuisine,
toggleLocation,
togglePriceLevel,
toggleAmenity,
toggleDietaryOption,
setRating,
clearAllFilters,
hasActiveFilters,
activeFilterCount,
} = useRestaurantFilters()
Returns
Reactive state
| Key | Type | Description |
|---|---|---|
selectedCuisines | Ref<string[]> | Currently selected cuisine ids. |
selectedLocations | Ref<string[]> | Currently selected neighborhoods. |
selectedRatingMin | Ref<number | null> | Minimum star rating threshold. |
selectedPriceLevels | Ref<number[]> | Currently selected price levels (1–4). |
selectedAmenities | Ref<string[]> | Currently selected amenity ids. |
selectedDietaryOptions | Ref<string[]> | Currently selected dietary option ids. |
selectedOpenNow | Ref<'any' | 'open' | 'closed'> | Open-now filter. Defaults to 'any'. |
selectedSort | Ref<'recommended' | 'distance' | 'rating' | 'price' | 'reviews'> | Sort order. Defaults to 'recommended'. 'distance' triggers a geolocation permission prompt. |
selectedVibes | Ref<string[]> | Currently selected vibe ids (Good For / Atmosphere / Noise). Combined with AND logic. |
filteredRestaurants | ComputedRef<any[]> | Restaurants matching the active filters (derived from filteredData). |
totalCount | ComputedRef<number> | Total count from the API response (raw.total when present, otherwise array length). |
pending | ComputedRef<boolean> | true while the filtered-results fetch is in-flight. |
Derived option lists
| Key | Type | Description |
|---|---|---|
availableCuisines | ComputedRef<{ id: string, label: string }[]> | All cuisines present in the meta dataset. |
availableLocations | ComputedRef<string[]> | All neighborhoods present in the meta dataset (sorted). |
availableAmenities | ComputedRef<{ id: string, label: string }[]> | All amenities present in the meta dataset. |
Sync helpers
| Key | Type | Description |
|---|---|---|
initializeFromUrl | () => void | Reads the current route's query params and seeds each selected* ref. |
updateUrl | () => void | Writes each selected* ref back to the URL (router.replace) and resets page to 1, then refreshes the lazy fetch. |
refresh | () => Promise<void> | Manually re-runs the filtered-results fetch. |
Toggle / setters
| Key | Type | Description |
|---|---|---|
toggleCuisine | (id: string) => void | Toggles a cuisine id in selectedCuisines. |
toggleLocation | (location: string) => void | Toggles a neighborhood in selectedLocations. |
togglePriceLevel | (level: number) => void | Toggles a price level in selectedPriceLevels. |
toggleAmenity | (id: string) => void | Toggles an amenity id in selectedAmenities. |
toggleDietaryOption | (option: string) => void | Toggles a dietary option in selectedDietaryOptions. |
toggleVibe | (vibeId: string) => void | Toggles a vibe id in selectedVibes. Vibe ids come from useVibes(). |
setRating | (rating: number | null) => void | Sets the minimum rating (pass null to clear). |
clearAllFilters | () => void | Resets all filter refs and the URL query. |
Computed status
| Key | Type | Description |
|---|---|---|
hasActiveFilters | ComputedRef<boolean> | true when at least one filter is active. |
activeFilterCount | ComputedRef<number> | Total number of currently active filter values. |
AI Context
composable: useRestaurantFilters
package: "@xenterprises/nuxt-x-restaurants"
use-when: >
Building or customising the restaurants listing page filter UX. Used
internally by XRDFilters, XRDFiltersAsideFilters, and XRDFiltersActiveFilters.
Also use when you need to read filteredRestaurants, totalCount, or pending
reactively, drive derived option lists (availableCuisines/Locations/Amenities),
or clear filters programmatically from outside the filter panel.
Schema.org JSON-LD & Site Meta
Schema composables — emit Article, Review, Product, ItemList, BreadcrumbList JSON-LD for Google rich results, plus a useSiteMeta helper that consolidates title/description/OG/Twitter Card boilerplate.
useFilters
Generic filter composable for menu items and other list data — reads groups from app config, supports custom filter handlers and a shared mobile drawer state.
