Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 8 additions & 1 deletion src/components/common/Post/PostHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface PostHeaderProps {
postDate: string;
creatorId?: number;
type?: 'post' | 'reply';
isWriter?: boolean;
}

const PostHeader = ({
Expand All @@ -18,12 +19,18 @@ const PostHeader = ({
postDate,
creatorId,
type = 'post',
isWriter,
}: PostHeaderProps) => {
const navigate = useNavigate();

const handleClick = () => {
if (creatorId) {
navigate(`/otherfeed/${creatorId}`);
// isWriter가 true면 MyFeedPage로, false면 OtherFeedPage로 이동
if (isWriter) {
navigate(`/myfeed/${creatorId}`);
} else {
navigate(`/otherfeed/${creatorId}`);
}
}
};

Expand Down
3 changes: 3 additions & 0 deletions src/components/common/Post/Reply.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { deleteComment } from '@/api/comments/deleteComment';

interface ReplyProps extends CommentData {
onDelete?: () => void;
isWriter?: boolean;
}

const Reply = ({
Expand All @@ -27,6 +28,7 @@ const Reply = ({
likeCount: initialLikeCount,
isDeleted,
onDelete,
isWriter,
}: ReplyProps) => {
const [liked, setLiked] = useState(isLike);
const [likeCount, setLikeCount] = useState<number>(initialLikeCount);
Expand Down Expand Up @@ -121,6 +123,7 @@ const Reply = ({
aliasColor={aliasColor}
postDate={postDate}
creatorId={creatorId}
isWriter={isWriter}
type="reply"
/>
<ReplySection onClick={handleMoreClick}>
Expand Down
3 changes: 3 additions & 0 deletions src/components/common/Post/SubReply.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { deleteComment } from '@/api/comments/deleteComment';

interface SubReplyProps extends ReplyData {
onDelete?: () => void;
isWriter?: boolean;
}

const SubReply = ({
Expand All @@ -29,6 +30,7 @@ const SubReply = ({
isLike,
isDeleted,
onDelete,
isWriter,
}: SubReplyProps) => {
const [liked, setLiked] = useState<boolean>(isLike);
const [currentLikeCount, setCurrentLikeCount] = useState<number>(likeCount);
Expand Down Expand Up @@ -143,6 +145,7 @@ const SubReply = ({
aliasColor={aliasColor}
postDate={postDate}
creatorId={creatorId}
isWriter={isWriter}
type="reply"
/>
<ReplySection onClick={handleMoreClick}>
Expand Down
14 changes: 11 additions & 3 deletions src/components/feed/OtherFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@ interface OtherFeedProps {
isMyFeed?: boolean;
profileData?: OtherProfileData | null;
userId?: number;
showFollowButton?: boolean; // showFollowButton prop 추가
}

const OtherFeed = ({ posts = [], profileData, userId }: OtherFeedProps) => {
const OtherFeed = ({
posts = [],
profileData,
userId,
showFollowButton,
isMyFeed,
}: OtherFeedProps) => {
const hasPosts = posts.length > 0;

if (!profileData) {
Expand All @@ -25,19 +32,20 @@ const OtherFeed = ({ posts = [], profileData, userId }: OtherFeedProps) => {
<Container>
<Profile
userId={userId}
showFollowButton={true}
showFollowButton={showFollowButton !== undefined ? showFollowButton : !profileData.isWriter}
isFollowing={profileData.isFollowing}
profileImageUrl={profileData.profileImageUrl}
nickname={profileData.nickname}
aliasName={profileData.aliasName}
aliasColor={profileData.aliasColor}
followerCount={profileData.followerCount}
latestFollowerProfileImageUrls={profileData?.latestFollowerProfileImageUrls || []}
isMyFeed={isMyFeed}
/>
<TotalBar count={profileData.totalFeedCount} />
{hasPosts ? (
posts.map(post => (
<FeedPost key={post.feedId} showHeader={false} isMyFeed={false} {...post} />
<FeedPost key={post.feedId} showHeader={false} isMyFeed={isMyFeed} {...post} />
))
) : (
<EmptyState>
Expand Down
12 changes: 7 additions & 5 deletions src/components/feed/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface ProfileProps {
followerCount: number;
latestFollowerProfileImageUrls?: string[];
userId?: number;
isMyFeed?: boolean;
}

const Profile = ({
Expand All @@ -26,6 +27,7 @@ const Profile = ({
followerCount,
latestFollowerProfileImageUrls = [],
userId,
isMyFeed,
}: ProfileProps) => {
const [followed, setFollowed] = useState(isFollowing);
const { openPopup } = usePopupStore();
Expand Down Expand Up @@ -54,14 +56,14 @@ const Profile = ({
console.log(`${nickname} - ${response.data.isFollowing ? '띱 완료' : '띱 취소'}`);

// Snackbar 표시
const message = response.data.isFollowing
? `${nickname}님을 띱 했어요.`
const message = response.data.isFollowing
? `${nickname}님을 띱 했어요.`
: `${nickname}님을 띱 취소했어요.`;

openPopup('snackbar', {
message,
variant: 'top',
onClose: () => {}
onClose: () => {},
});
} catch (error) {
console.error('팔로우/언팔로우 실패:', error);
Expand All @@ -81,7 +83,7 @@ const Profile = ({
</div>
</div>
</div>
{showFollowButton && (
{showFollowButton && !isMyFeed && (
<div className="followbutton" onClick={toggleFollow}>
{followed ? '띱 취소' : '띱 하기'}
</div>
Expand Down
8 changes: 8 additions & 0 deletions src/data/postData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const mockPosts: PostData[] = [
isSaved: false,
isLiked: true,
isPublic: true,
isWriter: false,
},
{
feedId: 56,
Expand All @@ -39,6 +40,7 @@ export const mockPosts: PostData[] = [
isSaved: true,
isLiked: false,
isPublic: false,
isWriter: false,
},
{
feedId: 58,
Expand All @@ -58,6 +60,7 @@ export const mockPosts: PostData[] = [
isSaved: false,
isLiked: false,
isPublic: true,
isWriter: false,
},
];

Expand All @@ -80,6 +83,7 @@ export const mockFeedPost: FeedPostProps = {
isSaved: true,
isLiked: false,
isPublic: true,
isWriter: false,
};

// 📌 댓글/대댓글(Mock)
Expand All @@ -97,6 +101,7 @@ export const mockCommentList: ReplyDataProps[] = [
likeCount: 1,
isLike: false,
isDeleted: false,
isWriter: false,
replyList: [
{
parentCommentCreatorNickname: 'User31',
Expand All @@ -110,6 +115,7 @@ export const mockCommentList: ReplyDataProps[] = [
content: '맞아요, 저도 너무 좋았어요!맞아요, 저도 너무 좋았어요!',
likeCount: 2,
isLike: false,
isWriter: false,
},
{
parentCommentCreatorNickname: 'User35',
Expand All @@ -123,6 +129,7 @@ export const mockCommentList: ReplyDataProps[] = [
content: '추천 감사합니다!',
likeCount: 123,
isLike: true,
isWriter: false,
},
],
},
Expand All @@ -139,5 +146,6 @@ export const mockCommentList: ReplyDataProps[] = [
isLike: true,
replyList: [],
isDeleted: false,
isWriter: false,
},
];
2 changes: 1 addition & 1 deletion src/hooks/useOAuthToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const useOAuthToken = () => {

// 서버에 토큰 발급 요청
apiClient
.post('/api/set-cookie', { loginTokenKey }, { withCredentials: true })
.post('/auth/set-cookie', { loginTokenKey }, { withCredentials: true })
.then(response => {
console.log('✅ 토큰 발급 성공:', response.data);
// URL에서 code 파라미터 제거
Expand Down
92 changes: 92 additions & 0 deletions src/pages/feed/MyFeedPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { useNavigate, useParams } from 'react-router-dom';
import { useState, useEffect } from 'react';
import styled from '@emotion/styled';
import NavBar from '../../components/common/NavBar';
import TitleHeader from '@/components/common/TitleHeader';
import writefab from '../../assets/common/writefab.svg';
import leftArrow from '../../assets/common/leftArrow.svg';
import OtherFeed from '@/components/feed/OtherFeed';
import { getOtherFeed, type OtherFeedItem } from '@/api/feeds/getOtherFeed';
import { getOtherProfile } from '@/api/users/getOtherProfile';
import type { OtherProfileData } from '@/types/profile';

const Container = styled.div`
min-width: 320px;
max-width: 767px;
margin: 0 auto;
`;

const MyFeedPage = () => {
const navigate = useNavigate();
const { userId } = useParams<{ userId: string }>();
const [feedData, setFeedData] = useState<OtherFeedItem[]>([]);
const [profileData, setProfileData] = useState<OtherProfileData | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);

const handleBackClick = () => {
navigate(-1);
};

// 다른 사용자 피드 및 프로필 데이터 로드
useEffect(() => {
const loadOtherData = async () => {
if (!userId) {
setError('사용자 ID가 없습니다.');
setLoading(false);
return;
}

try {
setLoading(true);

const [feedResponse, profileResponse] = await Promise.all([
getOtherFeed(Number(userId)),
getOtherProfile(Number(userId)),
]);

console.log('🔍 MyFeedPage - Profile Response:', profileResponse.data);
console.log('🔍 MyFeedPage - isWriter 값:', profileResponse.data.isWriter);

setFeedData(feedResponse.data.feedList);
setProfileData(profileResponse.data);
setError(null);
} catch (err) {
console.error('다른 사용자 데이터 로드 실패:', err);
setError('사용자 정보를 불러오는데 실패했습니다.');
} finally {
setLoading(false);
}
};

loadOtherData();
}, [userId]);

if (loading) {
return <></>;
}

if (error) {
return <></>;
}

return (
<Container>
<TitleHeader
leftIcon={<img src={leftArrow} alt="뒤로가기" />}
onLeftClick={handleBackClick}
/>
<OtherFeed
userId={Number(userId)}
showHeader={false}
posts={feedData}
isMyFeed={true}
profileData={profileData}
showFollowButton={false} // 띱하기 버튼 숨김
/>
<NavBar src={writefab} path="/post/create" />
</Container>
);
};

export default MyFeedPage;
1 change: 1 addition & 0 deletions src/pages/feed/OtherFeedPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const OtherFeedPage = () => {
posts={feedData}
isMyFeed={false}
profileData={profileData}
showFollowButton={!profileData?.isWriter} // isWriter가 true면 팔로우 버튼 숨김
/>
<NavBar src={writefab} path="/post/create" />
</Container>
Expand Down
2 changes: 2 additions & 0 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import GroupSearch from './groupSearch/GroupSearch';
import Search from './search/Search';
import ApplyBook from './search/ApplyBook';
import OtherFeedPage from './feed/OtherFeedPage';
import MyFeedPage from './feed/MyFeedPage';
import FollowerListPage from './feed/FollowerListPage';
import TodayWords from './today-words/TodayWords';
import SearchBook from './searchBook/SearchBook';
Expand Down Expand Up @@ -69,6 +70,7 @@ const Router = () => {
<Route path="search/book/:isbn" element={<SearchBook />} />
<Route path="search/book/group" element={<SearchBookGroup />} />
<Route path="otherfeed/:userId" element={<OtherFeedPage />} />
<Route path="myfeed/:userId" element={<MyFeedPage />} />
<Route path="follow/:type/:userId" element={<FollowerListPage />} />
<Route path="follow/:type" element={<FollowerListPage />} />
<Route path="today-words/:roomId" element={<TodayWords />} />
Expand Down
3 changes: 3 additions & 0 deletions src/types/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface PostData {
isSaved?: boolean;
isLiked?: boolean;
isPublic?: boolean;
isWriter?: boolean;
}

export interface FeedListProps {
Expand Down Expand Up @@ -50,6 +51,7 @@ export interface SubReplyDataProps {
likeCount: number;
replyId: number;
isLike: boolean;
isWriter: boolean;
}

// 댓글(Reply)
Expand All @@ -65,6 +67,7 @@ export interface ReplyDataProps {
likeCount: number;
isLike: boolean;
isDeleted: boolean;
isWriter: boolean;
replyList: SubReplyDataProps[];
}

Expand Down
1 change: 1 addition & 0 deletions src/types/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export interface MyProfileData {
// 다른 사용자 프로필 정보 타입 (isFollowing 포함)
export interface OtherProfileData extends MyProfileData {
isFollowing: boolean;
isWriter?: boolean;
}