From 4f43e75619817bd2993f5cb091cbe1c8b6591866 Mon Sep 17 00:00:00 2001
From: Kshitij Kochhar
Date: Tue, 30 Jul 2024 21:33:40 -0400
Subject: [PATCH] [feat] cropping finally works
---
.../settingComponents/generalPage.jsx | 68 +++++++++----------
1 file changed, 32 insertions(+), 36 deletions(-)
diff --git a/src/components/settingComponents/generalPage.jsx b/src/components/settingComponents/generalPage.jsx
index 8a3e4817..de55bbf5 100644
--- a/src/components/settingComponents/generalPage.jsx
+++ b/src/components/settingComponents/generalPage.jsx
@@ -87,27 +87,27 @@ export default function General() {
const onCropComplete = (croppedArea, croppedAreaPixels) => {
setCroppedAreaPixels(croppedAreaPixels);
- showCroppedImage();
+ //showCroppedImage();
};
const onBannerCropComplete = (croppedArea, croppedAreaPixels) => {
setBannerCroppedPixels(croppedAreaPixels);
- showCroppedBanner();
+ //showCroppedBanner();
};
- const showCroppedImage = async () => {
- try {
- const croppedImage = await getCroppedImg(
- URL.createObjectURL(selectedImage),
- croppedAreaPixels,
- rotation
- );
- console.log('donee', { croppedImage });
- setCroppedImage(croppedImage);
- } catch (e) {
- console.log(e);
- }
- };
+ // const showCroppedImage = async () => {
+ // try {
+ // const croppedImage = await getCroppedImg(
+ // URL.createObjectURL(imageUrl),
+ // croppedAreaPixels,
+ // rotation
+ // );
+ // console.log('donee', { croppedImage });
+ // setCroppedImage(croppedImage);
+ // } catch (e) {
+ // console.log(e);
+ // }
+ // };
useEffect(() => {
if (isPopupOpen) {
@@ -221,14 +221,14 @@ export default function General() {
const handleSaveChanges = async () => {
setIsSaving(true);
- if (!croppedImage) {
- console.log('No cropped image available');
- setIsPopupOpen(false);
- return;
- }
try {
- const response = await fetch(croppedImage);
+ const croppedImage2 = await getCroppedImg(
+ imageUrl,
+ croppedAreaPixels,
+ rotation
+ );
+ const response = await fetch(croppedImage2);
const blob = await response.blob();
const file = new File([blob], 'profile_picture.png', {
type: 'image/png',
@@ -268,14 +268,16 @@ export default function General() {
const handleBannerSaveChanges = async () => {
setIsSaving(true);
- if (!croppedBanner) {
- console.log('No cropped banner available');
- setIsBannerPopupOpen(false);
- return;
- }
-
try {
- const response = await fetch(croppedBanner);
+
+ const croppedBanner2 = await getCroppedImg(
+ URL.createObjectURL(selectedBanner),
+ bannerCroppedPixels,
+ bannerRotation
+ );
+
+
+ const response = await fetch(croppedBanner2);
const blob = await response.blob();
const file = new File([blob], 'banner.png', {
type: 'image/png',
@@ -793,7 +795,7 @@ export default function General() {
.
- {imageUrl && (
+ {imageUrl && isPopupOpen && (
)}
@@ -879,7 +878,7 @@ export default function General() {
.
- {banner && (
+ {banner && isBannerPopupOpen && (
)}