Enhance park search with autocomplete and improved filtering options

Introduce autocomplete for park searches, optimize park data fetching with select_related and prefetch_related, add new API endpoints for autocomplete and quick filters, and refactor the park list view to use new Django Cotton components for a more dynamic and user-friendly experience.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: c446bc9e-66df-438c-a86c-f53e6da13649
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
This commit is contained in:
pac7
2025-09-23 21:44:12 +00:00
parent 7feb7c462d
commit 4c954fff6f
13 changed files with 1588 additions and 245 deletions

View File

@@ -1,93 +1,301 @@
{% extends "base/base.html" %}
{% load static %}
{% load cotton %}
{% block title %}Parks{% endblock %}
{% block content %}
<div class="container mx-auto px-4 py-6">
<!-- Consolidated Search and View Controls Bar -->
<div class="bg-gray-800 rounded-lg p-4 mb-6">
<div class="flex flex-col lg:flex-row lg:items-center lg:justify-between gap-4">
<!-- Search Section -->
<div class="flex-1 max-w-2xl">
<div class="relative">
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
<svg class="h-5 w-5 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path>
</svg>
</div>
<input
type="text"
name="search"
value="{{ search_query }}"
placeholder="Search parks by name, location, or features..."
class="block w-full pl-10 pr-3 py-2 border border-gray-600 rounded-md leading-5 bg-gray-700 text-white placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
hx-get="{% url 'parks:park_list' %}"
hx-trigger="keyup changed delay:300ms"
hx-target="#park-results"
hx-include="[name='view_mode']"
hx-indicator="#search-spinner"
/>
<div id="search-spinner" class="absolute inset-y-0 right-0 pr-3 flex items-center htmx-indicator">
<svg class="animate-spin h-5 w-5 text-gray-400" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
</svg>
</div>
</div>
<div class="container mx-auto px-4 py-6" x-data="parkListState()">
<!-- Enhanced Header Section -->
<div class="mb-8">
<div class="flex flex-col lg:flex-row lg:items-center lg:justify-between gap-4 mb-6">
<div>
<h1 class="text-3xl lg:text-4xl font-bold text-gray-900 dark:text-white">
Theme Parks
</h1>
<p class="mt-2 text-lg text-gray-600 dark:text-gray-400">
Discover amazing theme parks around the world
</p>
</div>
<!-- Results Count and View Controls -->
<div class="flex items-center gap-4">
<!-- Results Count -->
<div class="text-gray-300 text-sm whitespace-nowrap">
<span class="font-medium">Parks</span>
{% if total_results %}
<span class="text-gray-400">({{ total_results }} found)</span>
{% endif %}
<!-- Quick Stats -->
<div class="flex items-center gap-6 text-sm text-gray-600 dark:text-gray-400">
<div class="text-center">
<div class="font-bold text-lg text-gray-900 dark:text-white">{{ filter_counts.total_parks|default:0 }}</div>
<div>Total Parks</div>
</div>
<!-- View Mode Toggle -->
<div class="flex bg-gray-700 rounded-lg p-1">
<input type="hidden" name="view_mode" value="{{ view_mode }}" />
<!-- Grid View Button -->
<button
type="button"
class="p-2 rounded-md transition-colors duration-200 {% if view_mode == 'grid' %}bg-blue-600 text-white{% else %}text-gray-400 hover:text-white{% endif %}"
title="Grid View"
hx-get="{% url 'parks:park_list' %}?view_mode=grid"
hx-target="#park-results"
hx-include="[name='search']"
hx-push-url="true"
>
<svg class="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2V6zM14 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V6zM4 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2v-2zM14 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z"></path>
</svg>
</button>
<!-- List View Button -->
<button
type="button"
class="p-2 rounded-md transition-colors duration-200 {% if view_mode == 'list' %}bg-blue-600 text-white{% else %}text-gray-400 hover:text-white{% endif %}"
title="List View"
hx-get="{% url 'parks:park_list' %}?view_mode=list"
hx-target="#park-results"
hx-include="[name='search']"
hx-push-url="true"
>
<svg class="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 10h16M4 14h16M4 18h16"></path>
</svg>
</button>
<div class="text-center">
<div class="font-bold text-lg text-gray-900 dark:text-white">{{ filter_counts.operating_parks|default:0 }}</div>
<div>Operating</div>
</div>
<div class="text-center">
<div class="font-bold text-lg text-gray-900 dark:text-white">{{ filter_counts.parks_with_coasters|default:0 }}</div>
<div>With Coasters</div>
</div>
</div>
</div>
</div>
<!-- Results Container -->
<div id="park-results">
{% include "parks/partials/park_list.html" %}
<!-- Enhanced Search and Filter Bar -->
<div class="bg-white dark:bg-gray-800 rounded-xl shadow-lg border border-gray-200 dark:border-gray-700 p-6 mb-8">
<div class="space-y-6">
<!-- Main Search Row -->
<div class="flex flex-col lg:flex-row gap-4">
<!-- Enhanced Search Input -->
<div class="flex-1">
<c-enhanced_search
placeholder="Search parks by name, location, or features..."
current_value="{{ search_query }}"
autocomplete_url="{% url 'parks:park_autocomplete' %}"
class="w-full"
/>
</div>
<!-- Controls Row -->
<div class="flex items-center gap-3">
<!-- Sort Controls -->
<c-sort_controls
current_sort="{{ current_ordering }}"
class="min-w-0"
/>
<!-- View Toggle -->
<c-view_toggle
current_view="{{ view_mode }}"
class="flex-shrink-0"
/>
<!-- Filter Toggle Button (Mobile) -->
<button
type="button"
class="lg:hidden inline-flex items-center px-3 py-2 border border-gray-300 rounded-md shadow-sm bg-white text-sm font-medium text-gray-700 hover:bg-gray-50 dark:bg-gray-700 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-600"
@click="showFilters = !showFilters"
aria-label="Toggle filters"
>
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z" />
</svg>
<span class="ml-1">Filters</span>
</button>
</div>
</div>
<!-- Advanced Filters Row -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4"
x-show="showFilters"
x-transition:enter="transition ease-out duration-200"
x-transition:enter-start="opacity-0 transform scale-95"
x-transition:enter-end="opacity-100 transform scale-100"
x-transition:leave="transition ease-in duration-150"
x-transition:leave-start="opacity-100 transform scale-100"
x-transition:leave-end="opacity-0 transform scale-95">
<!-- Status Filter -->
<div>
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
Status
</label>
<select
name="status"
class="block w-full px-3 py-2 border border-gray-300 rounded-md bg-white text-gray-900 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:focus:ring-blue-500"
hx-get="{% url 'parks:park_list' %}"
hx-target="#park-results"
hx-include="[name='search'], [name='view_mode'], [name='ordering'], [name='operator'], [name='park_type']"
hx-push-url="true"
hx-indicator="#search-spinner"
>
<option value="">All Statuses</option>
<option value="OPERATING" {% if request.GET.status == 'OPERATING' %}selected{% endif %}>Operating</option>
<option value="CLOSED_TEMP" {% if request.GET.status == 'CLOSED_TEMP' %}selected{% endif %}>Temporarily Closed</option>
<option value="CLOSED_PERM" {% if request.GET.status == 'CLOSED_PERM' %}selected{% endif %}>Permanently Closed</option>
<option value="UNDER_CONSTRUCTION" {% if request.GET.status == 'UNDER_CONSTRUCTION' %}selected{% endif %}>Under Construction</option>
</select>
</div>
<!-- Operator Filter -->
<div>
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
Operator
</label>
<select
name="operator"
class="block w-full px-3 py-2 border border-gray-300 rounded-md bg-white text-gray-900 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:focus:ring-blue-500"
hx-get="{% url 'parks:park_list' %}"
hx-target="#park-results"
hx-include="[name='search'], [name='view_mode'], [name='ordering'], [name='status'], [name='park_type']"
hx-push-url="true"
hx-indicator="#search-spinner"
>
<option value="">All Operators</option>
{% for operator in filter_counts.top_operators %}
<option value="{{ operator.operator__id }}"
{% if request.GET.operator == operator.operator__id|stringformat:"s" %}selected{% endif %}>
{{ operator.operator__name }} ({{ operator.park_count }})
</option>
{% endfor %}
</select>
</div>
<!-- Park Type Filter -->
<div>
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
Park Type
</label>
<select
name="park_type"
class="block w-full px-3 py-2 border border-gray-300 rounded-md bg-white text-gray-900 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:focus:ring-blue-500"
hx-get="{% url 'parks:park_list' %}"
hx-target="#park-results"
hx-include="[name='search'], [name='view_mode'], [name='ordering'], [name='status'], [name='operator']"
hx-push-url="true"
hx-indicator="#search-spinner"
>
<option value="">All Types</option>
<option value="disney" {% if request.GET.park_type == 'disney' %}selected{% endif %}>Disney Parks</option>
<option value="universal" {% if request.GET.park_type == 'universal' %}selected{% endif %}>Universal Parks</option>
<option value="six_flags" {% if request.GET.park_type == 'six_flags' %}selected{% endif %}>Six Flags</option>
<option value="cedar_fair" {% if request.GET.park_type == 'cedar_fair' %}selected{% endif %}>Cedar Fair</option>
<option value="independent" {% if request.GET.park_type == 'independent' %}selected{% endif %}>Independent</option>
</select>
</div>
<!-- Quick Filters -->
<div>
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
Quick Filters
</label>
<div class="space-y-2">
<label class="flex items-center">
<input
type="checkbox"
name="has_coasters"
value="true"
{% if request.GET.has_coasters %}checked{% endif %}
class="rounded border-gray-300 text-blue-600 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700"
hx-get="{% url 'parks:park_list' %}"
hx-target="#park-results"
hx-include="[name='search'], [name='view_mode'], [name='ordering'], [name='status'], [name='operator'], [name='park_type']"
hx-push-url="true"
hx-indicator="#search-spinner"
/>
<span class="ml-2 text-sm text-gray-700 dark:text-gray-300">Has Roller Coasters</span>
</label>
<label class="flex items-center">
<input
type="checkbox"
name="big_parks_only"
value="true"
{% if request.GET.big_parks_only %}checked{% endif %}
class="rounded border-gray-300 text-blue-600 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700"
hx-get="{% url 'parks:park_list' %}"
hx-target="#park-results"
hx-include="[name='search'], [name='view_mode'], [name='ordering'], [name='status'], [name='operator'], [name='park_type']"
hx-push-url="true"
hx-indicator="#search-spinner"
/>
<span class="ml-2 text-sm text-gray-700 dark:text-gray-300">Major Parks (10+ rides)</span>
</label>
</div>
</div>
</div>
<!-- Active Filter Chips -->
{% if active_filters %}
<div class="border-t border-gray-200 dark:border-gray-700 pt-4">
<c-filter_chips
filters=active_filters
base_url="{% url 'parks:park_list' %}"
class="flex-wrap"
/>
</div>
{% endif %}
</div>
</div>
<!-- Results Section -->
<div class="space-y-6">
<!-- Results Statistics -->
<c-result_stats
total_results="{{ total_results }}"
page_obj="{{ page_obj }}"
search_query="{{ search_query }}"
is_search="{{ is_search }}"
filter_count="{{ filter_count }}"
/>
<!-- Loading Overlay -->
<div id="loading-overlay" class="htmx-indicator">
<div class="fixed inset-0 bg-black bg-opacity-50 z-50 flex items-center justify-center">
<div class="bg-white dark:bg-gray-800 rounded-lg p-6 shadow-xl">
<div class="flex items-center space-x-3">
<svg class="animate-spin h-8 w-8 text-blue-600" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
</svg>
<span class="text-lg font-medium text-gray-900 dark:text-white">Loading parks...</span>
</div>
</div>
</div>
</div>
<!-- Park Results Container -->
<div id="park-results"
hx-indicator="#loading-overlay"
class="min-h-[400px]">
{% include "parks/partials/park_list.html" %}
</div>
</div>
</div>
{% endblock %}
<!-- AlpineJS State Management -->
<script>
function parkListState() {
return {
showFilters: window.innerWidth >= 1024, // Show on desktop by default
viewMode: '{{ view_mode }}',
searchQuery: '{{ search_query }}',
init() {
// Handle responsive filter visibility
this.handleResize();
window.addEventListener('resize', () => this.handleResize());
// Handle HTMX events
document.addEventListener('htmx:beforeRequest', () => {
this.setLoading(true);
});
document.addEventListener('htmx:afterRequest', () => {
this.setLoading(false);
});
document.addEventListener('htmx:responseError', () => {
this.setLoading(false);
this.showError('Failed to load results. Please try again.');
});
},
handleResize() {
if (window.innerWidth >= 1024) {
this.showFilters = true;
} else {
// Keep current state on mobile
}
},
setLoading(loading) {
// Additional loading state management if needed
},
showError(message) {
// Show error notification
console.error(message);
},
clearAllFilters() {
window.location.href = '{% url "parks:park_list" %}';
}
}
}
</script>
{% endblock %}

