|
1 |
| -"use client"; |
2 |
| -import { useState, useEffect } from "react"; |
3 |
| -import axios, { type AxiosResponse } from "axios"; |
4 |
| -import Footer from "@/components/Footer"; |
5 |
| -import Navbar from "@/components/Navbar"; |
6 |
| -import { Download, Eye, Maximize } from "lucide-react"; |
7 |
| -import { useRouter } from "next/navigation"; |
8 |
| -import { Worker } from "@react-pdf-viewer/core"; |
9 |
| -import { Viewer } from "@react-pdf-viewer/core"; |
10 |
| -import { |
11 |
| - zoomPlugin, |
12 |
| - ZoomInIcon, |
13 |
| - ZoomOutIcon, |
14 |
| - type RenderZoomOutProps, |
15 |
| - type RenderZoomInProps, |
16 |
| - type RenderCurrentScaleProps, |
17 |
| -} from "@react-pdf-viewer/zoom"; |
18 |
| -import { getFilePlugin } from "@react-pdf-viewer/get-file"; |
| 1 | +// "use client"; |
| 2 | +// import { useState, useEffect } from "react"; |
| 3 | +// import axios, { type AxiosResponse } from "axios"; |
| 4 | +// import Footer from "@/components/Footer"; |
| 5 | +// import Navbar from "@/components/Navbar"; |
| 6 | +// import { Download, Eye, Maximize } from "lucide-react"; |
| 7 | +// import { useRouter } from "next/navigation"; |
| 8 | +// import { Worker } from "@react-pdf-viewer/core"; |
| 9 | +// import { Viewer } from "@react-pdf-viewer/core"; |
| 10 | +// import { |
| 11 | +// zoomPlugin, |
| 12 | +// ZoomInIcon, |
| 13 | +// ZoomOutIcon, |
| 14 | +// type RenderZoomOutProps, |
| 15 | +// type RenderZoomInProps, |
| 16 | +// type RenderCurrentScaleProps, |
| 17 | +// } from "@react-pdf-viewer/zoom"; |
| 18 | +// import { getFilePlugin } from "@react-pdf-viewer/get-file"; |
19 | 19 |
|
20 |
| -import { |
21 |
| - fullScreenPlugin, |
22 |
| - type RenderEnterFullScreenProps, |
23 |
| -} from "@react-pdf-viewer/full-screen"; |
| 20 | +// import { |
| 21 | +// fullScreenPlugin, |
| 22 | +// type RenderEnterFullScreenProps, |
| 23 | +// } from "@react-pdf-viewer/full-screen"; |
24 | 24 |
|
25 |
| -import "@react-pdf-viewer/full-screen/lib/styles/index.css"; |
26 |
| -import "@react-pdf-viewer/core/lib/styles/index.css"; |
27 |
| -import "@react-pdf-viewer/zoom/lib/styles/index.css"; |
28 |
| -import Loader from "@/components/ui/loader"; |
29 |
| -import Link from "next/link"; |
30 |
| -import { PaperResponse } from "@/interface"; |
31 |
| -import { fetchPaperID } from "@/app/actions/get-papers-by-id"; |
| 25 | +// import "@react-pdf-viewer/full-screen/lib/styles/index.css"; |
| 26 | +// import "@react-pdf-viewer/core/lib/styles/index.css"; |
| 27 | +// import "@react-pdf-viewer/zoom/lib/styles/index.css"; |
| 28 | +// import Loader from "@/components/ui/loader"; |
| 29 | +// import Link from "next/link"; |
| 30 | +// import { PaperResponse } from "@/interface"; |
| 31 | +// import { fetchPaperID } from "@/app/actions/get-papers-by-id"; |
32 | 32 |
|
33 |
| -interface ErrorResponse { |
34 |
| - message: string; |
35 |
| -} |
| 33 | +// interface ErrorResponse { |
| 34 | +// message: string; |
| 35 | +// } |
36 | 36 |
|
37 |
| -interface Params { |
38 |
| - params: { id: string }; |
39 |
| -} |
| 37 | +// interface Params { |
| 38 | +// params: { id: string }; |
| 39 | +// } |
40 | 40 |
|
41 |
| -export default function PaperPage({ params }: Params) { |
42 |
| - const [paper, setPaper] = useState<PaperResponse | null>(null); |
43 |
| - const [error, setError] = useState<string | null>(null); |
44 |
| - const router = useRouter(); |
45 |
| - const getFilePluginInstance = getFilePlugin(); |
46 |
| - const zoomPluginInstance = zoomPlugin(); |
47 |
| - const { CurrentScale, ZoomIn, ZoomOut } = zoomPluginInstance; |
48 |
| - const fullScreenPluginInstance = fullScreenPlugin(); |
49 |
| - const EnterFullScreen = fullScreenPluginInstance.EnterFullScreen.bind( |
50 |
| - fullScreenPluginInstance, |
51 |
| - ); |
| 41 | +// export default function PaperPage({ params }: Params) { |
| 42 | +// const [paper, setPaper] = useState<PaperResponse | null>(null); |
| 43 | +// const [error, setError] = useState<string | null>(null); |
| 44 | +// const router = useRouter(); |
| 45 | +// const getFilePluginInstance = getFilePlugin(); |
| 46 | +// const zoomPluginInstance = zoomPlugin(); |
| 47 | +// const { CurrentScale, ZoomIn, ZoomOut } = zoomPluginInstance; |
| 48 | +// const fullScreenPluginInstance = fullScreenPlugin(); |
| 49 | +// const EnterFullScreen = fullScreenPluginInstance.EnterFullScreen.bind( |
| 50 | +// fullScreenPluginInstance, |
| 51 | +// ); |
52 | 52 |
|
53 |
| - useEffect(() => {pag |
54 |
| - try { |
55 |
| - const response = await fetchPaperID(params.id) |
56 |
| - // const response: AxiosResponse<PaperResponse> = await axios.get( |
57 |
| - // `/api/paper-by-id/${params.id}`, |
58 |
| - // ); |
59 |
| - if(response) |
60 |
| - { |
61 |
| - setPaper(response); |
62 |
| - } |
63 |
| - } catch (err: unknown) { |
64 |
| - if (axios.isAxiosError(err)) { |
65 |
| - const errorResponse = err.response as AxiosResponse<ErrorResponse>; |
66 |
| - if (errorResponse?.status === 400 || errorResponse?.status === 404) { |
67 |
| - router.push("/"); |
68 |
| - } else { |
69 |
| - setError(errorResponse?.data?.message ?? "Failed to fetch paper"); |
70 |
| - } |
71 |
| - } else { |
72 |
| - throw(err) |
73 |
| - // setError("An unknown error occurred"); |
74 |
| - } |
75 |
| - } |
76 |
| - }; |
| 53 | +// useEffect(() => {pag |
| 54 | +// try { |
| 55 | +// const response = await fetchPaperID(params.id) |
| 56 | +// // const response: AxiosResponse<PaperResponse> = await axios.get( |
| 57 | +// // `/api/paper-by-id/${params.id}`, |
| 58 | +// // ); |
| 59 | +// if(response) |
| 60 | +// { |
| 61 | +// setPaper(response); |
| 62 | +// } |
| 63 | +// } catch (err: unknown) { |
| 64 | +// if (axios.isAxiosError(err)) { |
| 65 | +// const errorResponse = err.response as AxiosResponse<ErrorResponse>; |
| 66 | +// if (errorResponse?.status === 400 || errorResponse?.status === 404) { |
| 67 | +// router.push("/"); |
| 68 | +// } else { |
| 69 | +// setError(errorResponse?.data?.message ?? "Failed to fetch paper"); |
| 70 | +// } |
| 71 | +// } else { |
| 72 | +// throw(err) |
| 73 | +// // setError("An unknown error occurred"); |
| 74 | +// } |
| 75 | +// } |
| 76 | +// }; |
77 | 77 |
|
78 |
| - if (params.id) { |
79 |
| - void fetchPaper(); |
80 |
| - } |
81 |
| - }, [params.id, router]); |
| 78 | +// if (params.id) { |
| 79 | +// void fetchPaper(); |
| 80 | +// } |
| 81 | +// }, [params.id, router]); |
82 | 82 |
|
83 |
| - if (error) { |
84 |
| - return <div>Error: {error}</div>; |
85 |
| - } |
| 83 | +// if (error) { |
| 84 | +// return <div>Error: {error}</div>; |
| 85 | +// } |
86 | 86 |
|
87 |
| - if (!paper) { |
88 |
| - return <Loader prop="h-screen w-screen" />; |
89 |
| - } |
| 87 | +// if (!paper) { |
| 88 | +// return <Loader prop="h-screen w-screen" />; |
| 89 | +// } |
90 | 90 |
|
91 |
| - return ( |
92 |
| - <div> |
93 |
| - <Navbar /> |
94 |
| - <div className="flex flex-col items-center justify-center"> |
95 |
| - <h1 className="jost mb-4 text-center text-2xl font-semibold md:mb-10 md:text-3xl"> |
96 |
| - {paper.subject} {paper.exam} {paper.slot} {paper.year} |
97 |
| - </h1> |
98 |
| - <div className="flex w-[95%] items-center justify-between bg-gray-900 px-4 py-4 md:w-[80%]"> |
99 |
| - <div className="flex gap-x-4"> |
100 |
| - <ZoomOut> |
101 |
| - {(props: RenderZoomOutProps) => ( |
102 |
| - <button onClick={props.onClick}> |
103 |
| - <ZoomOutIcon /> |
104 |
| - </button> |
105 |
| - )} |
106 |
| - </ZoomOut> |
107 |
| - <CurrentScale> |
108 |
| - {(props: RenderCurrentScaleProps) => ( |
109 |
| - <>{`${Math.round(props.scale * 100)}%`}</> |
110 |
| - )} |
111 |
| - </CurrentScale> |
112 |
| - <ZoomIn> |
113 |
| - {(props: RenderZoomInProps) => ( |
114 |
| - <button onClick={props.onClick}> |
115 |
| - <ZoomInIcon /> |
116 |
| - </button> |
117 |
| - )} |
118 |
| - </ZoomIn> |
119 |
| - </div> |
120 |
| - <div className="hidden gap-x-4 md:flex md:items-center"> |
121 |
| - <getFilePluginInstance.Download> |
122 |
| - {(props) => ( |
123 |
| - <button className="" onClick={props.onClick}> |
124 |
| - <Download /> |
125 |
| - </button> |
126 |
| - )} |
127 |
| - </getFilePluginInstance.Download> |
128 |
| - <EnterFullScreen> |
129 |
| - {(props: RenderEnterFullScreenProps) => ( |
130 |
| - <button onClick={() => props.onClick()}> |
131 |
| - <Maximize /> |
132 |
| - </button> |
133 |
| - )} |
134 |
| - </EnterFullScreen> |
135 |
| - </div> |
136 |
| - <Link className="flex md:hidden" href={paper.finalUrl}> |
137 |
| - <Download /> |
138 |
| - </Link> |
139 |
| - </div> |
| 91 | +// return ( |
| 92 | +// <div> |
| 93 | +// <Navbar /> |
| 94 | +// <div className="flex flex-col items-center justify-center"> |
| 95 | +// <h1 className="jost mb-4 text-center text-2xl font-semibold md:mb-10 md:text-3xl"> |
| 96 | +// {paper.subject} {paper.exam} {paper.slot} {paper.year} |
| 97 | +// </h1> |
| 98 | +// <div className="flex w-[95%] items-center justify-between bg-gray-900 px-4 py-4 md:w-[80%]"> |
| 99 | +// <div className="flex gap-x-4"> |
| 100 | +// <ZoomOut> |
| 101 | +// {(props: RenderZoomOutProps) => ( |
| 102 | +// <button onClick={props.onClick}> |
| 103 | +// <ZoomOutIcon /> |
| 104 | +// </button> |
| 105 | +// )} |
| 106 | +// </ZoomOut> |
| 107 | +// <CurrentScale> |
| 108 | +// {(props: RenderCurrentScaleProps) => ( |
| 109 | +// <>{`${Math.round(props.scale * 100)}%`}</> |
| 110 | +// )} |
| 111 | +// </CurrentScale> |
| 112 | +// <ZoomIn> |
| 113 | +// {(props: RenderZoomInProps) => ( |
| 114 | +// <button onClick={props.onClick}> |
| 115 | +// <ZoomInIcon /> |
| 116 | +// </button> |
| 117 | +// )} |
| 118 | +// </ZoomIn> |
| 119 | +// </div> |
| 120 | +// <div className="hidden gap-x-4 md:flex md:items-center"> |
| 121 | +// <getFilePluginInstance.Download> |
| 122 | +// {(props) => ( |
| 123 | +// <button className="" onClick={props.onClick}> |
| 124 | +// <Download /> |
| 125 | +// </button> |
| 126 | +// )} |
| 127 | +// </getFilePluginInstance.Download> |
| 128 | +// <EnterFullScreen> |
| 129 | +// {(props: RenderEnterFullScreenProps) => ( |
| 130 | +// <button onClick={() => props.onClick()}> |
| 131 | +// <Maximize /> |
| 132 | +// </button> |
| 133 | +// )} |
| 134 | +// </EnterFullScreen> |
| 135 | +// </div> |
| 136 | +// <Link className="flex md:hidden" href={paper.finalUrl}> |
| 137 | +// <Download /> |
| 138 | +// </Link> |
| 139 | +// </div> |
140 | 140 |
|
141 |
| - <Worker workerUrl="https://unpkg.com/[email protected]/build/pdf.worker.min.js"> |
142 |
| - <div className="border-1 w-[95%] overflow-x-hidden md:w-[80%]"> |
143 |
| - <Viewer |
144 |
| - fileUrl={paper.finalUrl} |
145 |
| - plugins={[ |
146 |
| - zoomPluginInstance, |
147 |
| - getFilePluginInstance, |
148 |
| - fullScreenPluginInstance, |
149 |
| - ]} |
150 |
| - /> |
151 |
| - </div> |
152 |
| - </Worker> |
153 |
| - </div> |
154 |
| - <Footer /> |
155 |
| - </div> |
156 |
| - ); |
157 |
| -} |
| 141 | +// <Worker workerUrl="https://unpkg.com/[email protected]/build/pdf.worker.min.js"> |
| 142 | +// <div className="border-1 w-[95%] overflow-x-hidden md:w-[80%]"> |
| 143 | +// <Viewer |
| 144 | +// fileUrl={paper.finalUrl} |
| 145 | +// plugins={[ |
| 146 | +// zoomPluginInstance, |
| 147 | +// getFilePluginInstance, |
| 148 | +// fullScreenPluginInstance, |
| 149 | +// ]} |
| 150 | +// /> |
| 151 | +// </div> |
| 152 | +// </Worker> |
| 153 | +// </div> |
| 154 | +// <Footer /> |
| 155 | +// </div> |
| 156 | +// ); |
0 commit comments