|
1 | | -import React from "react"; |
2 | | -import { useParams } from "react-router-dom"; |
3 | | -import { Container, Row, Col } from "react-bootstrap"; |
| 1 | +import React, { useState, useEffect } from "react"; |
| 2 | +import { useParams, useNavigate } from "react-router-dom"; |
| 3 | +import { Container, Row, Col, Alert, Button } from "react-bootstrap"; |
4 | 4 | import NavigationBar from "../components/NavigationBar"; |
5 | 5 | import RestaurantDetailPanel from "../components/ResturantDetailPanel"; |
6 | | - |
7 | | -// TEMP dummy data – replace later if your group has real data |
8 | | -const dummyRestaurants = [ |
9 | | - { |
10 | | - id: 1, |
11 | | - name: "Mickies Dairy Bar", |
12 | | - rating: 4.6, |
13 | | - tags: ["Brunch", "American"], |
14 | | - address: "123 Monroe St, Madison, WI", |
15 | | - hours: "8:00 AM – 2:00 PM", |
16 | | - description: "Classic Madison brunch spot with huge portions. Known for their famous scrambler and friendly service.", |
17 | | - image: "https://images.unsplash.com/photo-1533777857889-4be7c70b33f7?w=800&h=600&fit=crop", |
18 | | - imageAlt: "Delicious brunch plate with eggs, bacon, and toast at Mickies Dairy Bar" |
19 | | - }, |
20 | | - { |
21 | | - id: 2, |
22 | | - name: "Village Pizza", |
23 | | - rating: 4.3, |
24 | | - tags: ["Pizza", "Italian"], |
25 | | - address: "456 State St, Madison, WI", |
26 | | - hours: "11:00 AM – 10:00 PM", |
27 | | - description: "Casual pizza place great for group dinners. Authentic Italian recipes with fresh ingredients.", |
28 | | - image: "https://images.unsplash.com/photo-1513104890138-7c749659a591?w=800&h=600&fit=crop", |
29 | | - imageAlt: "Fresh Italian pizza with melted cheese and basil" |
30 | | - }, |
31 | | -]; |
| 6 | +import LoadingSpinner from "../components/LoadingSpinner"; |
| 7 | +import { supabase } from "../lib/supabase"; |
32 | 8 |
|
33 | 9 | export default function RestaurantPage() { |
34 | 10 | const { restaurantId } = useParams(); |
| 11 | + const navigate = useNavigate(); |
| 12 | + const [restaurant, setRestaurant] = useState(null); |
| 13 | + const [loading, setLoading] = useState(true); |
| 14 | + const [error, setError] = useState(""); |
35 | 15 |
|
36 | | - const restaurant = dummyRestaurants.find( |
37 | | - (r) => String(r.id) === String(restaurantId) |
38 | | - ); |
| 16 | + useEffect(() => { |
| 17 | + const fetchRestaurant = async () => { |
| 18 | + try { |
| 19 | + const { data, error } = await supabase |
| 20 | + .from('restaurants') |
| 21 | + .select('*') |
| 22 | + .eq('id', restaurantId) |
| 23 | + .single(); |
| 24 | + |
| 25 | + if (error) throw error; |
| 26 | + setRestaurant(data); |
| 27 | + } catch (err) { |
| 28 | + setError(err.message); |
| 29 | + } finally { |
| 30 | + setLoading(false); |
| 31 | + } |
| 32 | + }; |
| 33 | + |
| 34 | + fetchRestaurant(); |
| 35 | + }, [restaurantId]); |
| 36 | + |
| 37 | + if (loading) { |
| 38 | + return ( |
| 39 | + <> |
| 40 | + <NavigationBar /> |
| 41 | + <LoadingSpinner message="Loading restaurant..." /> |
| 42 | + </> |
| 43 | + ); |
| 44 | + } |
39 | 45 |
|
40 | | - if (!restaurant) { |
| 46 | + if (error || !restaurant) { |
41 | 47 | return ( |
42 | 48 | <> |
43 | 49 | <NavigationBar /> |
44 | 50 | <Container className="py-4"> |
45 | | - <p>Restaurant not found.</p> |
| 51 | + <Alert variant="danger"> |
| 52 | + {error || "Restaurant not found."} |
| 53 | + </Alert> |
| 54 | + <Button onClick={() => navigate("/")}>Back to Home</Button> |
46 | 55 | </Container> |
47 | 56 | </> |
48 | 57 | ); |
|
0 commit comments