-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAllInterviewsList.tsx
64 lines (56 loc) · 1.75 KB
/
AllInterviewsList.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"use client";
import { useState } from "react";
import { motion, AnimatePresence } from "framer-motion";
import { CircleArrowDown } from "lucide-react";
interface AllInterviewsListProps {
renderedCards: React.ReactNode[];
}
export default function AllInterviewsList({
renderedCards
}: AllInterviewsListProps) {
const interviewsPerPage = Number(process.env.NEXT_PUBLIC_INTERVIEWS_PER_PAGE) || 3;
const [itemsToShow, setItemsToShow] = useState(interviewsPerPage);
const incrementBy = 6;
const handleLoadMore = () => {
setItemsToShow(prev => prev + incrementBy);
};
const hasMoreItems = itemsToShow < renderedCards.length;
if (renderedCards.length === 0) {
return <div className="interviews-section">
<p>There are no interviews available</p>
</div>;
}
return (
<div className="flex flex-col gap-6">
<div className="interviews-section">
<AnimatePresence>
{renderedCards.slice(0, itemsToShow).map((card, index) => (
<motion.div
key={index}
className="flex"
initial={{ opacity: 0, scale: 0.95 }}
animate={{ opacity: 1, scale: 1 }}
transition={{
duration: 0.3,
delay: index >= itemsToShow - incrementBy ? 0.1 * (index % incrementBy) : 0,
}}
>
{card}
</motion.div>
))}
</AnimatePresence>
</div>
{hasMoreItems && (
<div className="flex justify-center mt-4">
<button
onClick={handleLoadMore}
className="btn-secondary flex items-center gap-2"
>
<span>Load More</span>
<CircleArrowDown />
</button>
</div>
)}
</div>
);
}