@@ -28,6 +28,7 @@ const Card = ({
28
28
} , [ isSelected ] ) ;
29
29
30
30
const handleDownload = async ( paper : Paper ) => {
31
+
31
32
const extension = paper . finalUrl . split ( "." ) . pop ( ) ;
32
33
const fileName = `${ extractBracketContent ( paper . subject ) } -${ paper . exam } -${ paper . slot } -${ paper . year } .${ extension } ` ;
33
34
await downloadFile ( paper . finalUrl , fileName ) ;
@@ -39,16 +40,23 @@ const Card = ({
39
40
}
40
41
41
42
async function downloadFile ( url : string , filename : string ) {
42
- try {
43
- const response = await axios . get ( url , { responseType : "blob" } ) ;
44
- const blob = new Blob ( [ response . data ] ) ;
45
- const link = document . createElement ( "a" ) ;
46
- link . href = window . URL . createObjectURL ( blob ) ;
47
- link . download = filename ;
48
- link . click ( ) ;
49
- window . URL . revokeObjectURL ( link . href ) ;
50
- } catch ( error ) {
51
- console . error ( "Error downloading file:" , error ) ;
43
+ if ( / M o b i | A n d r o i d / i. test ( navigator . userAgent ) ) {
44
+ window . location . href = url ;
45
+ } else {
46
+ try {
47
+ const response = await axios . get ( url , { responseType : "blob" } ) ;
48
+ const blob = new Blob ( [ response . data ] ) ;
49
+ const link = document . createElement ( "a" ) ;
50
+ link . href = window . URL . createObjectURL ( blob ) ;
51
+ link . download = filename ;
52
+
53
+ document . body . appendChild ( link ) ;
54
+ link . click ( ) ;
55
+ document . body . removeChild ( link ) ;
56
+ window . URL . revokeObjectURL ( link . href ) ;
57
+ } catch ( error ) {
58
+ console . error ( "Error downloading file:" , error ) ;
59
+ }
52
60
}
53
61
}
54
62
@@ -78,10 +86,7 @@ const Card = ({
78
86
alt = { paper . subject }
79
87
width = { 320 }
80
88
height = { 180 }
81
- onClick = { ( e ) => {
82
- e . stopPropagation ( ) ; // Prevents any parent link click from being triggered
83
- handleOpen ( ) ;
84
- } }
89
+ onClick = { handleOpen }
85
90
className = "mb-2 h-[180px] w-full cursor-pointer object-cover"
86
91
/>
87
92
</ Link >
@@ -97,7 +102,7 @@ const Card = ({
97
102
{ capsule ( paper . slot ) }
98
103
{ capsule ( paper . year ) }
99
104
</ div >
100
- < div className = "hidden items-center justify-between gap-2 md:flex " >
105
+ < div className = "hidden md:flex items-center justify-between gap-2" >
101
106
< div className = "flex items-center gap-1" >
102
107
< input
103
108
checked = { checked }
0 commit comments