View File

@@ -0,0 +1,301 @@
{% extends "base/base.html" %}
{% load static %}
{% load cotton %}
{% block title %}Parks{% endblock %}
{% block content %}
<div class="container mx-auto px-4 py-6" x-data="parkListState()">
<!-- Enhanced Header Section -->
<div class="mb-8">
<div class="flex flex-col lg:flex-row lg:items-center lg:justify-between gap-4 mb-6">
<div>
<h1 class="text-3xl lg:text-4xl font-bold text-gray-900 dark:text-white">
Theme Parks
</h1>
<p class="mt-2 text-lg text-gray-600 dark:text-gray-400">
Discover amazing theme parks around the world
</p>
</div>
<!-- Quick Stats -->
<div class="flex items-center gap-6 text-sm text-gray-600 dark:text-gray-400">
<div class="text-center">
<div class="font-bold text-lg text-gray-900 dark:text-white">{{ filter_counts.total_parks|default:0 }}</div>
<div>Total Parks</div>
</div>
<div class="text-center">
<div class="font-bold text-lg text-gray-900 dark:text-white">{{ filter_counts.operating_parks|default:0 }}</div>
<div>Operating</div>
</div>
<div class="text-center">
<div class="font-bold text-lg text-gray-900 dark:text-white">{{ filter_counts.parks_with_coasters|default:0 }}</div>
<div>With Coasters</div>
</div>
</div>
</div>
</div>
<!-- Enhanced Search and Filter Bar -->
<div class="bg-white dark:bg-gray-800 rounded-xl shadow-lg border border-gray-200 dark:border-gray-700 p-6 mb-8">
<div class="space-y-6">
<!-- Main Search Row -->
<div class="flex flex-col lg:flex-row gap-4">
<!-- Enhanced Search Input -->
<div class="flex-1">
<c-enhanced_search
placeholder="Search parks by name, location, or features..."
current_value="{{ search_query }}"
autocomplete_url="{% url 'parks:park_autocomplete' %}"
class="w-full"
/>
</div>
<!-- Controls Row -->
<div class="flex items-center gap-3">
<!-- Sort Controls -->
<c-sort_controls
current_sort="{{ current_ordering }}"
class="min-w-0"
/>
<!-- View Toggle -->
<c-view_toggle
current_view="{{ view_mode }}"
class="flex-shrink-0"
/>
<!-- Filter Toggle Button (Mobile) -->
<button
type="button"
class="lg:hidden inline-flex items-center px-3 py-2 border border-gray-300 rounded-md shadow-sm bg-white text-sm font-medium text-gray-700 hover:bg-gray-50 dark:bg-gray-700 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-600"
@click="showFilters = !showFilters"
aria-label="Toggle filters"
>
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z" />
</svg>
<span class="ml-1">Filters</span>
</button>
</div>
</div>
<!-- Advanced Filters Row -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4"
x-show="showFilters"
x-transition:enter="transition ease-out duration-200"
x-transition:enter-start="opacity-0 transform scale-95"
x-transition:enter-end="opacity-100 transform scale-100"
x-transition:leave="transition ease-in duration-150"
x-transition:leave-start="opacity-100 transform scale-100"
x-transition:leave-end="opacity-0 transform scale-95">
<!-- Status Filter -->
<div>
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
Status
</label>
<select
name="status"
class="block w-full px-3 py-2 border border-gray-300 rounded-md bg-white text-gray-900 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:focus:ring-blue-500"
hx-get="{% url 'parks:park_list' %}"
hx-target="#park-results"
hx-include="[name='search'], [name='view_mode'], [name='ordering'], [name='operator'], [name='park_type']"
hx-push-url="true"
hx-indicator="#search-spinner"
>
<option value="">All Statuses</option>
<option value="OPERATING" {% if request.GET.status == 'OPERATING' %}selected{% endif %}>Operating</option>
<option value="CLOSED_TEMP" {% if request.GET.status == 'CLOSED_TEMP' %}selected{% endif %}>Temporarily Closed</option>
<option value="CLOSED_PERM" {% if request.GET.status == 'CLOSED_PERM' %}selected{% endif %}>Permanently Closed</option>
<option value="UNDER_CONSTRUCTION" {% if request.GET.status == 'UNDER_CONSTRUCTION' %}selected{% endif %}>Under Construction</option>
</select>
</div>
<!-- Operator Filter -->
<div>
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
Operator
</label>
<select
name="operator"
class="block w-full px-3 py-2 border border-gray-300 rounded-md bg-white text-gray-900 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:focus:ring-blue-500"
hx-get="{% url 'parks:park_list' %}"
hx-target="#park-results"
hx-include="[name='search'], [name='view_mode'], [name='ordering'], [name='status'], [name='park_type']"
hx-push-url="true"
hx-indicator="#search-spinner"
>
<option value="">All Operators</option>
{% for operator in filter_counts.top_operators %}
<option value="{{ operator.operator__id }}"
{% if request.GET.operator == operator.operator__id|stringformat:"s" %}selected{% endif %}>
{{ operator.operator__name }} ({{ operator.park_count }})
</option>
{% endfor %}
</select>
</div>
<!-- Park Type Filter -->
<div>
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
Park Type
</label>
<select
name="park_type"
class="block w-full px-3 py-2 border border-gray-300 rounded-md bg-white text-gray-900 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:focus:ring-blue-500"
hx-get="{% url 'parks:park_list' %}"
hx-target="#park-results"
hx-include="[name='search'], [name='view_mode'], [name='ordering'], [name='status'], [name='operator']"
hx-push-url="true"
hx-indicator="#search-spinner"
>
<option value="">All Types</option>
<option value="disney" {% if request.GET.park_type == 'disney' %}selected{% endif %}>Disney Parks</option>
<option value="universal" {% if request.GET.park_type == 'universal' %}selected{% endif %}>Universal Parks</option>
<option value="six_flags" {% if request.GET.park_type == 'six_flags' %}selected{% endif %}>Six Flags</option>
<option value="cedar_fair" {% if request.GET.park_type == 'cedar_fair' %}selected{% endif %}>Cedar Fair</option>
<option value="independent" {% if request.GET.park_type == 'independent' %}selected{% endif %}>Independent</option>
</select>
</div>
<!-- Quick Filters -->
<div>
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
Quick Filters
</label>
<div class="space-y-2">
<label class="flex items-center">
<input
type="checkbox"
name="has_coasters"
value="true"
{% if request.GET.has_coasters %}checked{% endif %}
class="rounded border-gray-300 text-blue-600 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700"
hx-get="{% url 'parks:park_list' %}"
hx-target="#park-results"
hx-include="[name='search'], [name='view_mode'], [name='ordering'], [name='status'], [name='operator'], [name='park_type']"
hx-push-url="true"
hx-indicator="#search-spinner"
/>
<span class="ml-2 text-sm text-gray-700 dark:text-gray-300">Has Roller Coasters</span>
</label>
<label class="flex items-center">
<input
type="checkbox"
name="big_parks_only"
value="true"
{% if request.GET.big_parks_only %}checked{% endif %}
class="rounded border-gray-300 text-blue-600 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700"
hx-get="{% url 'parks:park_list' %}"
hx-target="#park-results"
hx-include="[name='search'], [name='view_mode'], [name='ordering'], [name='status'], [name='operator'], [name='park_type']"
hx-push-url="true"
hx-indicator="#search-spinner"
/>
<span class="ml-2 text-sm text-gray-700 dark:text-gray-300">Major Parks (10+ rides)</span>
</label>
</div>
</div>
</div>
<!-- Active Filter Chips -->
{% if active_filters %}
<div class="border-t border-gray-200 dark:border-gray-700 pt-4">
<c-filter_chips
filters=active_filters
base_url="{% url 'parks:park_list' %}"
class="flex-wrap"
/>
</div>
{% endif %}
</div>
</div>
<!-- Results Section -->
<div class="space-y-6">
<!-- Results Statistics -->
<c-result_stats
total_results="{{ total_results }}"
page_obj="{{ page_obj }}"
search_query="{{ search_query }}"
is_search="{{ is_search }}"
filter_count="{{ filter_count }}"
/>
<!-- Loading Overlay -->
<div id="loading-overlay" class="htmx-indicator">
<div class="fixed inset-0 bg-black bg-opacity-50 z-50 flex items-center justify-center">
<div class="bg-white dark:bg-gray-800 rounded-lg p-6 shadow-xl">
<div class="flex items-center space-x-3">
<svg class="animate-spin h-8 w-8 text-blue-600" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
</svg>
<span class="text-lg font-medium text-gray-900 dark:text-white">Loading parks...</span>
</div>
</div>
</div>
</div>
<!-- Park Results Container -->
<div id="park-results"
hx-indicator="#loading-overlay"
class="min-h-[400px]">
{% include "parks/partials/park_list.html" %}
</div>
</div>
</div>
<!-- AlpineJS State Management -->
<script>
function parkListState() {
return {
showFilters: window.innerWidth >= 1024, // Show on desktop by default
viewMode: '{{ view_mode }}',
searchQuery: '{{ search_query }}',
init() {
// Handle responsive filter visibility
this.handleResize();
window.addEventListener('resize', () => this.handleResize());
// Handle HTMX events
document.addEventListener('htmx:beforeRequest', () => {
this.setLoading(true);
});
document.addEventListener('htmx:afterRequest', () => {
this.setLoading(false);
});
document.addEventListener('htmx:responseError', () => {
this.setLoading(false);
this.showError('Failed to load results. Please try again.');
});
},
handleResize() {
if (window.innerWidth >= 1024) {
this.showFilters = true;
} else {
// Keep current state on mobile
}
},
setLoading(loading) {
// Additional loading state management if needed
},
showError(message) {
// Show error notification
console.error(message);
},
clearAllFilters() {
window.location.href = '{% url "parks:park_list" %}';
}
}
}
</script>
{% endblock %}

