Skip to content
This repository was archived by the owner on Apr 15, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/MapView.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useHistory } from "react-router-dom";
import "./App.css";

export default function MapView({ restaurants }) {
const [activePark, setActivePark] = React.useState(null);
let history = useHistory();

return (
Expand All @@ -19,13 +20,34 @@ export default function MapView({ restaurants }) {
restaurant.geometry.location.lat,
restaurant.geometry.location.lng,
]}
// onClick={() => {
// setActivePark(restaurant);
// }}
eventHandlers={{
click: () => {
history.push(`/restaurants/berlin/${restaurant.id}`);
},
}}
/>
))}

{/* {activePark && (
<Popup
position={[
restaurant.geometry.location.lat,
restaurant.geometry.location.lng,
]}
onClose={() => {
setActivePark(null);
}}
>
<div>
<h2>{activePark.name}</h2>
<p>{activePark.formatted_address}</p>
<p>Rating: {activePark.rating}</p>
</div>
</Popup>
)} */}
</MapContainer>
);
}
34 changes: 23 additions & 11 deletions src/components/Filters.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
import React from "react";
import React, { useState, useEffect } from "react";

const Filters = ({ restaurants }) => {
const [selectedPrice, setSelectedPrice] = useState();
const [resto, setResto] = useState([]);

useEffect(() => {
const result = restaurants.filter(
(item) => item.price_level == selectedPrice
);
setResto(result);
}, [selectedPrice]);

const handleGameChange = (e) => {
setSelectedPrice(e.target.value);
};

console.log("resto: ", resto, resto.length);

const Filters = ({
selectedFilters,
setSelectedFilter,
handleChange,
resto,
}) => {
return (
<div className="filterArea">
<div className="selectWrapper">
<select className="filterSelect" onChange={handleChange}>
<select className="filterSelect" onChange={handleGameChange}>
<option default>Price</option>
<option value="1">$</option>
<option value="2">$$</option>
<option value="3">$$$</option>
<option value="4">$$$$</option>
</select>
<select className="filterSelect" onChange={handleChange}>
<select className="filterSelect">
<option default>Open Now</option>
<option value="true">Open</option>
<option value="1">$</option>
<option value="2">$$</option>
<option value="3">$$$</option>
</select>
<select className="filterSelect">
<option default>By rating</option>
Expand Down
22 changes: 10 additions & 12 deletions src/components/RestaurantListings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@ import RestaurantCard from "./RestaurantCard";

const RestaurantListings = ({ restaurants }) => {
return (
<>
<div className="results-for-restaurants">
<div className="sectionTitle">
<h2 style={{ marginBottom: "10px", marginLeft: "15px" }}>
Restaurants in Berlin{" "}
</h2>
{restaurants && (
<h2 style={{ marginBottom: "10px", marginLeft: "15px" }}>
Restaurants in Berlin{" "}
</h2>
)}
</div>

<div className="results-for-restaurants">
{restaurants &&
restaurants.map((restaurant) => (
<RestaurantCard key={restaurant.id} restaurant={restaurant} />
))}
</div>
</>
{restaurants.map((restaurant) => (
<RestaurantCard key={restaurant.id} restaurant={restaurant} />
))}
</div>
);
};

Expand Down
28 changes: 3 additions & 25 deletions src/components/Restaurants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect, useContext } from "react";
import React, { useEffect, useContext } from "react";
import "../restaurantsStyle.css";
import Header from "./Header";
import Filters from "./Filters";
Expand All @@ -11,20 +11,6 @@ import RestaurantsContext from "../contexts/restaurantsContext";
const Restaurants = ({ logo }) => {
const { restaurants, setRestaurants } = useContext(RestaurantsContext);

const [selectedFilters, setSelectedFilters] = useState({});
const [resto, setResto] = useState([]);

useEffect(() => {
const result = restaurants.filter(
(item) => item.price_level == selectedFilters
);
setResto(result);
}, [selectedFilters]);

const handleChange = (e) => {
setSelectedFilters(e.target.value);
};

useEffect(() => {
(async () => {
const response = await fetch(
Expand All @@ -42,16 +28,8 @@ const Restaurants = ({ logo }) => {
<Header logo={logo} />
<div id="resultsDiv">
<div id="listOfRestautants">
<Filters
selectedFilters={selectedFilters}
setSelectedFilters={setSelectedFilters}
handleChange={handleChange}
resto={resto}
/>
{resto.length >= 1 && <RestaurantListings restaurants={resto} />}
{resto.length === 0 && (
<RestaurantListings restaurants={restaurants} />
)}
<Filters restaurants={restaurants} />
<RestaurantListings restaurants={restaurants} />
<TopRated restaurants={restaurants} />
</div>
<div className="mapView">
Expand Down