Skip to content

fix: pagination controls not updating content #703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions apps/web/components/Blog.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use client";
import { useEffect } from "react";
import { useRecoilValue } from "recoil";
import { useRouter } from "next/navigation";

import { Problem, Track } from "@prisma/client";
import { isLegacyViewMode } from "@repo/store";
Expand Down Expand Up @@ -27,6 +29,12 @@ export const Blog = ({
}) => {
const mounted = useMountStatus();
const isLegacyMode = useRecoilValue(isLegacyViewMode);
const router = useRouter();

useEffect(() => {
// Force re-render when problem changes
router.refresh();
}, [problem.id, router]);

if (isPdfRequested == undefined || !isPdfRequested) {
if (!mounted) {
Expand Down
112 changes: 59 additions & 53 deletions apps/web/components/CustomPagination.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Track, Problem } from "@prisma/client";
import { PageToggle } from "./PageToggle";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { Button } from "@repo/ui";
import { ChevronLeftIcon, ChevronRightIcon } from "@radix-ui/react-icons";

Expand All @@ -14,64 +14,70 @@ const CustomPagination = ({
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} />
<Link
prefetch
href={problemIndex !== 0 ? `/tracks/${track.id}/${track.problems[problemIndex - 1]!.id}` : ``}
style={{ cursor: problemIndex !== 0 ? "pointer" : "not-allowed" }}
<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}`);
}
}}
>
<Button
variant="outline"
className="ml-2 hidden bg-black text-white md:flex"
disabled={problemIndex !== 0 ? false : true}
>
<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 ? false : true}
>
<div>
<ChevronLeftIcon />
</div>
</Button>
</Link>
<div>
<ChevronLeftIcon />
</div>
</Button>

<Link
prefetch={true}
href={
problemIndex + 1 === track.problems.length
? ``
: `/tracks/${track.id}/${track.problems[problemIndex + 1]!.id}`
}
style={{ cursor: problemIndex + 1 !== track.problems.length ? "pointer" : "not-allowed" }}
<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}`);
}
}}
>
<Button
variant="outline"
className="hidden bg-black text-white md:flex"
disabled={problemIndex + 1 !== track.problems.length ? false : true}
>
<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 ? false : true}
>
<div>
<ChevronRightIcon />
</div>
</Button>
</Link>
<div>
<ChevronRightIcon />
</div>
</Button>
</div>
);
};
Expand Down
Loading