Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 32 additions & 36 deletions src/components/settingComponents/generalPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -793,7 +795,7 @@ export default function General() {
.
</p>

{imageUrl && (
{imageUrl && isPopupOpen && (
<div
className="mx-auto mt-4"
style={{
Expand All @@ -810,9 +812,6 @@ export default function General() {
onCropChange={setCrop}
onZoomChange={setZoom}
onCropComplete={onCropComplete}
style={{
containerStyle: { height: '100%', width: '100%' },
}}
/>
</div>
)}
Expand Down Expand Up @@ -879,7 +878,7 @@ export default function General() {
.
</p>

{banner && (
{banner && isBannerPopupOpen && (
<div
className="mx-auto mt-4"
style={{
Expand All @@ -896,9 +895,6 @@ export default function General() {
onCropChange={setBannerCrop}
onZoomChange={setBannerZoom}
onCropComplete={onBannerCropComplete}
style={{
containerStyle: { height: '100%', width: '100%' },
}}
/>
</div>
)}
Expand Down