Park Operators
Discover companies that operate theme parks
Loading park operators...
No park operators found
{searchTerm ? "Try adjusting your search terms or filters" : "No park operators are currently available" }
import React, { useState } from 'react'; import { useQuery } from '@tanstack/react-query'; import { Header } from '@/components/layout/Header'; import { Input } from '@/components/ui/input'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { Search, Filter, Building } from 'lucide-react'; import { supabase } from '@/integrations/supabase/client'; import OperatorCard from '@/components/operators/OperatorCard'; import { Company } from '@/types/database'; const Operators = () => { const [searchTerm, setSearchTerm] = useState(''); const [sortBy, setSortBy] = useState('name'); const [filterBy, setFilterBy] = useState('all'); const { data: operators, isLoading } = useQuery({ queryKey: ['operators'], queryFn: async () => { // Get companies that are park operators with park counts const { data, error } = await supabase .from('companies') .select(` *, parks:parks!operator_id(count) `) .in('id', await supabase .from('parks') .select('operator_id') .not('operator_id', 'is', null) .then(({ data }) => data?.map(park => park.operator_id) || []) ) .order('name'); if (error) throw error; // Transform the data to include park_count const transformedData = data?.map(company => ({ ...company, park_count: company.parks?.[0]?.count || 0 })) || []; return transformedData as (Company & { park_count: number })[]; }, }); const filteredAndSortedOperators = React.useMemo(() => { if (!operators) return []; let filtered = operators.filter(operator => { const matchesSearch = operator.name.toLowerCase().includes(searchTerm.toLowerCase()) || (operator.description && operator.description.toLowerCase().includes(searchTerm.toLowerCase())); if (filterBy === 'all') return matchesSearch; if (filterBy === 'with-rating') return matchesSearch && operator.average_rating > 0; if (filterBy === 'established') return matchesSearch && operator.founded_year; return matchesSearch; }); // Sort filtered.sort((a, b) => { switch (sortBy) { case 'name': return a.name.localeCompare(b.name); case 'rating': return (b.average_rating || 0) - (a.average_rating || 0); case 'founded': return (b.founded_year || 0) - (a.founded_year || 0); case 'reviews': return (b.review_count || 0) - (a.review_count || 0); default: return 0; } }); return filtered; }, [operators, searchTerm, sortBy, filterBy]); return (
Discover companies that operate theme parks
Loading park operators...
{searchTerm ? "Try adjusting your search terms or filters" : "No park operators are currently available" }