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