1
-
2
- import { useState , useEffect } from "react" ;
3
- import { cn } from "@/lib/utils" ;
4
- import PageSkeleton from "./PageSkeleton" ;
1
+ import { useState , useEffect } from 'react' ;
2
+ import { cn } from '@/lib/utils' ;
3
+ import PageSkeleton from './PageSkeleton' ;
5
4
6
5
interface PageViewerProps {
7
6
pageNumber : number ;
@@ -12,86 +11,90 @@ interface PageViewerProps {
12
11
export default function PageViewer ( { pageNumber, totalPages, className } : PageViewerProps ) {
13
12
const [ isLoading , setIsLoading ] = useState ( true ) ;
14
13
const [ error , setError ] = useState < string | null > ( null ) ;
15
-
14
+
16
15
// Format page number to 3 digits with leading zeros
17
16
const formattedPageNumber = pageNumber . toString ( ) . padStart ( 3 , '0' ) ;
18
-
17
+
19
18
// SVG path
20
19
const pagePath = `https://raw.githubusercontent.com/yaqiin/quran-svg/refs/heads/main/hafs/${ formattedPageNumber } .svg` ;
21
-
20
+
22
21
useEffect ( ( ) => {
23
22
// Reset loading state when page changes
24
23
setIsLoading ( true ) ;
25
24
setError ( null ) ;
26
-
25
+
27
26
// Simulate loading - in production, this would be real SVG loading
28
27
const timer = setTimeout ( ( ) => {
29
28
setIsLoading ( false ) ;
30
29
} , 500 ) ;
31
-
30
+
32
31
return ( ) => clearTimeout ( timer ) ;
33
32
} , [ pageNumber ] ) ;
34
-
33
+
35
34
const handleImageLoad = ( ) => {
36
35
setIsLoading ( false ) ;
37
36
} ;
38
-
37
+
39
38
const handleImageError = ( ) => {
40
39
setIsLoading ( false ) ;
41
40
setError ( `لم يتم العثور على الصفحة ${ pageNumber } ` ) ;
42
41
} ;
43
-
42
+
44
43
if ( pageNumber > totalPages || pageNumber < 1 ) {
45
44
return (
46
- < div className = { cn ( " flex items-center justify-center bg-muted rounded-lg" , className ) } >
45
+ < div className = { cn ( ' flex items-center justify-center rounded-lg bg-muted' , className ) } >
47
46
< p className = "text-muted-foreground" > لا توجد صفحة</ p >
48
47
</ div >
49
48
) ;
50
49
}
51
-
50
+
52
51
return (
53
- < div className = { cn ( "relative flex items-center justify-center overflow-hidden bg-white rounded-lg shadow-md" , className ) } >
52
+ < div
53
+ className = { cn (
54
+ 'relative flex items-center justify-center overflow-hidden rounded-lg bg-white shadow-md' ,
55
+ className ,
56
+ ) }
57
+ >
54
58
{ isLoading && < PageSkeleton /> }
55
-
59
+
56
60
{ error ? (
57
61
< div className = "flex items-center justify-center p-8" >
58
62
< p className = "text-destructive" > { error } </ p >
59
63
</ div >
60
64
) : (
61
65
< >
62
- { /* For the demo, we'll use placeholder images */ }
63
- < img
66
+ < img
64
67
src = { pagePath }
65
68
alt = { `صفحة ${ pageNumber } ` }
66
69
className = { cn (
67
- "w -full h -full object-contain transition-opacity duration-300" ,
68
- isLoading ? " opacity-0" : " opacity-100"
70
+ 'h -full w -full object-contain transition-opacity duration-300' ,
71
+ isLoading ? ' opacity-0' : ' opacity-100' ,
69
72
) }
70
73
onLoad = { handleImageLoad }
71
74
onError = { handleImageError }
72
75
/>
73
-
76
+
74
77
{ /* This would be the actual SVG in production */ }
75
- { /*
76
- <object
78
+ { /*
79
+ <object
77
80
data={pagePath}
78
81
type="image/svg+xml"
79
82
className={cn(
80
- "w-full h-full transition-opacity duration-300",
83
+ "w-full h-full transition-opacity duration-300",
81
84
isLoading ? "opacity-0" : "opacity-100"
82
85
)}
83
86
onLoad={handleImageLoad}
84
87
onError={handleImageError}
85
88
>
86
- <img
87
- src={`https://placehold.co/800x1200/e2e8f0/1e293b?text=صفحة+${pageNumber}`}
89
+ <img
90
+ src={`https://placehold.co/800x1200/e2e8f0/1e293b?text=صفحة+${pageNumber}`}
88
91
alt={`صفحة ${pageNumber}`}
89
92
className="w-full h-full object-contain"
90
93
/>
91
94
</object>
92
95
*/ }
93
-
94
- < span className = "absolute bottom-2 left-1/2 transform -translate-x-1/2 text-xs text-muted-foreground bg-white/80 px-2 py-1 rounded-full " >
96
+
97
+ < span className = "absolute bottom-2 left-1/2 -translate-x-1/2 transform rounded-full bg-white/80 px-2 py-1 text-xs text-muted-foreground " >
95
98
{ pageNumber }
96
99
</ span >
97
100
</ >
0 commit comments