Skip to content

Commit 2125846

Browse files
authored
Merge pull request #160 from ctfguide-tech/dev
feat: address cropping issues
2 parents 4083381 + 4f43e75 commit 2125846

File tree

1 file changed

+32
-36
lines changed

1 file changed

+32
-36
lines changed

src/components/settingComponents/generalPage.jsx

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -87,27 +87,27 @@ export default function General() {
8787

8888
const onCropComplete = (croppedArea, croppedAreaPixels) => {
8989
setCroppedAreaPixels(croppedAreaPixels);
90-
showCroppedImage();
90+
//showCroppedImage();
9191
};
9292

9393
const onBannerCropComplete = (croppedArea, croppedAreaPixels) => {
9494
setBannerCroppedPixels(croppedAreaPixels);
95-
showCroppedBanner();
95+
//showCroppedBanner();
9696
};
9797

98-
const showCroppedImage = async () => {
99-
try {
100-
const croppedImage = await getCroppedImg(
101-
URL.createObjectURL(selectedImage),
102-
croppedAreaPixels,
103-
rotation
104-
);
105-
console.log('donee', { croppedImage });
106-
setCroppedImage(croppedImage);
107-
} catch (e) {
108-
console.log(e);
109-
}
110-
};
98+
// const showCroppedImage = async () => {
99+
// try {
100+
// const croppedImage = await getCroppedImg(
101+
// URL.createObjectURL(imageUrl),
102+
// croppedAreaPixels,
103+
// rotation
104+
// );
105+
// console.log('donee', { croppedImage });
106+
// setCroppedImage(croppedImage);
107+
// } catch (e) {
108+
// console.log(e);
109+
// }
110+
// };
111111

112112
useEffect(() => {
113113
if (isPopupOpen) {
@@ -221,14 +221,14 @@ export default function General() {
221221

222222
const handleSaveChanges = async () => {
223223
setIsSaving(true);
224-
if (!croppedImage) {
225-
console.log('No cropped image available');
226-
setIsPopupOpen(false);
227-
return;
228-
}
229224

230225
try {
231-
const response = await fetch(croppedImage);
226+
const croppedImage2 = await getCroppedImg(
227+
imageUrl,
228+
croppedAreaPixels,
229+
rotation
230+
);
231+
const response = await fetch(croppedImage2);
232232
const blob = await response.blob();
233233
const file = new File([blob], 'profile_picture.png', {
234234
type: 'image/png',
@@ -268,14 +268,16 @@ export default function General() {
268268
const handleBannerSaveChanges = async () => {
269269
setIsSaving(true);
270270

271-
if (!croppedBanner) {
272-
console.log('No cropped banner available');
273-
setIsBannerPopupOpen(false);
274-
return;
275-
}
276-
277271
try {
278-
const response = await fetch(croppedBanner);
272+
273+
const croppedBanner2 = await getCroppedImg(
274+
URL.createObjectURL(selectedBanner),
275+
bannerCroppedPixels,
276+
bannerRotation
277+
);
278+
279+
280+
const response = await fetch(croppedBanner2);
279281
const blob = await response.blob();
280282
const file = new File([blob], 'banner.png', {
281283
type: 'image/png',
@@ -793,7 +795,7 @@ export default function General() {
793795
.
794796
</p>
795797

796-
{imageUrl && (
798+
{imageUrl && isPopupOpen && (
797799
<div
798800
className="mx-auto mt-4"
799801
style={{
@@ -810,9 +812,6 @@ export default function General() {
810812
onCropChange={setCrop}
811813
onZoomChange={setZoom}
812814
onCropComplete={onCropComplete}
813-
style={{
814-
containerStyle: { height: '100%', width: '100%' },
815-
}}
816815
/>
817816
</div>
818817
)}
@@ -879,7 +878,7 @@ export default function General() {
879878
.
880879
</p>
881880

882-
{banner && (
881+
{banner && isBannerPopupOpen && (
883882
<div
884883
className="mx-auto mt-4"
885884
style={{
@@ -896,9 +895,6 @@ export default function General() {
896895
onCropChange={setBannerCrop}
897896
onZoomChange={setBannerZoom}
898897
onCropComplete={onBannerCropComplete}
899-
style={{
900-
containerStyle: { height: '100%', width: '100%' },
901-
}}
902898
/>
903899
</div>
904900
)}

0 commit comments

Comments
 (0)