Skip to content

Commit 80cc9f3

Browse files
shimmering effect
1 parent ac24c30 commit 80cc9f3

File tree

4 files changed

+48
-14
lines changed

4 files changed

+48
-14
lines changed

swiggy(LTS)/src/component/Body.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import CardContainer from '../component/CardContainer'
33

44
const Body = () =>{
55
return(
6-
<div className='md:px-36 w-full'>
6+
<div className='xl:px-36 lg:px-20 w-full'>
77

88
<CardContainer/>
99

swiggy(LTS)/src/component/CardContainer.jsx

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import RestaurantCard from '../component/RestaurantCard'
22
import { API_URL} from '../constant/config.js'
33
import { useState, useEffect } from 'react'
4+
import ShimmerCard from '../component/ShimmerCard.jsx'
45

56
const CardContainer = () => {
67
const [restaurantList , setRestaurantList] = useState([]);
@@ -17,12 +18,17 @@ const CardContainer = () => {
1718

1819
useEffect(() =>{
1920
const getRestaurantData = async() => {
20-
const response = await fetch(API_URL);
21-
const data = await response.json();
22-
console.log("data",data);
23-
// console.log("carousel data", data.data.cards[0].card.card.gridElements.infoWithStyle.info);
24-
console.log("restaurant data", data.data.cards[1].card.card.gridElements.infoWithStyle.restaurants);
25-
setRestaurantList(data.data.cards[1].card.card.gridElements.infoWithStyle.restaurants);
21+
try{
22+
const response = await fetch(API_URL);
23+
const data = await response.json();
24+
console.log("data",data);
25+
console.log("carousel data", data?.data?.cards[0]?.card?.card?.gridElements?.infoWithStyle?.info);
26+
console.log("restaurant data", data?.data?.cards[1]?.card?.card?.gridElements?.infoWithStyle?.restaurants);
27+
setRestaurantList(data?.data?.cards[1]?.card?.card?.gridElements?.infoWithStyle?.restaurants);
28+
}
29+
catch(error){
30+
console.log("error", error);
31+
}
2632
};
2733

2834
getRestaurantData();
@@ -33,12 +39,15 @@ const CardContainer = () => {
3339
<>
3440
<button className="bg-gray-300 hover:bg-gray-400 border border-black" onClick={filter}>Filter</button>
3541
<div className='flex justify-start flex-wrap gap-2 py-4'>
36-
{
42+
{restaurantList.length === 0 ? <ShimmerCard/> :
3743
restaurantList.map((restaurant) =>{
38-
return(
39-
<RestaurantCard
40-
{...restaurant.info}
44+
return(
45+
(
46+
<RestaurantCard
47+
{...restaurant?.info}
4148
/>
49+
)
50+
4251
)
4352
})
4453
}

swiggy(LTS)/src/component/RestaurantCard.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ const RestaurantCard = ({name, avgRating, sla, cuisines, areaName, cloudinaryIma
44
return(
55
<div className=" md:w-[24%] w-full my-5 ">
66
<div className="max-w-full px-1 h-[150px]">
7-
<img className="h-full w-full object-cover rounded-[15px]" src={IMG_URL + cloudinaryImageId}/>
7+
<img className="h-full w-full object-cover rounded-[15px]" src={IMG_URL + cloudinaryImageId}/>
88
</div>
99
<div className="px-2">
1010
<h2 className="font-semibold text-2xl">{name}</h2>
1111
<div className="flex gap-2">
1212
<h2><i className="fa-solid fa-star text-[16px] text-green-600"></i>{avgRating}</h2>
13-
<h2 className="text-[16px] ">{sla.deliveryTime}</h2>
13+
<h2 className="text-[16px] ">{sla?.deliveryTime} min</h2>
1414
</div>
1515
</div>
16-
<p className="text-gray-500 px-3">{cuisines}</p>
16+
<p className="text-gray-500 px-3">{cuisines.join(", ")}</p>
1717
<p className="text-gray-500 px-3">{areaName}</p>
1818
</div>
1919
)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
3+
const ShimmerCard = () =>{
4+
return(
5+
new Array(20).fill(0).map(()=>{
6+
return (
7+
<div className=" md:w-[24%] w-full h-max my-5 shadow-lg shadow-slate-300 p-2">
8+
<div className="max-w-full px-1 h-[150px] w-full bg-[#7f7f7f]">
9+
</div>
10+
<div className="px-2 mt-2">
11+
<h2 className="font-semibold text-2xl bg-[#7f7f7f] h-4 w-full"></h2>
12+
<div className="flex gap-2 mt-2">
13+
<h2 className="bg-[#7f7f7f] h-4 w-1/5 "></h2>
14+
<h2 className="text-[16px] bg-[#7f7f7f] h-4 w-1/5"></h2>
15+
</div>
16+
</div>
17+
<p className="text-gray-500 mx-2 bg-[#7f7f7f] h-4 w-11/12 mt-2"></p>
18+
<p className="text-gray-500 mx-2 bg-[#7f7f7f] h-4 w-11/12 mt-2"></p>
19+
</div>
20+
)
21+
})
22+
)
23+
}
24+
25+
export default ShimmerCard;

0 commit comments

Comments
 (0)