From f0ee71f494f8ed623157ba8e4adf30d83e75e698 Mon Sep 17 00:00:00 2001 From: zziglet Date: Wed, 4 Sep 2024 11:00:20 +0900 Subject: [PATCH 1/8] =?UTF-8?q?fix=20:=20user=5Fid=EB=A5=BC=20access=20tok?= =?UTF-8?q?en=EC=9C=BC=EB=A1=9C=20=ED=95=B4=EC=84=9D=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD=20(#7)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit user_id를 받는 모든 api의 방식을 수정했습니다. --- src/components/bars/TitleBar.jsx | 1 + src/user.json | 12 ------------ 2 files changed, 1 insertion(+), 12 deletions(-) delete mode 100644 src/user.json diff --git a/src/components/bars/TitleBar.jsx b/src/components/bars/TitleBar.jsx index 57d178c..5c92030 100644 --- a/src/components/bars/TitleBar.jsx +++ b/src/components/bars/TitleBar.jsx @@ -140,6 +140,7 @@ function TitleBar(props) { {isProfileMenuOpen && ( + nav('/mypage')}>마이페이지 로그아웃 nav('/settings')}>설정 diff --git a/src/user.json b/src/user.json deleted file mode 100644 index 73d4a30..0000000 --- a/src/user.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "user": { - "id": "jinji123", - "bio": "안녕하시소", - "tier": 1, - "score": 75, - "follower": 20, - "following": 35, - "profile": "https://example.com/path/to/profile.png", - "background": "https://example.com/path/to/background.png" - } -} From 4f81245b69c916c8cd70ca50861bfffda5a11e27 Mon Sep 17 00:00:00 2001 From: zziglet Date: Wed, 4 Sep 2024 11:41:11 +0900 Subject: [PATCH 2/8] =?UTF-8?q?fix=20:=20user=5Fid=EB=A5=BC=20access=20tok?= =?UTF-8?q?en=EC=9C=BC=EB=A1=9C=20=ED=95=B4=EC=84=9D=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95=20(#7)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit user_id 관련 api 모두 수정했습니다. --- src/components/user/Wandubat.jsx | 4 +++- src/pages/LoginAlertPage.jsx | 2 +- src/pages/MyPage.jsx | 22 +++++++++++++++++----- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/components/user/Wandubat.jsx b/src/components/user/Wandubat.jsx index d5b3981..9c467ea 100644 --- a/src/components/user/Wandubat.jsx +++ b/src/components/user/Wandubat.jsx @@ -141,12 +141,14 @@ function Wandubat(props) { useEffect(() => { const fetchWandu = async () => { try { + const accessToken = localStorage.getItem('accessToken'); const response = await fetch( - `http://3.37.43.129/api/user/${userId}/seriousness/seriousness-field`, + `http://3.37.43.129/api/user/seriousness/seriousness-field`, { method: 'GET', headers: { 'Content-Type': 'application/json', + 'Authorization': `Bearer ${accessToken}`, }, } ); diff --git a/src/pages/LoginAlertPage.jsx b/src/pages/LoginAlertPage.jsx index 094c5d3..3fa5e4a 100644 --- a/src/pages/LoginAlertPage.jsx +++ b/src/pages/LoginAlertPage.jsx @@ -94,7 +94,7 @@ const LoginAlertPage = ({ isOpen, onClose }) => { setIsLoggedIn(true); // 사용자 대시보드로 리디렉션 - navigate('/mypage'); + navigate('/'); } catch (error) { setError(error.message); } diff --git a/src/pages/MyPage.jsx b/src/pages/MyPage.jsx index 4eec066..6e50c6e 100644 --- a/src/pages/MyPage.jsx +++ b/src/pages/MyPage.jsx @@ -219,8 +219,16 @@ function MyPage() { useEffect(() => { const fetchTiers = async () => { try { + const accessToken = localStorage.getItem('accessToken'); const response = await fetch( - `http://3.37.43.129/api/user/${user.userId}/seriousness` + `http://3.37.43.129/api/user/seriousness`, + { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${accessToken}`, + }, + } ); if (!response.ok) { throw new Error('Failed to fetch user info'); @@ -235,9 +243,14 @@ function MyPage() { const fetchUserPosts = async () => { try { - const response = await fetch( - `http://3.37.43.129/api/user/${user.userId}/posts` - ); + const accessToken = localStorage.getItem('accessToken'); + const response = await fetch(`http://3.37.43.129/api/user/posts`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${accessToken}`, + }, + }); if (!response.ok) { throw new Error('Failed to fetch user posts'); } @@ -260,7 +273,6 @@ function MyPage() { - {/* data에서 user의 배경이미지와 연결 */} back From 8e362f5371a96348153f77b87c768856b60b69d5 Mon Sep 17 00:00:00 2001 From: zziglet Date: Wed, 4 Sep 2024 22:47:33 +0900 Subject: [PATCH 3/8] =?UTF-8?q?fix=20:=20mainpage=20nav=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(#7)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit mainpage에서 현재 위치한 mainbar item에 맞게 api를 호출하도록 수정하였습니다. --- src/pages/MainPage.jsx | 20 ++++++++++++-------- src/routes/Router.jsx | 6 +++--- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/pages/MainPage.jsx b/src/pages/MainPage.jsx index b61769b..cec50df 100644 --- a/src/pages/MainPage.jsx +++ b/src/pages/MainPage.jsx @@ -28,7 +28,8 @@ const MainBarWrapper = styled.div` background-color: white; `; -function MainPage() { +function MainPage(props) { + const { posttype } = props; const [posts, setPosts] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); @@ -36,12 +37,15 @@ function MainPage() { useEffect(() => { const fetchPosts = async () => { try { - const response = await fetch('http://3.37.43.129/api/posts/recent', { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - }); + const response = await fetch( + `http://3.37.43.129/api/posts/${posttype}`, + { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + } + ); if (!response.ok) { throw new Error('Failed to fetch user info'); } @@ -56,7 +60,7 @@ function MainPage() { }; fetchPosts(); - }, []); + }, [posttype]); return ( diff --git a/src/routes/Router.jsx b/src/routes/Router.jsx index b5152e4..c311018 100644 --- a/src/routes/Router.jsx +++ b/src/routes/Router.jsx @@ -10,7 +10,7 @@ function Router() { return ( - } /> + } /> {/* test: /mypage로 임시 url 설정 */} } /> } /> - } /> - } /> + } /> + } /> } /> } /> From d3a189715e05e133701e3a608a229081e1ba9298 Mon Sep 17 00:00:00 2001 From: zziglet Date: Wed, 4 Sep 2024 23:31:09 +0900 Subject: [PATCH 4/8] =?UTF-8?q?feat=20:=20follower,=20followin=20list=20?= =?UTF-8?q?=EC=B6=9C=EB=A0=A5=20(#7)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit user의 팔로워, 팔로잉 리스트 출력 구현하였습니다. --- src/components/user/FollowItem.jsx | 32 ++++++++++++--- src/components/user/FollowerList.jsx | 57 ++++++++++++++++++++++++++- src/components/user/FollowingList.jsx | 55 ++++++++++++++++++++++++++ src/pages/FollowListPage.jsx | 55 ++++++++++++++++++-------- src/routes/Router.jsx | 1 - 5 files changed, 176 insertions(+), 24 deletions(-) diff --git a/src/components/user/FollowItem.jsx b/src/components/user/FollowItem.jsx index 6aac7db..fae7c2a 100644 --- a/src/components/user/FollowItem.jsx +++ b/src/components/user/FollowItem.jsx @@ -52,17 +52,39 @@ const UserBio = styled.div` margin-right: 830px; `; -function FollowItem() { +function FollowItem({ props }) { + const { followeeId } = props; + const [user, setUser] = useState(null); + const [loading, setLoading] = useState(true); + + useEffect(() => { + const fetchUser = async () => { + const response = await fetch( + `http://3.37.43.129/api/users/${followeeId}` + ); + if (response.ok) { + const data = await response.json(); + setUser(data); + } + setLoading(false); + }; + + fetchUser(); + }, [followeeId]); + + if (loading) return
Loading...
; + if (!user) return null; + return ( - profile + profile - 나는다연 - @hongdari + {user.nickName} + {user.userId} - 안녕하시소 + {user.introduce}