@@ -8,7 +8,7 @@ import ReactCrop, {
88 PixelCrop ,
99} from "react-image-crop" ;
1010
11- import { Button , Input } from "@/components" ;
11+ import { Button , Input , Range } from "@/components" ;
1212import { useToast } from "@/context/ToastContext" ;
1313import {
1414 CursorArrowRaysIcon ,
@@ -35,6 +35,8 @@ const centerAspectCrop = (
3535 {
3636 unit : "%" ,
3737 width : 100 ,
38+ x : 0 ,
39+ y : 0 ,
3840 } ,
3941 aspect ,
4042 mediaWidth ,
@@ -140,6 +142,7 @@ const ImagePicker: React.FC<Props> = ({ aspect, children, onChange }) => {
140142
141143 const fetchImageFromPexels = async ( ) => {
142144 try {
145+ setFetchingImage ( true ) ;
143146 const headers = new Headers ( ) ;
144147 headers . append (
145148 "Authorization" ,
@@ -158,10 +161,15 @@ const ImagePicker: React.FC<Props> = ({ aspect, children, onChange }) => {
158161 ) ;
159162 const pictures = await res . json ( ) ;
160163 if ( pictures ?. photos . length ) {
161- getBase64FromUrl ( pictures ?. photos [ 0 ] ?. src ?. medium ) ;
164+ await getBase64FromUrl (
165+ pictures ?. photos [ 0 ] ?. src ?. medium +
166+ "?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2"
167+ ) ;
162168 }
163169 } catch ( error ) {
164170 console . log ( "Error while fetching images from pexels " , error ) ;
171+ } finally {
172+ setFetchingImage ( false ) ;
165173 }
166174 } ;
167175
@@ -218,16 +226,18 @@ const ImagePicker: React.FC<Props> = ({ aspect, children, onChange }) => {
218226 onChange = { onSelectFile }
219227 />
220228 < button
229+ disabled = { fetchingImage }
221230 onClick = { fetchImageFromPexels }
222- className = "w-full mt-3 inline-flex items-center text-center dark:border-zinc-400 border-zinc-400 rounded-sm px-2 py-1 border-[1px] text-zinc-900 dark:text-white"
231+ className = "w-full disabled:opacity-40 mt-3 inline-flex items-center text-center dark:border-zinc-400 border-zinc-400 rounded-sm px-2 py-1 border-[1px] text-zinc-900 dark:text-white"
223232 >
224- < PhotoIcon className = "h-4 w-4 mr-2" /> From pexels
233+ < PhotoIcon className = "h-4 w-4 mr-2" /> Random img ( pexels)
225234 </ button >
226235 { ! ! src && (
227236 < div className = "w-full flex flex-col justify-start items-end" >
228237 < button onClick = { resetImageSelection } >
229- < XCircleIcon className = "h-6 w-6 my-2 dark:text-white text-zinc-900" />
238+ < XCircleIcon className = "h-6 my-2 w-6 dark:text-white text-zinc-900" />
230239 </ button >
240+
231241 < ReactCrop
232242 crop = { crop }
233243 onChange = { ( _ , percentCrop ) => setCrop ( percentCrop ) }
0 commit comments