From 83f89ed4b71cfc723026b076d7244909b3b9a299 Mon Sep 17 00:00:00 2001 From: heeyongKim <166043860+heeeeyong@users.noreply.github.com> Date: Wed, 20 Aug 2025 22:28:05 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=82=B4=20=ED=94=BC=EB=93=9C=EC=9D=B8?= =?UTF-8?q?=EA=B2=BD=EC=9A=B0,=20=EB=B9=84=EB=B0=80=EA=B8=80=20=EB=B3=B4?= =?UTF-8?q?=EC=9D=B4=EA=B2=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/feed/OtherFeed.tsx | 52 ++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/src/components/feed/OtherFeed.tsx b/src/components/feed/OtherFeed.tsx index e49615c9..25c9a4b6 100644 --- a/src/components/feed/OtherFeed.tsx +++ b/src/components/feed/OtherFeed.tsx @@ -1,10 +1,16 @@ import styled from '@emotion/styled'; +import { useState, useEffect } from 'react'; import Profile from './Profile'; import FeedPost from './FeedPost'; import TotalBar from './TotalBar'; import { colors, typography } from '../../styles/global/global'; import type { OtherFeedItem } from '@/api/feeds/getOtherFeed'; import type { OtherProfileData } from '@/types/profile'; +import { getOtherFeed } from '@/api/feeds/getOtherFeed'; +import { getMyFeeds } from '@/api/feeds/getMyFeed'; +import { getMyProfile } from '@/api/feeds/getMyProfile'; +import type { PostData } from '@/types/post'; +import LoadingSpinner from '../common/LoadingSpinner'; interface OtherFeedProps { showHeader?: boolean; @@ -24,7 +30,43 @@ const OtherFeed = ({ isMyFeed, isMyself, }: OtherFeedProps) => { - const hasPosts = posts.length > 0; + const [feedPosts, setFeedPosts] = useState(posts); + const [loading, setLoading] = useState(false); + const [totalFeedCount, setTotalFeedCount] = useState(profileData?.totalFeedCount || 0); + + // isMyself 값에 따라 적절한 API 호출 + useEffect(() => { + const loadFeeds = async () => { + if (!userId) return; + + try { + setLoading(true); + + if (isMyself) { + // 자신의 피드인 경우 getMyFeeds와 getMyProfile 병렬 호출 + const [feedsResponse, profileResponse] = await Promise.all([ + getMyFeeds(), + getMyProfile() + ]); + setFeedPosts(feedsResponse.data.feedList); + // getMyProfile에서 총 피드 수 업데이트 + setTotalFeedCount(profileResponse.data.totalFeedCount); + } else { + // 다른 사용자의 피드인 경우 getOtherFeed 호출 + const response = await getOtherFeed(userId); + setFeedPosts(response.data.feedList); + } + } catch (error) { + console.error('피드 로드 실패:', error); + } finally { + setLoading(false); + } + }; + + loadFeeds(); + }, [userId, isMyself]); + + const hasPosts = feedPosts.length > 0; if (!profileData) { return <>; @@ -46,9 +88,11 @@ const OtherFeed = ({ latestFollowerProfileImageUrls={profileData?.latestFollowerProfileImageUrls || []} isMyFeed={isMyFeed} /> - - {hasPosts ? ( - posts.map(post => ( + + {loading ? ( + + ) : hasPosts && !loading ? ( + feedPosts.map(post => ( )) ) : (