View File

@@ -1,119 +1,27 @@
{% load cotton %}
{% if view_mode == 'list' %}
<!-- Parks List View -->
<div class="space-y-4">
{% for park in parks %}
<div class="bg-white rounded-lg shadow-lg dark:bg-gray-800 overflow-hidden">
<div class="flex flex-col md:flex-row">
{% if park.photos.exists %}
<div class="md:w-48 md:flex-shrink-0">
<img src="{{ park.photos.first.image.url }}"
alt="{{ park.name }}"
class="w-full h-48 md:h-full object-cover">
</div>
{% endif %}
<div class="flex-1 p-6">
<div class="flex flex-col md:flex-row md:items-start md:justify-between">
<div class="flex-1">
<h2 class="text-2xl font-bold mb-2">
<a href="{% url 'parks:park_detail' park.slug %}"
class="text-gray-900 hover:text-blue-600 dark:text-white dark:hover:text-blue-400">
{{ park.name }}
</a>
</h2>
{% if park.city or park.state or park.country %}
<p class="text-gray-600 dark:text-gray-400 mb-3">
<i class="mr-1 fas fa-map-marker-alt"></i>
{% spaceless %}
{% if park.city %}{{ park.city }}{% endif %}{% if park.city and park.state %}, {% endif %}{% if park.state %}{{ park.state }}{% endif %}{% if park.country and park.state or park.city %}, {% endif %}{% if park.country %}{{ park.country }}{% endif %}
{% endspaceless %}
</p>
{% endif %}
{% if park.operator %}
<p class="text-blue-600 dark:text-blue-400 mb-3">
{{ park.operator.name }}
</p>
{% endif %}
</div>
<div class="flex flex-col items-start md:items-end gap-2 mt-4 md:mt-0">
<span class="status-badge {% if park.status == 'OPERATING' %}status-operating
{% elif park.status == 'CLOSED_TEMP' or park.status == 'CLOSED_PERM' %}status-closed
{% elif park.status == 'UNDER_CONSTRUCTION' %}status-construction
{% elif park.status == 'DEMOLISHED' %}status-demolished
{% elif park.status == 'RELOCATED' %}status-relocated{% endif %}">
{{ park.get_status_display }}
</span>
{% if park.average_rating %}
<span class="text-yellow-800 bg-yellow-100 status-badge dark:bg-yellow-400/30 dark:text-yellow-200 dark:ring-1 dark:ring-yellow-400/30">
<i class="mr-1 text-yellow-500 fas fa-star dark:text-yellow-300"></i>
{{ park.average_rating|floatformat:1 }}/10
</span>
{% endif %}
</div>
</div>
</div>
<!-- Parks List View -->
<div class="space-y-4">
{% for park in parks %}
<c-park_card park=park view_mode="list" />
{% empty %}
<div class="py-8 text-center">
<p class="text-gray-500 dark:text-gray-400">No parks found matching your criteria.</p>
</div>
</div>
{% empty %}
<div class="py-8 text-center">
<p class="text-gray-500 dark:text-gray-400">No parks found matching your criteria.</p>
</div>
{% endfor %}
</div>
{% endfor %}
</div>
{% else %}
<!-- Parks Grid View -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
{% for park in parks %}
<div class="overflow-hidden transition-transform transform bg-white rounded-lg shadow-lg dark:bg-gray-800 hover:-translate-y-1">
{% if park.photos.exists %}
<div class="aspect-w-16 aspect-h-9">
<img src="{{ park.photos.first.image.url }}"
alt="{{ park.name }}"
class="object-cover w-full h-48">
</div>
{% endif %}
<div class="p-4">
<h2 class="mb-2 text-xl font-bold">
<a href="{% url 'parks:park_detail' park.slug %}"
class="text-gray-900 hover:text-blue-600 dark:text-white dark:hover:text-blue-400">
{{ park.name }}
</a>
</h2>
{% if park.city or park.state or park.country %}
<p class="mb-3 text-gray-600 dark:text-gray-400">
<i class="mr-1 fas fa-map-marker-alt"></i>
{% spaceless %}
{% if park.city %}{{ park.city }}{% endif %}{% if park.city and park.state %}, {% endif %}{% if park.state %}{{ park.state }}{% endif %}{% if park.country and park.state or park.city %}, {% endif %}{% if park.country %}{{ park.country }}{% endif %}
{% endspaceless %}
</p>
{% endif %}
<div class="flex flex-wrap gap-2">
<span class="status-badge {% if park.status == 'OPERATING' %}status-operating
{% elif park.status == 'CLOSED_TEMP' or park.status == 'CLOSED_PERM' %}status-closed
{% elif park.status == 'UNDER_CONSTRUCTION' %}status-construction
{% elif park.status == 'DEMOLISHED' %}status-demolished
{% elif park.status == 'RELOCATED' %}status-relocated{% endif %}">
{{ park.get_status_display }}
</span>
{% if park.average_rating %}
<span class="text-yellow-800 bg-yellow-100 status-badge dark:bg-yellow-400/30 dark:text-yellow-200 dark:ring-1 dark:ring-yellow-400/30">
<i class="mr-1 text-yellow-500 fas fa-star dark:text-yellow-300"></i>
{{ park.average_rating|floatformat:1 }}/10
</span>
{% endif %}
</div>
{% if park.operator %}
<div class="mt-4 text-sm text-blue-600 dark:text-blue-400">
{{ park.operator.name }}
</div>
{% endif %}
<!-- Parks Grid View -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
{% for park in parks %}
<c-park_card park=park view_mode="grid" />
{% empty %}
<div class="col-span-full py-8 text-center">
<p class="text-gray-500 dark:text-gray-400">No parks found matching your criteria.</p>
</div>
</div>
{% empty %}
<div class="col-span-full py-8 text-center">
<p class="text-gray-500 dark:text-gray-400">No parks found matching your criteria.</p>
</div>
{% endfor %}
</div>
{% endfor %}
</div>
{% endif %}
<!-- Pagination -->