-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathBlog.tsx
More file actions
69 lines (62 loc) · 2.03 KB
/
Blog.tsx
File metadata and controls
69 lines (62 loc) · 2.03 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
"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";
import { BlogAppbar } from "./BlogAppbar";
import { NotionRenderer } from "./NotionRenderer";
import useMountStatus from "../hooks/useMountStatus";
import TrackTools from "./TrackTools";
import CustomPagination from "./CustomPagination";
export const Blog = ({
problem,
track,
showAppBar,
showPagination,
isPdfRequested,
problemIndex,
}: {
problem: Problem & { notionRecordMap: any };
track: Track & { problems: Problem[] };
showAppBar?: boolean;
showPagination?: boolean;
isPdfRequested?: boolean;
problemIndex: number;
}) => {
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) {
return null;
}
}
const renderBlog = () =>
isLegacyMode ? (
<div className="break-after-page">
{showAppBar && <BlogAppbar problem={problem} track={track} problemIndex={problemIndex} />}
<NotionRenderer recordMap={problem.notionRecordMap} />
{showPagination && (
<div className="justify-center pt-2">
<CustomPagination allProblems={track.problems} track={track} problemIndex={problemIndex} />
</div>
)}
</div>
) : (
<div>
<NotionRenderer recordMap={problem.notionRecordMap} />
<div className="fixed top-0 w-full">
<BlogAppbar problem={problem} track={track} problemIndex={problemIndex} />
</div>
<div className="itemsc-center fixed bottom-0 mx-auto w-full justify-center">
<TrackTools allProblems={track.problems} track={track} problemIndex={problemIndex} />
</div>
</div>
);
return renderBlog();
};