Skip to content

Commit

Permalink
[Refactor][Comment] 댓글페이지 개선
Browse files Browse the repository at this point in the history
  • Loading branch information
ysh4296 committed Nov 26, 2023
1 parent b1aade7 commit 6be4e27
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 541 deletions.
10 changes: 0 additions & 10 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import InsightSampleScreen from './src/screens/onboarding/InsightSampleScreen';
import Tabs from './src/screens/Main/Tabs';
import ChallengeParticipationScreen from './src/screens/Main/challenge/ChallengeParticipationScreen';
import ShareScreen from './src/screens/detailedPost/ShareScreen';
import CommentsScreen from './src/screens/detailedPost/CommentsScreen';
import ProfileEditScreen from './src/screens/Main/mypage/ProfileEditScreen';
import NicknameEditingScreen from './src/screens/Main/mypage/NicknameEditingScreen';
import IntroductionEditingScreen from './src/screens/Main/mypage/IntroductionEditingScreen';
Expand Down Expand Up @@ -466,15 +465,6 @@ export default function App() {
headerStyle: { backgroundColor: '#F1F1E9' },
}}
/>
<Stack.Screen
name={'Comments'}
component={CommentsScreen}
options={{
...headerOptions,
cardStyle: { backgroundColor: 'white' },
title: '댓글',
}}
/>
<Stack.Screen
name={'Statistics'}
component={StatisticsScreen}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@react-navigation/stack": "^6.3.17",
"@tanstack/react-query": "^4.14.3",
"axios": "^0.27.2",
"expo": "^48.0.0",
"expo": "^49.0.0",
"expo-app-loading": "~2.1.1",
"expo-asset": "~8.9.1",
"expo-blur": "~12.2.2",
Expand Down
15 changes: 1 addition & 14 deletions src/components/comments/CommentInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ interface CommentInputProps {
replyInfo?: ReplyInfo;
onCancelReply: () => void;
onCreate: (response: CommentCreateResponse) => void;
setComment: Dispatch<SetStateAction<Comment[]>>;
}

export type ReplyInfo = {
Expand All @@ -27,25 +26,13 @@ const bottom = Platform.OS === 'ios' ? 80 : 0;

const CommentInput = forwardRef(
(
{ insightId, replyInfo, onCancelReply, onCreate, setComment }: CommentInputProps,
{ insightId, replyInfo, onCancelReply, onCreate }: CommentInputProps,
ref: React.LegacyRef<TextInput>,
) => {
const [input, setInput] = useState<string>('');
const { mutate: createComment } = useMutation(InsightAPI.createComment, {
onSuccess: (response) => {
onCreate(response);
setComment((prev) => {
if (replyInfo) {
const index = prev.findIndex((comment) => comment.id === replyInfo.id);
const updatedReply = {
...prev[index],
replies: [response.data as Reply, ...(prev[index].replies ?? [])],
};

return [...prev.slice(0, index), updatedReply, ...prev.slice(index + 1)];
}
return [response.data, ...prev] as Comment[];
});
},
});

Expand Down
38 changes: 38 additions & 0 deletions src/screens/detailedPost/CommentList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react';
import Comment from '../../components/comments/Comment';
import { ReplyInfo } from '../../components/comments/CommentInput';
import ReplyList from './ReplyList';

interface CommentListProps {
insightId: number;
authorId: number;
handleReplyClick: (info: ReplyInfo) => void;
commentList?: Comment[];
}

const CommentList = ({ insightId, authorId, handleReplyClick, commentList }: CommentListProps) => {
return (
<>
{commentList?.flatMap((item, index) => (
<>
<Comment
key={`${item.id} ${index}`}
content={item.content}
nickname={item.writer?.name}
title={item.writer?.title}
createdAt={item.createdAt}
isInsightWriter={item.writer?.id === authorId}
commentWriterId={item.writer?.id}
image={item.writer?.image}
isReply={false}
onReply={() => handleReplyClick({ id: item.id, nickname: item.writer?.name ?? '' })}
commentId={item.id}
/>
<ReplyList insightId={insightId} parentId={item.id} authorId={authorId} />
</>
))}
</>
);
};

export default CommentList;
146 changes: 0 additions & 146 deletions src/screens/detailedPost/CommentSection.tsx

This file was deleted.

Loading

0 comments on commit 6be4e27

Please sign in to comment.