import React, {useState, useEffect, useContext} from 'react'; import 'bootstrap/dist/css/bootstrap.min.css'; import StarRating from './StarRating'; import { useNavigate } from 'react-router-dom'; import {RestaurantContext} from "./RestaurantContext"; const Restaurants = () => { const [restaurants, setRestaurants] = useState([]); const navigate = useNavigate(); const restaurantContext = useContext(RestaurantContext); useEffect(() => { setRestaurants(restaurantContext.restaurants); }, [restaurantContext]); 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}