Ignore:
Timestamp:
03/03/24 10:52:49 (15 months ago)
Author:
Aleksandar Panovski <apano77@…>
Branches:
main
Children:
c63036a
Parents:
75f5086
Message:

RetaurantServiceImpl problemi
isAvailable od tableEntity...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • my-react-app/src/components/Restaurants.js

    r75f5086 rcfc16a3  
    1 import React, { useState, useEffect } from 'react';
    2 import axios from 'axios';
     1import React, {useState, useEffect, useContext} from 'react';
    32import 'bootstrap/dist/css/bootstrap.min.css';
    43import StarRating from './StarRating';
    54import { useNavigate } from 'react-router-dom';
     5import {RestaurantContext} from "./RestaurantContext";
    66
    77const Restaurants = () => {
    88    const [restaurants, setRestaurants] = useState([]);
    99    const navigate = useNavigate();
     10    const restaurantContext = useContext(RestaurantContext);
    1011
    1112    useEffect(() => {
    12         const fetchRestaurants = async () => {
    13             try {
    14                 const response = await axios.get('http://localhost:8080/api/restaurants');
    15                 setRestaurants(response.data);
    16             } catch (error) {
    17                 console.error('Error fetching restaurants:', error);
    18             }
    19         };
    20 
    21         fetchRestaurants();
    22     }, []);
     13        setRestaurants(restaurantContext.restaurants);
     14    }, [restaurantContext]);
    2315
    2416    const handleDetailClick = (restaurantId) => {
     
    9890                                </div>
    9991                            </div>
    100                             <button onClick={() => handleDetailClick(restaurant.restaurantId)} className="btn btn-primary">View Details</button>
     92                            <button onClick={() => handleDetailClick(restaurant.restaurantId)}
     93                                    className="btn btn-primary">View Details
     94                            </button>
    10195                        </div>
    10296                    </div>
Note: See TracChangeset for help on using the changeset viewer.