Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/#114 image compression (+webp) #208

Merged
merged 5 commits into from
Feb 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 13 additions & 6 deletions src/@components/JoinPage/UserProfilePage/ProfileImage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,37 @@ import { useState } from "react";

import { IcAddProfileBtn } from "../../../../asset/icon";
import { ImgDefaultBigProfile } from "../../../../asset/image";
import compressImage from "../../../../util/imageCompressor";
import { St } from "./style";

interface ProfileImageProps {
setImage: (file: File) => void;
setProfileImage: (file: File) => void;
}

const MAX_IMAGE_SIZE = 80 * 2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

최대치가 *2인 이유가 있을까요?!?!

Copy link
Member Author

@joohaem joohaem Feb 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

80으로 직접 명시를 해도 좋은데, 레티나 디스플레이 대응 이슈로 인해 2배 정도로 지정하면 좋다고 알아요!!!~

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하 구렇구나😆😆


export default function ProfileImage(props: ProfileImageProps) {
const { setImage } = props;
const [imgUrl, setImgUrl] = useState<string>("");
const { setProfileImage } = props;
const [previewImgUrl, setPreviewImgUrl] = useState("");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<string> 요거 있는거랑 없는거랑 상관업숴?-?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"" 로 string인게 이미 추론되어서, 직접 명시할 필요 없어!!


const handleImagePatch = async (e: React.ChangeEvent<HTMLInputElement>) => {
if (e.target.files === null) return;

const selectedImg = e.target.files[0];
setImgUrl(URL.createObjectURL(selectedImg));
const compressedSelectedImg = await compressImage(selectedImg, {
maxWidth: MAX_IMAGE_SIZE,
maxHeight: MAX_IMAGE_SIZE,
});
Comment on lines +22 to +25
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요로코롬 사용하눈 거구나👀👀 므싯다요😎😎😎😎


setImage(selectedImg);
setProfileImage(compressedSelectedImg);
setPreviewImgUrl(URL.createObjectURL(compressedSelectedImg));
};

return (
<St.ProfileImage>
<St.ImageContainer>
<St.ImageWrapper>
<St.AddImage src={imgUrl ? imgUrl : ImgDefaultBigProfile} alt="프로필" />
<St.AddImage src={previewImgUrl ? previewImgUrl : ImgDefaultBigProfile} alt="프로필" />
</St.ImageWrapper>
<St.AddBtnWrapper>
<IcAddProfileBtn />
Expand Down
7 changes: 4 additions & 3 deletions src/@components/JoinPage/UserProfilePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function UserProfilePage() {
const [birthData, setBirthData] = useState<string>(""); // 생년월일
// TODO :: 변수명 gender로 바꾸기
const [isSelected, setIsSelected] = useState<string>(""); // 성별
const [image, setImage] = useState(ImgDefaultBigProfile); // 이미지
const [profileImage, setProfileImage] = useState(ImgDefaultBigProfile); // 이미지

const [isChecked, setIsChecked] = useState(false); //닉넴 중복 확인
const [isInComplete, setisInComplete] = useState(false); // 다음으로 버튼
Expand All @@ -44,7 +44,7 @@ export default function UserProfilePage() {
currentFormData.append("birthday", birthData);

if (isSelected) currentFormData.append("gender", isSelected);
if (image) currentFormData.append("imgFile", image);
if (profileImage) currentFormData.append("imgFile", profileImage);

return currentFormData;
});
Expand All @@ -64,7 +64,8 @@ export default function UserProfilePage() {
<St.ProfileContainer>
<St.Title>프로필을 설정해주세요</St.Title>
<St.SubTitle>프로필 사진(선택)</St.SubTitle>
<ProfileImage setImage={setImage} />
<ProfileImage setProfileImage={setProfileImage} />

<St.SubTitle>닉네임(필수)</St.SubTitle>
<St.Requirement>※ 한글, 영문, 숫자 상관없이 8자 이내</St.Requirement>
<ProfileNickname
Expand Down