-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #293 from boostcampwm-2021/refactor/teamsetting
Refactor/teamsetting
- Loading branch information
Showing
27 changed files
with
327 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { teamState } from "@Recoil/TeamData"; | ||
import { userState } from "@Recoil/UserData"; | ||
import { postImage } from "@Util/data"; | ||
import { useEffect, useRef, useState } from "react"; | ||
import { useRecoilValue, useSetRecoilState } from "recoil"; | ||
|
||
export const useHandleImageEdit = (checkPathName: boolean) => { | ||
const { id, gid } = useRecoilValue(userState); | ||
const setUserInfo = useSetRecoilState(userState); | ||
const setTeamInfo = useSetRecoilState(teamState); | ||
|
||
const handleImageEdit = (imageFile: Blob) => async () => { | ||
const targetId = checkPathName ? id : String(gid); | ||
const handler = checkPathName ? setUserInfo : setTeamInfo; | ||
const url = await postImage(imageFile, targetId); | ||
|
||
handler((prev: any) => ({ | ||
...prev, | ||
image: url, | ||
})); | ||
}; | ||
|
||
return handleImageEdit; | ||
}; | ||
|
||
const initBlob = new Blob(); | ||
const reader = new FileReader(); | ||
const defaultImage = "/Asset/meetingImage.png"; | ||
|
||
export const useHandleImage = (checkPathName: boolean) => { | ||
const [imageFile, setImageFile] = useState<Blob>(initBlob); | ||
const { image: userImage } = useRecoilValue(userState); | ||
const { image: teamImage } = useRecoilValue(teamState); | ||
const [profileImage, setProfileImage] = useState<string | ArrayBuffer | null>((checkPathName ? userImage : teamImage) ?? defaultImage); | ||
|
||
const changeImage = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
if (!e.target.files) return; | ||
setImageFile(e.target.files[0]); | ||
}; | ||
|
||
useEffect(() => { | ||
if (imageFile === initBlob) return; | ||
reader.onloadend = () => { | ||
setProfileImage(reader.result); | ||
}; | ||
reader.readAsDataURL(imageFile); | ||
}, [imageFile]); | ||
|
||
return { imageFile, profileImage, changeImage }; | ||
}; | ||
|
||
export const useHandleImageClick = () => { | ||
const imageRef = useRef<HTMLInputElement | null>(null); | ||
const handleClickImage = () => (imageRef.current as HTMLInputElement).click(); | ||
return { imageRef, handleClickImage }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React from "react"; | ||
import { css } from "@emotion/react"; | ||
import { ProfileImage } from "@Atom/ProfileImage"; | ||
import { Button } from "@Atom/Button"; | ||
import { useGetParams } from "@Hook/useGetParams"; | ||
import { useHandleImage, useHandleImageClick, useHandleImageEdit } from "./InfoImage.hook"; | ||
|
||
export const InfoImage: React.FC = () => { | ||
const checkPathName = useGetParams("myInfo"); | ||
const { imageRef, handleClickImage } = useHandleImageClick(); | ||
const { imageFile, profileImage, changeImage } = useHandleImage(checkPathName); | ||
const handleImageEdit = () => useHandleImageEdit(checkPathName)(imageFile); | ||
|
||
return ( | ||
<div css={TeamInfoImageContainerStyle}> | ||
<ProfileImage type="Big" image={profileImage} onClick={handleClickImage}> | ||
<Button size="Small" onClick={handleImageEdit}> | ||
Edit | ||
</Button> | ||
</ProfileImage> | ||
<input ref={imageRef} onChange={changeImage} css={imageInputStyle} type="file" accept="image/*" /> | ||
</div> | ||
); | ||
}; | ||
|
||
const TeamInfoImageContainerStyle = css` | ||
width: 100%; | ||
height: 100%; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
`; | ||
|
||
const imageInputStyle = css` | ||
display: none; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from "react"; | ||
import { checkLogin, passToLoginPage } from "@Util/."; | ||
import { ChildrenType } from "@Util/type"; | ||
|
||
export const LoginUserRouter = ({ children }: ChildrenType) => { | ||
// if (!checkLogin()) { | ||
// passToLoginPage(); | ||
// return null; | ||
// } | ||
return <>{children}</>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
export * from "./InfoContainer"; | ||
export * from "./InfoImageContainer"; | ||
export * from "./ProfileImageContainer"; | ||
export * from "./TeamButtonContainer"; | ||
export * from "./UserContainer"; |
18 changes: 7 additions & 11 deletions
18
client/src/Component/Molecules/Team/TeamSettingButtonContainer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.