Skip to content

Commit

Permalink
✨add reload when editing comment
Browse files Browse the repository at this point in the history
  • Loading branch information
GlassyFoozle authored Feb 1, 2025
2 parents f55e943 + 035a627 commit ee5efb4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/components/CommentEditWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { CommentEditWindowProps } from '../typings/communityPost';
const CommentEditWindow = ({
CommentInfo,
closeWindow,
onCommentEdit,
}: CommentEditWindowProps) => {
const [commentBody, setCommentBody] = useState<string>(CommentInfo.content);

Expand All @@ -36,6 +37,7 @@ const CommentEditWindow = ({
}

closeWindow();
onCommentEdit();
} catch (error) {
console.error('수정 중 에러 발생:', error);
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/CommentItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { getTimeAgo } from '../utils/utils';
import CommentEditWindow from './CommentEditWindow';
import Overlay from './Overlay';

const Comment = ({ CommentInfo }: CommentProps) => {
const Comment = ({ CommentInfo, onCommentEdit }: CommentProps) => {
const [isOverlayOpen, setIsOverlayOpen] = useState<boolean>(false);
const [isCommentEditOpen, setIsCommentEditOpen] = useState<boolean>(false);
const [isLiked, setIsLiked] = useState<boolean>(CommentInfo.isLiked);
Expand Down Expand Up @@ -186,6 +186,7 @@ const Comment = ({ CommentInfo }: CommentProps) => {
closeWindow={() => {
setIsCommentEditOpen(false);
}}
onCommentEdit={onCommentEdit}
/>
)}
</div>
Expand Down
8 changes: 7 additions & 1 deletion src/pages/CommunityPostPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,13 @@ const CommunityPostPage = () => {
: 0;
})
.map((Comment, index) => (
<CommentItem key={index} CommentInfo={Comment} />
<CommentItem
key={index}
CommentInfo={Comment}
onCommentEdit={() => {
void fetchPost();
}}
/>
))}
</div>
)}
Expand Down
2 changes: 2 additions & 0 deletions src/typings/communityPost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ type Comment = {

export type CommentProps = {
CommentInfo: Comment;
onCommentEdit: () => void;
};

export type CommentEditWindowProps = {
CommentInfo: Comment;
closeWindow: () => void;
onCommentEdit: () => void;
};

export const TagsArray = [
Expand Down

0 comments on commit ee5efb4

Please sign in to comment.