'use client'; import { useEffect, useState } from 'react'; import L from 'leaflet'; import { MapContainer, TileLayer, Marker, Popup, useMap } from 'react-leaflet'; import 'leaflet/dist/leaflet.css'; import { Star, ThumbsUp, ThumbsDown, MessageSquare } from 'lucide-react'; import { Restaurant } from '@/lib/api'; // Fix for default markers in React-Leaflet interface LeafletIconDefault extends L.Icon.Default { _getIconUrl?: string; } if (typeof window !== 'undefined') { const iconDefault = L.Icon.Default.prototype as LeafletIconDefault; delete iconDefault._getIconUrl; L.Icon.Default.mergeOptions({ iconRetinaUrl: '/leaflet/marker-icon-2x.png', iconUrl: '/leaflet/marker-icon.png', shadowUrl: '/leaflet/marker-shadow.png', }); } interface MapProps { center: { lat: number; lng: number }; restaurants: Restaurant[]; onRestaurantClick: (restaurant: Restaurant) => void; onToastStatusUpdate: (restaurantId: number, hasToast: boolean) => void; } // Component to recenter map when location changes function RecenterMap({ center }: { center: { lat: number; lng: number } }) { const map = useMap(); useEffect(() => { map.setView([center.lat, center.lng], 13); }, [center, map]); return null; } export default function Map({ center, restaurants, onRestaurantClick, onToastStatusUpdate }: MapProps) { const [mounted, setMounted] = useState(false); useEffect(() => { setMounted(true); }, []); if (!mounted) { return
; } // Create icons based on toast status const createRestaurantIcon = (hasToast: boolean | null) => { let iconContent = ''; let bgColor = ''; if (hasToast === null) { // Unknown status - gray question mark iconContent = '❓'; bgColor = '#9CA3AF'; // gray-400 } else if (hasToast) { // Has toast - green toast iconContent = '🍞'; bgColor = '#10B981'; // green-500 } else { // No toast - red X iconContent = '❌'; bgColor = '#EF4444'; // red-500 } return new L.Icon({ iconUrl: 'data:image/svg+xml,' + encodeURIComponent(` `), iconSize: [40, 40], iconAnchor: [20, 40], popupAnchor: [0, -40], }); }; const userIcon = new L.Icon({ iconUrl: 'data:image/svg+xml,' + encodeURIComponent(` `), iconSize: [30, 30], iconAnchor: [15, 15], }); return (You are here!
Ready to find some toast? 🍞
{restaurant.address}
{/* Toast status */}{restaurant.has_toast === null && "🤔 Does this place have toast?"} {restaurant.has_toast === true && "✅ This place serves toast!"} {restaurant.has_toast === false && "❌ No toast here"}
{/* Toast voting buttons */}
No ratings yet
)} {/* Review button */}