-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathCustomPagination.tsx
More file actions
85 lines (81 loc) · 2.47 KB
/
CustomPagination.tsx
File metadata and controls
85 lines (81 loc) · 2.47 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { Track, Problem } from "@prisma/client";
import { PageToggle } from "./PageToggle";
import { useRouter } from "next/navigation";
import { Button } from "@repo/ui";
import { ChevronLeftIcon, ChevronRightIcon } from "@radix-ui/react-icons";
const CustomPagination = ({
isAtHeader = false,
problemIndex,
track,
}: {
allProblems: Problem[];
isAtHeader?: boolean;
problemIndex: number;
track: Track & { problems: Problem[] };
}) => {
const router = useRouter();
return (
<div className="flex items-center justify-center space-x-2">
<PageToggle allProblems={track.problems} isAtHeader track={track} />
<Button
variant="outline"
className="ml-2 hidden bg-black text-white md:flex"
disabled={problemIndex === 0}
onClick={() => {
if (problemIndex !== 0) {
router.push(`/tracks/${track.id}/${track.problems[problemIndex - 1]!.id}`);
}
}}
>
<div className="pr-2">
<ChevronLeftIcon />
</div>
<span className={isAtHeader ? "hidden lg:block" : ""}>Prev</span>
</Button>
<Button
variant="outline"
className="block bg-black text-white md:hidden"
disabled={problemIndex === 0}
onClick={() => {
if (problemIndex !== 0) {
router.push(`/tracks/${track.id}/${track.problems[problemIndex - 1]!.id}`);
}
}}
>
<div>
<ChevronLeftIcon />
</div>
</Button>
<Button
variant="outline"
className="hidden bg-black text-white md:flex"
disabled={problemIndex + 1 === track.problems.length}
onClick={() => {
if (problemIndex + 1 !== track.problems.length) {
router.push(`/tracks/${track.id}/${track.problems[problemIndex + 1]!.id}`);
}
}}
>
<span className={isAtHeader ? "hidden lg:block" : ""}>Next</span>
<div className="pl-2">
<ChevronRightIcon />
</div>
</Button>
<Button
variant="outline"
className="block bg-black text-white md:hidden"
disabled={problemIndex + 1 === track.problems.length}
onClick={() => {
if (problemIndex + 1 !== track.problems.length) {
router.push(`/tracks/${track.id}/${track.problems[problemIndex + 1]!.id}`);
}
}}
>
<div>
<ChevronRightIcon />
</div>
</Button>
</div>
);
};
export default CustomPagination;