Skip to content

Commit

Permalink
useRestaurantList updated
Browse files Browse the repository at this point in the history
  • Loading branch information
haddercone committed Jan 11, 2024
1 parent 7635c41 commit 8039992
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 73 deletions.
2 changes: 1 addition & 1 deletion src/components/Body.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const Body = () => {
No restaurant found...
</p>
) : (
restaurants.map((restaurant, index) => {
restaurants && restaurants.map((restaurant, index) => {
{
if (restaurants.length === index + 1) {
return (
Expand Down
2 changes: 0 additions & 2 deletions src/components/RestaurantMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ const RestaurantMenu = () => {
<MenuShimmer />
) : (
<>
{/* {console.log(res[2]?.groupedCard?.cardGroupMap?.REGULAR.cards)} */}
<RestaurantProfile {...restaurantProfileData} />
{/* {console.log(menuData)} */}
{menuData &&
menuData.map((menu) => {
const menuCard = menu?.card?.card;
Expand Down
131 changes: 65 additions & 66 deletions src/components/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,76 +3,75 @@ import { filteredRestaurants } from "../utils/helpers";
import { Link } from "react-router-dom";

const Search = ({ restaurants, actualData, setRestaurants }) => {
const [searchText, setSearchText] = useState("");
const [suggestions, setSuggestions] = useState([]);
const [searchText, setSearchText] = useState("");
const [suggestions, setSuggestions] = useState([]);

const handleOnsubmit = (e) => {
e.preventDefault();
};
useEffect(() => {
if (searchText === "") {
setSuggestions([]);
return;
}
const timer = setTimeout(() => {
const data = filteredRestaurants(searchText, actualData);
setSuggestions(data);
}, 200);
const handleOnsubmit = (e) => {
e.preventDefault();
};
useEffect(() => {
if (searchText === "") {
setSuggestions([]);
return;
}
const timer = setTimeout(() => {
const data = filteredRestaurants(searchText, actualData);
setSuggestions(data);
}, 200);

return () => {
return clearTimeout(timer);
};
}, [searchText]);
return () => {
return clearTimeout(timer);
};
}, [searchText]);

const handleOnchange = (e) => {
setSearchText(e.target.value);
};
const handelOnBlur = () => {
const timer = setTimeout(() => {
setSuggestions([]);
clearTimeout(timer);
const handleOnchange = (e) => {
setSearchText(e.target.value);
};
const handelOnBlur = () => {
const timer = setTimeout(() => {
setSuggestions([]);
clearTimeout(timer);
}, 300);
};
return (
<div className="bg-search-bg bg-gray-900 mb-5">
<div className="w-full m-0 md:w-4/5 md:m-auto py-3 flex h-64 justify-evenly items-center flex-col md:flex-row">
<h1 className="w-full pl-3 font-bold text-5xl text-white">
Find restaurants near you..
</h1>

}, 300);
};
return (
<div className="bg-search-bg bg-gray-900 mb-5">
<div className="w-full m-0 md:w-4/5 md:m-auto py-3 flex h-64 justify-evenly items-center flex-col md:flex-row">
<h1 className="w-full pl-3 font-bold text-5xl text-white">
Find restaurants near you..
</h1>

<form
className=" md:text-right w-full py-2 text-xl relative"
onSubmit={handleOnsubmit}
>
<input
type="text"
className="p-2 border-2 md:w-full w-4/5 mx-2 md:mx-0 outline-none md:border-r-0 "
placeholder="Search restaurants.."
autoFocus={true}
onChange={handleOnchange}
onBlur={handelOnBlur}
value={searchText}
/>
<div className=" bg-white absolute md:w-full w-4/5 mx-2 md:mx-0 ">
{suggestions &&
suggestions.map((suggestion) => {
return (
<button
key={suggestion?.data?.id}
className="w-full text-start p-2 hover:bg-gray-300"
>
<Link to={"/restaurant/" + suggestion?.info.id}>
<p>{suggestion?.info.name}</p>
</Link>
</button>
);
})}
</div>
</form>
</div>
</div>
);
<form
className=" md:text-right w-full py-2 text-xl relative"
onSubmit={handleOnsubmit}
>
<input
type="text"
className="p-2 border-2 md:w-full w-4/5 mx-2 md:mx-0 outline-none md:border-r-0 "
placeholder="Search restaurants.."
autoFocus={true}
onChange={handleOnchange}
onBlur={handelOnBlur}
value={searchText}
/>
<div className=" bg-white absolute md:w-full w-4/5 mx-2 md:mx-0 ">
{suggestions &&
suggestions.map((suggestion) => {
return (
<button
key={suggestion?.data?.id}
className="w-full text-start p-2 hover:bg-gray-300"
>
<Link to={"/restaurant/" + suggestion?.info.id}>
<p>{suggestion?.info.name}</p>
</Link>
</button>
);
})}
</div>
</form>
</div>
</div>
);
};

export default Search;
3 changes: 1 addition & 2 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const CROUSEL_IMAGE_CDN_URL =
export const RESTAURANT_MENU_URL = "https://food-villa-server.vercel.app/api/restaurant/menu?&lat=27.8973944&lng=78.0880129&menuId="

export const SWIGGY_RESTAURANT_CDN_URL =
"https://food-villa-server.vercel.app/api/restaurants?lat=28.4594965&lng=77.0266383&is-seo-homepage-enabled=true&page_type=DESKTOP_WEB_LISTING";

"https://food-villa-server.vercel.app/api/restaurants?lat=28.4594965&lng=77.0266383"
export const SITE_LOGO =
"https://lh3.googleusercontent.com/Em7AHf7XBH_RtGfCBVXz9RH8SM_pHkj3xPP-yd3cRguY1_Jc8fmqgx6WxnvGVyPV5xs5gL3HCD0FCuv6Xo4CwoY6ak4";
5 changes: 3 additions & 2 deletions src/utils/useRestaurantList.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ const useRestaurantList = () => {
try {
const data = await fetch(SWIGGY_RESTAURANT_CDN_URL);
const json = await data.json();
console.log(json);
setRestaurants(
json?.data?.cards[5]?.card?.card?.gridElements?.infoWithStyle?.restaurants
json?.data?.success?.cards[1]?.card?.card?.gridElements?.infoWithStyle?.restaurants
)
setActualData(
json?.data?.cards[5]?.card?.card?.gridElements?.infoWithStyle?.restaurants
json?.data?.success?.cards[1]?.card?.card?.gridElements?.infoWithStyle?.restaurants
)
setIsLoading(false)
} catch (error) {
Expand Down

0 comments on commit 8039992

Please sign in to comment.