-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d696333
commit 86dfbc4
Showing
9 changed files
with
157,484 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import React from "react"; | ||
// import RestaurantCard from "./RestaurantCard"; | ||
import { useState, useEffect } from "react"; | ||
import Shimmer from "./Shimmer"; | ||
import { Link } from "react-router-dom"; | ||
import { filterData } from "../utils/helper.js"; | ||
import { ALL_RESTAURANTS_LIST } from "../mocks/mockData"; | ||
import BodyCard from './BodyCard'; | ||
|
||
function Body() { | ||
|
||
|
||
|
||
const [allRestaurants, setAllRestaurants] = useState([]); | ||
const [filteredRestaurants, setFilteredRestaurants] = useState([]); | ||
const [searchText, setSearchText] = useState(""); | ||
|
||
// const { user, setUser } = useContext(UserContext); | ||
|
||
useEffect(() => { | ||
setFilteredRestaurants(ALL_RESTAURANTS_LIST); | ||
//api call | ||
// getRestaurants(setAllRestaurants, setFilteredRestaurants); | ||
}, []); | ||
|
||
useEffect(() => { | ||
const data = filterData(searchText, ALL_RESTAURANTS_LIST); | ||
// update the state - restaurants | ||
setFilteredRestaurants(data); | ||
}, [searchText]); | ||
|
||
//early return | ||
if (!ALL_RESTAURANTS_LIST) return null; | ||
|
||
return ALL_RESTAURANTS_LIST?.length === 0 ? ( | ||
<Shimmer /> | ||
) : ( | ||
<div className="flex flex-col"> | ||
<div className="p-4 text-center mt-24"> | ||
<input | ||
data-testid="search-input" | ||
type="text" | ||
className="mx-3 p-2 px-2 w-96 border border-gray-300 rounded-md focus:outline-none " | ||
placeholder="Search" | ||
value={searchText} | ||
onChange={(e) => { | ||
//e.target.value is whatever i write | ||
setSearchText(e.target.value); | ||
}} | ||
/> | ||
|
||
<button | ||
data-testid="search-btn" | ||
className=" p-2 px-4 bg-gray-700 text-white rounded-md hover:shadow-md max-sm:hidden" | ||
onClick={() => { | ||
//need to filter the data | ||
const data = filterData(searchText, allRestaurants); | ||
// update the state - restaurants | ||
setFilteredRestaurants(data); | ||
}} | ||
> | ||
Search | ||
</button> | ||
</div> | ||
|
||
{/* <input | ||
className="border" | ||
onChange={(e) => | ||
setUser({ | ||
name: e.target.value, | ||
email: "dummy@gmail.com", | ||
}) | ||
} | ||
/> */} | ||
|
||
<div | ||
className=" sm:flex flex-wrap m-0 p-0 justify-center " | ||
data-testid="res-list" | ||
> | ||
{filteredRestaurants.map((restaurant) => { | ||
return ( | ||
<Link | ||
to={`/restaurant/${restaurant.data.id}`} | ||
key={restaurant.data.id} | ||
className="res-cards " | ||
> | ||
<BodyCard {...restaurant.data} /> | ||
</Link> | ||
); | ||
})} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default Body; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from "react"; | ||
import { IMG_CDN_URL, NO_IMAGE_AVAILABLE } from "../constants"; | ||
|
||
const BodyCard = ({ | ||
name, | ||
cuisines, | ||
cloudinaryImageId, | ||
lastMileTravelString, | ||
}) => { | ||
return ( | ||
<div className="w-56 p-4 m-3 h-72 border border-gray-100 bg-gray rounded-md hover:shadow-lg bg-gray-50 "> | ||
<img | ||
className="rounded-md" | ||
src={ | ||
!cloudinaryImageId | ||
? NO_IMAGE_AVAILABLE | ||
: IMG_CDN_URL + cloudinaryImageId | ||
} | ||
/> | ||
|
||
<h2 className="text-xl font-semibold py-1">{name}</h2> | ||
<h3 className="cuisines text-sm text-gray-500 ">{cuisines.join(", ")}</h3> | ||
<h4 className="distance text-sm">📍 {lastMileTravelString} away</h4> | ||
</div> | ||
); | ||
}; | ||
|
||
export default BodyCard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default "http://localhost/dummyImage.png"; |
Oops, something went wrong.
86dfbc4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
goodfoods – ./
goodfoods.vercel.app
goodfoods-sjuber608-gmailcom.vercel.app
goodfoods-git-main-sjuber608-gmailcom.vercel.app