import React, { useState, useEffect } from 'react'; import axios from 'axios'; import 'bootstrap/dist/css/bootstrap.min.css'; import StarRating from './StarRating'; import { useNavigate } from 'react-router-dom'; const Restaurants = () => { const [restaurants, setRestaurants] = useState([]); const navigate = useNavigate(); useEffect(() => { const fetchRestaurants = async () => { try { const response = await axios.get('http://localhost:8080/api/restaurants'); setRestaurants(response.data); } catch (error) { console.error('Error fetching restaurants:', error); } }; fetchRestaurants(); }, []); const handleDetailClick = (restaurantId) => { navigate(`/restaurants/${restaurantId}`); } const handleTimeSlotClick = (table, timeSlot, restaurant) => { const tableNumber = table.id; const formattedTimeSlot = timeSlot; const restaurantId = restaurant.restaurantId; const encodedTableNumber = encodeURI(tableNumber); const encodedTimeSlot = encodeURIComponent(formattedTimeSlot); const encodedRestaurantId = encodeURIComponent(restaurantId); navigate(`/reservationConfirmation/${encodedTableNumber}/${encodedTimeSlot}/${encodedRestaurantId}`); } const renderTimeSlots = (tablesList, restaurant) => { const currentTime = new Date().getTime(); let renderedTimeSlots = {}; // Object to store rendered slots for each table capacity return tablesList.flatMap(table => { // Render capacity header when encountering a new capacity if (!renderedTimeSlots[table.capacity]) { renderedTimeSlots[table.capacity] = 0; return (
{restaurant.cuisineType}
{restaurant.operatingHours}
Ul. {restaurant.address}