@@ -14,6 +14,7 @@ export default function App() {
14
14
const [ completedCrop , setCompletedCrop ] = useState ( ) ;
15
15
const [ scale , setScale ] = useState ( 1 ) ;
16
16
const [ rotate , setRotate ] = useState ( 0 ) ;
17
+ const [ isLoading , setIsLoading ] = useState ( false ) ;
17
18
18
19
function onSelectFile ( e ) {
19
20
if ( e . target . files && e . target . files . length > 0 ) {
@@ -42,6 +43,7 @@ export default function App() {
42
43
}
43
44
44
45
function onDownloadCropClick ( ) {
46
+ setIsLoading ( true ) ;
45
47
if ( ! previewCanvasRef . current ) {
46
48
throw new Error ( "Crop canvas does not exist" ) ;
47
49
}
@@ -58,6 +60,8 @@ export default function App() {
58
60
hiddenAnchorRef . current . href = blobUrl ;
59
61
hiddenAnchorRef . current . download = "croped-image.png" ;
60
62
hiddenAnchorRef . current . click ( ) ;
63
+
64
+ setIsLoading ( false ) ;
61
65
} ,
62
66
} ) ;
63
67
} , "image/png" ) ;
@@ -81,15 +85,15 @@ export default function App() {
81
85
} , [ completedCrop , scale , rotate ] ) ;
82
86
83
87
return (
84
- < section className = "max-w-7xl mx-auto bg-gray-200 p-14 rounded-xl min-h-screen" >
88
+ < section className = "max-w-7xl mx-auto bg-gray-200 p-6 sm:p- 14 rounded-xl min-h-screen" >
85
89
< div className = "mb-6" >
86
90
< h1 className = "font-extrabold text-[#222328] text-[32px]" >
87
91
Image Crop Tool
88
92
</ h1 >
89
- < p className = "mt-2 text-[#666e75] text-[16px] max-w[500px]" >
93
+ < p className = "mt-2 text-[#666e75] text-[16px] max-w- [500px]" >
90
94
Select an image and crop it, then download the cropped version.
91
95
</ p >
92
- < p className = "mt-2 text-[#666e75] text-[16px] max-w[500px]" >
96
+ < p className = "mt-2 text-[#666e75] text-[16px] max-w- [500px]" >
93
97
Copyright © 2023 < span className = "font-bold" > ShouldiRenovate</ span > .
94
98
All rights reserved.
95
99
</ p >
@@ -101,7 +105,7 @@ export default function App() {
101
105
type = "file"
102
106
accept = "image/*"
103
107
onChange = { onSelectFile }
104
- className = "py-2 px-4 bg-blue-500 text-white rounded-md cursor-pointer"
108
+ className = "py-2 px-4 bg-blue-500 text-white rounded-md cursor-pointer w-[101%] max-w-full lg:w-auto "
105
109
/>
106
110
</ div >
107
111
{ ! ! imgSrc && (
@@ -136,12 +140,18 @@ export default function App() {
136
140
} }
137
141
/>
138
142
< div className = "mt-4" >
139
- < button
140
- onClick = { onDownloadCropClick }
141
- className = "py-2 px-4 bg-green-500 text-white rounded-md cursor-pointer"
142
- >
143
- Download Crop
144
- </ button >
143
+ { isLoading ? (
144
+ < button className = "py-2 px-4 bg-green-500 text-white rounded-md cursor-pointer" >
145
+ Downloading...
146
+ </ button >
147
+ ) : (
148
+ < button
149
+ onClick = { onDownloadCropClick }
150
+ className = "py-2 px-4 bg-green-500 text-white rounded-md cursor-pointer"
151
+ >
152
+ Download Image
153
+ </ button >
154
+ ) }
145
155
< a
146
156
ref = { hiddenAnchorRef }
147
157
download
0 commit comments