- Implemented park card component with image, status badge, favorite button, and quick stats overlay. - Developed ride card component featuring thrill level badge, status badge, favorite button, and detailed stats. - Created advanced search page with filters for parks and rides, including location, type, status, and thrill level. - Added dynamic quick search functionality with results display. - Enhanced user experience with JavaScript for filter toggling, range slider updates, and view switching. - Included custom CSS for improved styling of checkboxes and search results layout.
6.2 KiB
ThrillWiki Frontend JavaScript Refactoring Plan
Date: 2025-01-15
Status: In Progress
Priority: CRITICAL
Overview
Refactoring ThrillWiki frontend to comply with the core rule: "🚨 ABSOLUTELY NO Custom JS - HTMX + AlpineJS ONLY". The audit identified 20 custom JavaScript files that need to be removed and their functionality migrated to HTMX endpoints and AlpineJS components in templates.
Current Violations
Custom JavaScript Files to Remove (19 files):
static/js/thrillwiki-enhanced.js(600+ lines) - ❌ REMOVEstatic/js/alpine-components.js(500+ lines) - ⚠️ REFACTOR (contains valid AlpineJS components)static/js/alerts.js- ❌ REMOVEstatic/js/dark-mode-maps.js- ❌ REMOVEstatic/js/geolocation.js- ❌ REMOVEstatic/js/htmx-maps.js- ❌ REMOVEstatic/js/location-autocomplete.js- ❌ REMOVEstatic/js/location-search.js- ❌ REMOVEstatic/js/main.js- ❌ REMOVEstatic/js/map-filters.js- ❌ REMOVEstatic/js/map-integration.js- ❌ REMOVEstatic/js/map-markers.js- ❌ REMOVEstatic/js/maps.js- ❌ REMOVEstatic/js/mobile-touch.js- ❌ REMOVEstatic/js/park-map.js- ❌ REMOVEstatic/js/photo-gallery.js- ❌ REMOVEstatic/js/roadtrip.js- ❌ REMOVEstatic/js/search.js- ❌ REMOVEstatic/js/theme.js- ❌ REMOVE
Files to Keep:
static/js/alpine.min.js- ✅ KEEP (AlpineJS library)
Functionality Migration Strategy
1. AlpineJS Components (from alpine-components.js)
Action: Move to inline <script> tags in templates or create Cotton components
Components to Migrate:
themeToggle→ Move to header templatesearchComponent→ Move to search templatesbrowseMenu→ Move to header templatemobileMenu→ Move to header templateuserMenu→ Move to header templatemodal→ Create Cotton modal componentdropdown→ Create Cotton dropdown componenttabs→ Create Cotton tabs componentaccordion→ Create Cotton accordion componentform→ Move to form templatespagination→ Create Cotton pagination componentauthModal→ Move to auth modal template- Global stores (
app,toast) → Move to base template
2. Search Functionality (from thrillwiki-enhanced.js, search.js)
Action: Replace with HTMX endpoints
Current Custom JS:
- Quick search with debouncing
- Search result parsing
- Search suggestions
HTMX Solution:
- Use
hx-getwithhx-trigger="keyup changed delay:300ms" - Server returns HTML fragments
- Use
hx-targetandhx-swapfor results
3. Card Interactions (from thrillwiki-enhanced.js)
Action: Replace with CSS hover effects and AlpineJS
Current Custom JS:
- Card hover animations
- Favorite button toggles
- Card image scaling
Solution:
- CSS transitions for hover effects
- AlpineJS for favorite toggles
- HTMX for favorite API calls
4. Notifications (from thrillwiki-enhanced.js)
Action: Use AlpineJS store and Cotton components
Current Custom JS:
- Custom notification system
- Auto-hide functionality
- Animation handling
Solution:
- AlpineJS
toaststore (already exists in alpine-components.js) - Cotton toast component
- CSS animations
5. Form Handling (from thrillwiki-enhanced.js)
Action: Use HTMX form submissions
Current Custom JS:
- Form validation
- Error display
- Loading states
Solution:
- Server-side validation
- HTMX form submissions
- AlpineJS for client-side enhancements
6. Scroll Effects (from thrillwiki-enhanced.js)
Action: Use CSS and minimal AlpineJS
Current Custom JS:
- Parallax effects
- Reveal animations
- Scroll to top button
Solution:
- CSS scroll-driven animations
- Intersection Observer in AlpineJS
- CSS-only scroll to top
7. Theme Handling (from theme.js)
Action: Move to AlpineJS component in base template
Current Custom JS:
- Theme switching
- System theme detection
- Local storage management
Solution:
- AlpineJS
themeTogglecomponent (already exists) - Move to base template
Implementation Steps
Phase 1: Preserve Critical Functionality
- ✅ Extract AlpineJS components from alpine-components.js
- ✅ Move theme toggle to base template
- ✅ Move search components to search templates
- ✅ Move auth modal components to auth templates
- ✅ Create Cotton components for reusable UI elements
Phase 2: Replace Custom JavaScript
- ✅ Remove custom JavaScript files
- ✅ Update base.html to remove script references
- ✅ Test functionality after removal
Phase 3: HTMX Integration
- ✅ Replace search functionality with HTMX endpoints
- ✅ Replace form submissions with HTMX
- ✅ Replace favorite toggles with HTMX
Phase 4: CSS Enhancements
- ✅ Replace JavaScript animations with CSS
- ✅ Add CSS hover effects for cards
- ✅ Implement CSS scroll effects
Phase 5: Testing & Validation
- ✅ Test all functionality works without custom JS
- ✅ Verify HTMX interactions
- ✅ Validate AlpineJS components
- ✅ Performance testing
Risk Mitigation
Backup Strategy
- Keep removed JS files in a backup directory temporarily
- Test each component migration individually
- Rollback plan if critical functionality breaks
Testing Checklist
- Search functionality works
- Authentication modal works
- Theme switching works
- Card interactions work
- Form submissions work
- Mobile menu works
- Notifications work
- Pagination works
Expected Outcomes
Compliance
- ✅ Zero custom JavaScript files
- ✅ HTMX + AlpineJS only architecture
- ✅ Progressive enhancement maintained
Performance
- ⬆️ Reduced JavaScript bundle size
- ⬆️ Faster page loads
- ⬆️ Better caching
Maintainability
- ⬆️ Simpler architecture
- ⬆️ Better separation of concerns
- ⬆️ Easier debugging
Notes
- The
alpine-components.jsfile contains valid AlpineJS components that should be preserved - Theme switching is critical functionality that must be maintained
- Search functionality is core to the user experience
- Authentication modal is essential for user management
- All functionality must work without JavaScript (progressive enhancement)
Last Updated: 2025-01-15