-
Notifications
You must be signed in to change notification settings - Fork 26
이희선 11주차 과제 제출 #91
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
base: heeseon
Are you sure you want to change the base?
이희선 11주차 과제 제출 #91
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import { useEffect, useState } from "react"; | ||
| import { updateInfo } from "../../apis/api"; | ||
|
|
||
| export const InfoElement = (props) => { | ||
| const { infoLabel, infoContent } = props; | ||
| const [content, setContent] = useState(infoContent); | ||
| const [isEdit, setIsEdit] = useState(false); | ||
|
|
||
| const handleEditInfo = (e) => { | ||
| e.preventDefault(); | ||
| updateInfo({ [infoLabel]: content }); | ||
| setContent(infoContent); | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| setContent(infoContent); | ||
| }, [infoContent]); | ||
|
Comment on lines
+15
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 부분이 왜 있는지 설명해주실 수 있나요? |
||
|
|
||
| return ( | ||
| <div className="w-full flex-col mb-2"> | ||
| <p>{infoLabel}: </p> | ||
| <div className="w-full flex mb-2 justify-between"> | ||
| <div className="w-full"> | ||
| {isEdit ? ( | ||
| <div className="w-full flex flex-col items-center"> | ||
| <input | ||
| className="input m-4" | ||
| value={content} | ||
| onChange={(e) => setContent(e.target.value)} | ||
| /> | ||
| <div className="flex items-center gap-4"> | ||
| <button className="button" onClick={(e) => handleEditInfo(e)}> | ||
| 수정하기 | ||
| </button> | ||
| <button | ||
| className="button mr-3" | ||
| onClick={() => { | ||
| setIsEdit(!isEdit); | ||
| setContent(infoContent); | ||
| }} | ||
| > | ||
| 취소하기 | ||
| </button> | ||
| </div> | ||
| </div> | ||
| ) : ( | ||
| <div className="w-full flex flex-row justify-center p-2 mb-5 border-b-2"> | ||
| <p className="w-full text-lg mr-5 p-3">{infoContent}</p> | ||
| <button className="button w-20" onClick={() => setIsEdit(!isEdit)}> | ||
| 변경 | ||
| </button> | ||
| </div> | ||
| )} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,60 @@ | ||||||||||||||||||||||
| import { useState, useEffect } from "react"; | ||||||||||||||||||||||
| import { InfoElement } from "../components/Info/InfoElement"; | ||||||||||||||||||||||
| import { getUser, getPosts } from "../apis/api"; | ||||||||||||||||||||||
| import { SmallPost } from "../components/Posts"; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const MyPage = () => { | ||||||||||||||||||||||
| const [email, setEmail] = useState(""); | ||||||||||||||||||||||
| const [username, setUsername] = useState(""); | ||||||||||||||||||||||
| const [college, setCollege] = useState(""); | ||||||||||||||||||||||
| const [major, setMajor] = useState(""); | ||||||||||||||||||||||
|
Comment on lines
+7
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 굳이 여러 state를 쓰지말고, 하나의 formdata에 넣는게 효율적으로 보입니다! |
||||||||||||||||||||||
| const [postList, setPostList] = useState([]); | ||||||||||||||||||||||
| const [user, setUser] = useState(null); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||
| const getPostsAPI = async () => { | ||||||||||||||||||||||
| const posts = await getPosts(); | ||||||||||||||||||||||
| setPostList(posts); | ||||||||||||||||||||||
| console.log(posts); | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
| getPostsAPI(); | ||||||||||||||||||||||
| }, []); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||
| const getInfoAPI = async () => { | ||||||||||||||||||||||
| const info = await getUser(); | ||||||||||||||||||||||
| setEmail(info.user.email); | ||||||||||||||||||||||
| setUsername(info.user.username); | ||||||||||||||||||||||
| setCollege(info.college); | ||||||||||||||||||||||
| setMajor(info.major); | ||||||||||||||||||||||
|
Comment on lines
+27
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
위에서 이어진 내용으로, 저라면 이렇게 할 것 같습니다! |
||||||||||||||||||||||
| setUser(info.user); | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
| getInfoAPI(); | ||||||||||||||||||||||
| }, []); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| return ( | ||||||||||||||||||||||
| <> | ||||||||||||||||||||||
| <div className="flex flex-col items-center w-1/3"> | ||||||||||||||||||||||
| <h3 className=" font-bold text-4xl mb-10">My Info</h3> | ||||||||||||||||||||||
| <InfoElement infoLabel="email" infoContent={email}/> | ||||||||||||||||||||||
| <InfoElement infoLabel="username" infoContent={username}/> | ||||||||||||||||||||||
| <InfoElement infoLabel="college" infoContent={college}/> | ||||||||||||||||||||||
| <InfoElement infoLabel="major" infoContent={major}/> | ||||||||||||||||||||||
| </div> | ||||||||||||||||||||||
| <div className="flex flex-col items-center mb-20 w-2/3"> | ||||||||||||||||||||||
| <h3 className=" font-bold text-4xl mt-10 mb-10">My Posts</h3> | ||||||||||||||||||||||
| <div className="grid grid-cols-2 px-10 gap-4"> | ||||||||||||||||||||||
| {postList.filter((post) => post?.author.id === user?.id | ||||||||||||||||||||||
| ).map((post) => ( | ||||||||||||||||||||||
| <SmallPost key={post.id} post={post} /> | ||||||||||||||||||||||
| ))} | ||||||||||||||||||||||
| </div> | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| </div> | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| </> | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| export default MyPage; | ||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기서
setContent를 한 이유가 무엇인가요?