Skip to content

Commit 99d9d54

Browse files
committed
fix: height issue and the first Promotion card issue of getting rendered twice
1 parent 33b1639 commit 99d9d54

File tree

2 files changed

+40
-18
lines changed

2 files changed

+40
-18
lines changed

client/src/app/components/PromotionCard.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ const option = [
2727
];
2828

2929
const PromotionCard = () => {
30-
// State to hold the random index
30+
// Use a static index initially, then randomize after hydration
3131
const [randomIndex, setRandomIndex] = useState(0);
3232

33-
// Effect to set random index on initial render
33+
// Effect to randomize after hydration is complete
3434
useEffect(() => {
3535
const random = Math.floor(Math.random() * option.length);
3636
setRandomIndex(random);
37-
}, []); // Empty dependency array ensures this effect runs only once
37+
}, []);
3838

3939
return (
4040
<Link
@@ -43,7 +43,7 @@ const PromotionCard = () => {
4343
target="_blank"
4444
className="hover:scale-105 transition-all ease-in-out duration-300 font-sourcecodepro "
4545
>
46-
<div className="flex justify-betwen max-w-[400px] flex-col items-center rounded h-[280px] border-2 border-[#f7f7f7] ">
46+
<div className="flex justify-between max-w-[400px] flex-col items-center rounded min-h-[280px] max-h-[280px] border-2 border-[#f7f7f7] overflow-hidden">
4747
{/* Heading and Logo */}
4848
<div className="flex gap-1 xl:gap-4 items-center justify-between ">
4949
<div className="flex items-center text-white justify-center px-4 py-2 w-full gap-2 rounded-md">

client/src/app/components/Skeleton.tsx

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,45 @@ const Skeleton = () => {
44
return (
55
<div
66
role="status"
7-
className="max-w-[400px] lg:w-[400px] rounded min-h-[280px] p-4 border border-gray-200 shadow animate-pulse md:p-6 dark:border-gray-700"
7+
className="max-w-[400px] w-full px-8 pb-3 bg-[#0e0e0e] flex justify-center flex-col items-center rounded h-[280px] border-2 border-[#cecece] shadow animate-pulse"
88
>
9-
<div className="flex items-center justify-center h-48 mb-4 bg-gray-300 rounded dark:bg-gray-700">
10-
<svg
11-
className="w-10 h-10 text-gray-200 dark:text-gray-600"
12-
aria-hidden="true"
13-
xmlns="http://www.w3.org/2000/svg"
14-
fill="currentColor"
15-
viewBox="0 0 16 20"
16-
>
17-
<path d="M14.066 0H7v5a2 2 0 0 1-2 2H0v11a1.97 1.97 0 0 0 1.934 2h12.132A1.97 1.97 0 0 0 16 18V2a1.97 1.97 0 0 0-1.934-2ZM10.5 6a1.5 1.5 0 1 1 0 2.999A1.5 1.5 0 0 1 10.5 6Zm2.221 10.515a1 1 0 0 1-.858.485h-8a1 1 0 0 1-.9-1.43L5.6 10.039a.978.978 0 0 1 .936-.57 1 1 0 0 1 .9.632l1.181 2.981.541-1a.945.945 0 0 1 .883-.522 1 1 0 0 1 .879.529l1.832 3.438a1 1 0 0 1-.031.988Z" />
18-
<path d="M5 5V.13a2.96 2.96 0 0 0-1.293.749L.879 3.707A2.98 2.98 0 0 0 .13 5H5Z" />
19-
</svg>
9+
{/* Profile section skeleton */}
10+
<div className="flex gap-1 xl:gap-4 items-center justify-between w-full mb-4">
11+
<div className="flex items-center gap-2">
12+
<div className="w-12 h-12 bg-gray-600 rounded-full"></div>
13+
<div className="flex flex-col gap-1">
14+
<div className="h-4 bg-gray-600 rounded w-20"></div>
15+
<div className="h-3 bg-gray-600 rounded w-16"></div>
16+
</div>
17+
</div>
18+
<div className="flex gap-2">
19+
<div className="w-6 h-6 bg-gray-600 rounded"></div>
20+
<div className="w-6 h-6 bg-gray-600 rounded"></div>
21+
<div className="w-6 h-6 bg-gray-600 rounded"></div>
22+
</div>
2023
</div>
21-
<div className="h-2.5 bg-gray-200 rounded-full dark:bg-gray-700 w-full min-w-[300px] mb-4"></div>
2224

23-
<div className="h-2 bg-gray-200 rounded-full dark:bg-gray-700"></div>
25+
{/* Divider */}
26+
<div className="h-[0.5px] bg-gray-600 w-full mb-4"></div>
27+
28+
{/* Stats section skeleton */}
29+
<div className="flex gap-5 items-center justify-center">
30+
<div className="w-16 h-16 bg-gray-600 rounded-full"></div>
31+
<div className="flex flex-col gap-3">
32+
<div className="flex items-center gap-2">
33+
<div className="h-3 bg-gray-600 rounded w-12"></div>
34+
<div className="h-2 bg-gray-600 rounded w-20"></div>
35+
</div>
36+
<div className="flex items-center gap-2">
37+
<div className="h-3 bg-gray-600 rounded w-16"></div>
38+
<div className="h-2 bg-gray-600 rounded w-20"></div>
39+
</div>
40+
<div className="flex items-center gap-2">
41+
<div className="h-3 bg-gray-600 rounded w-12"></div>
42+
<div className="h-2 bg-gray-600 rounded w-20"></div>
43+
</div>
44+
</div>
45+
</div>
2446
</div>
2547
);
2648
};

0 commit comments

Comments
 (0)