Skip to content

Commit

Permalink
제발 되라
Browse files Browse the repository at this point in the history
  • Loading branch information
D5ng committed Jun 24, 2024
1 parent 9be9749 commit 65fd593
Show file tree
Hide file tree
Showing 29 changed files with 793 additions and 1,190 deletions.
1 change: 0 additions & 1 deletion api/diaries/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { UpdateCommentData } from '@/types/story/details';
import { axiosInstance, axiosFileInstance } from '..';
import { DiaryData } from '@/types/diary/';
import { UpdateDiaryData } from '@/api/diaries';

interface ImageUpload {
images: File[];
Expand Down
2 changes: 0 additions & 2 deletions components/calendar-monthly/pet-checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import styles from './pet-radio.module.scss';
import { FieldValues, UseFormRegister } from 'react-hook-form';
import { IFormInput } from '@/types/calendar';
import { GrowthDetailsData } from '@/types/growth/details';
import { DiaryDetail } from '@/types/diary/details';
import { ChangeEvent } from 'react';

interface PetRadio {
register:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { FormEvent, FormEventHandler, KeyboardEventHandler, useEffect } from 'react';
import useRouterId from '@/hooks/utils/use-router-id';
import useTextarea from '@/hooks/utils/use-textarea';
import styles from './diary-detail-add-comment.module.scss';
import useCommentPostMutation from '@/hooks/queries/diary/use-comment-post-mutation';

interface DiaryDetailAddCommentProps {
replyOwner: { author: string; replyId: number } | null;
onReplyReset: () => void;
diaryId: number;
}

export default function DiaryDetailAddComment(props: DiaryDetailAddCommentProps) {
const diaryId = +useRouterId('diaryId');
const { ref, value, isDisbaled, handleValueChange, handleResizeHeight, handleResetValue } = useTextarea();
const commentMutation = useCommentPostMutation(String(diaryId));
const commentMutation = useCommentPostMutation(String(props.diaryId));

const handleSubmit: FormEventHandler<HTMLFormElement> = (event) => {
event.preventDefault();
Expand Down
10 changes: 4 additions & 6 deletions components/diaries/detail/diary-detail-post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@ import useReplyOwner from '@/hooks/detail/use-reply-owner';
import DirayItemInfo from '@/components/diaries/detail/diary-item-info';
import StoryItemSwiper from '@/components/story/item/story-item-swiper';

import useRouterId from '@/hooks/utils/use-router-id';
import { useDiaryQuery } from '@/hooks/queries/diary/use-diary-query';
import DiaryItemHeader from './diary-item-header';
import DirayDetailComments from '@/components/diaries/detail/comments/diary-detail-comments';
import DiaryDetailAddComment from './add-comment/diary-detail-add-comment';

interface StoryDetailPostProps {
id: string;
diaryId: number;
}

export default function DiaryDetailPost(props: StoryDetailPostProps) {
const diaryId = +useRouterId(props.id);
const detailQuery = useDiaryQuery(String(diaryId));
const detailQuery = useDiaryQuery(String(props.diaryId));
const { replyOwner, handleReplyClick, handleReplyReset } = useReplyOwner();

const isImage = detailQuery.data!.contentImages.length !== 0;
Expand All @@ -24,9 +22,9 @@ export default function DiaryDetailPost(props: StoryDetailPostProps) {
<>
<DiaryItemHeader {...detailQuery.data!} />
{isImage && <StoryItemSwiper images={detailQuery.data!.contentImages} />}
<DirayItemInfo {...detailQuery.data!} diaryId={diaryId} />
<DirayItemInfo {...detailQuery.data!} diaryId={props.diaryId} />
<DirayDetailComments comments={detailQuery.data!.comments} onReplyClick={handleReplyClick} />
<DiaryDetailAddComment replyOwner={replyOwner} onReplyReset={handleReplyReset} />
<DiaryDetailAddComment replyOwner={replyOwner} onReplyReset={handleReplyReset} diaryId={props.diaryId} />
</>
);
}
120 changes: 60 additions & 60 deletions components/diaries/diary-content/comment/diary-comment-reply.tsx
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
import DropdownMenu from '@/components/kebab/kebab';
import styles from './diary-comment-reply.module.scss';
import useToggle from '@/hooks/use-toggle';
import CalendarTodoProfile from '@/components/calendar-monthly/calendar-todo-profile';
import { Child } from '@/api/diaries';
import useChildCommentMutation from '@/hooks/queries/diary/use-child-comment-mutation';
import { useState } from 'react';
import DiaryCommentEdit from './diary-comment-edit';
import useCommentPutMutation from '@/hooks/queries/diary/use-comment-put-mutation';

interface DiaryCommentReplyProps {
comment: Child;
diaryId: string;
}

export default function DiaryCommentReply({ comment, diaryId }: DiaryCommentReplyProps) {
const [isEditing, setIsEditing] = useState(false);

const { isToggle: isOpen, handleCloseToggle: onCloseToggle, handleOpenToggle: onOpenToggle } = useToggle();

const commentPutMutation = useCommentPutMutation(diaryId, comment.commentId);
const childCommentMutation = useChildCommentMutation(diaryId, comment.commentId);

const handleEdit = () => {
setIsEditing(true);
onCloseToggle();
};

const handleCancel = () => setIsEditing(false);

const handleDelete = () => childCommentMutation.mutate();

return (
<div className={styles.outer} key={comment.commentId}>
<div className={styles.commentProfile}>
<CalendarTodoProfile name={comment.commentAuthor} src={comment.commentAuthorImage} />
{comment.isMyComment && (
<DropdownMenu value={{ isOpen, onCloseToggle, onOpenToggle }}>
<DropdownMenu.Kebab />
<DropdownMenu.Content>
<DropdownMenu.Item onClick={handleEdit}>수정</DropdownMenu.Item>
<DropdownMenu.Item onClick={handleDelete}>삭제</DropdownMenu.Item>
</DropdownMenu.Content>
</DropdownMenu>
)}
</div>

<p className={styles.commentDate}>{comment.date}</p>
{isEditing ? (
<DiaryCommentEdit
defaultValue={comment.comment}
mutationFn={commentPutMutation.mutate}
onCancel={handleCancel}
/>
) : (
<p className={styles.commentContent}>{comment.comment}</p>
)}
</div>
);
}
// import DropdownMenu from '@/components/kebab/kebab';
// import styles from './diary-comment-reply.module.scss';
// import useToggle from '@/hooks/use-toggle';
// import CalendarTodoProfile from '@/components/calendar-monthly/calendar-todo-profile';
// import { Child } from '@/api/diaries';
// import useChildCommentMutation from '@/hooks/queries/diary/use-child-comment-mutation';
// import { useState } from 'react';
// import DiaryCommentEdit from './diary-comment-edit';
// import useCommentPutMutation from '@/hooks/queries/diary/use-comment-put-mutation';

// interface DiaryCommentReplyProps {
// comment: Child;
// diaryId: string;
// }

// export default function DiaryCommentReply({ comment, diaryId }: DiaryCommentReplyProps) {
// const [isEditing, setIsEditing] = useState(false);

// const { isToggle: isOpen, handleCloseToggle: onCloseToggle, handleOpenToggle: onOpenToggle } = useToggle();

// const commentPutMutation = useCommentPutMutation(diaryId, comment.commentId);
// const childCommentMutation = useChildCommentMutation(diaryId, comment.commentId);

// const handleEdit = () => {
// setIsEditing(true);
// onCloseToggle();
// };

// const handleCancel = () => setIsEditing(false);

// const handleDelete = () => childCommentMutation.mutate();

// return (
// <div className={styles.outer} key={comment.commentId}>
// <div className={styles.commentProfile}>
// <CalendarTodoProfile name={comment.commentAuthor} src={comment.commentAuthorImage} />
// {comment.isMyComment && (
// <DropdownMenu value={{ isOpen, onCloseToggle, onOpenToggle }}>
// <DropdownMenu.Kebab />
// <DropdownMenu.Content>
// <DropdownMenu.Item onClick={handleEdit}>수정</DropdownMenu.Item>
// <DropdownMenu.Item onClick={handleDelete}>삭제</DropdownMenu.Item>
// </DropdownMenu.Content>
// </DropdownMenu>
// )}
// </div>

// <p className={styles.commentDate}>{comment.date}</p>
// {isEditing ? (
// <DiaryCommentEdit
// defaultValue={comment.comment}
// mutationFn={commentPutMutation.mutate}
// onCancel={handleCancel}
// />
// ) : (
// <p className={styles.commentContent}>{comment.comment}</p>
// )}
// </div>
// );
// }
154 changes: 77 additions & 77 deletions components/diaries/diary-content/comment/diary-comment.tsx
Original file line number Diff line number Diff line change
@@ -1,84 +1,84 @@
import DropdownMenu from '@/components/kebab/kebab';
import styles from './diary-comment.module.scss';
import useToggle from '@/hooks/use-toggle';
import CalendarTodoProfile from '@/components/calendar-monthly/calendar-todo-profile';
import { Comment } from '@/api/diaries';
import useParentCommentMutation from '@/hooks/queries/diary/use-parent-comment-mutation';
import { useState } from 'react';
import DiaryCommentForm from './diary-comment-form';
import DiaryCommentReply from './diary-comment-reply';
import useCommentPostMutation from '@/hooks/queries/diary/use-comment-post-mutation';
import DiaryCommentEdit from './diary-comment-edit';
import useCommentPutMutation from '@/hooks/queries/diary/use-comment-put-mutation';
// import DropdownMenu from '@/components/kebab/kebab';
// import styles from './diary-comment.module.scss';
// import useToggle from '@/hooks/use-toggle';
// import CalendarTodoProfile from '@/components/calendar-monthly/calendar-todo-profile';
// import { Comment } from '@/api/diaries';
// import useParentCommentMutation from '@/hooks/queries/diary/use-parent-comment-mutation';
// import { useState } from 'react';
// import DiaryCommentForm from './diary-comment-form';
// import DiaryCommentReply from './diary-comment-reply';
// import useCommentPostMutation from '@/hooks/queries/diary/use-comment-post-mutation';
// import DiaryCommentEdit from './diary-comment-edit';
// import useCommentPutMutation from '@/hooks/queries/diary/use-comment-put-mutation';

interface DiaryCommentProps {
comment: Comment;
diaryId: string;
}
// interface DiaryCommentProps {
// comment: Comment;
// diaryId: string;
// }

export default function DiaryComment({ comment, diaryId }: DiaryCommentProps) {
const [isReplying, setIsReplying] = useState(false);
const [isEditing, setIsEditing] = useState(false);
// export default function DiaryComment({ comment, diaryId }: DiaryCommentProps) {
// const [isReplying, setIsReplying] = useState(false);
// const [isEditing, setIsEditing] = useState(false);

const { isToggle: isOpen, handleCloseToggle: onCloseToggle, handleOpenToggle: onOpenToggle } = useToggle();
// const { isToggle: isOpen, handleCloseToggle: onCloseToggle, handleOpenToggle: onOpenToggle } = useToggle();

const commentPostMutation = useCommentPostMutation(diaryId);
const commentPutMutation = useCommentPutMutation(diaryId, comment.commentId);
const parentCommentMutation = useParentCommentMutation(diaryId, comment.commentId);
// const commentPostMutation = useCommentPostMutation(diaryId);
// const commentPutMutation = useCommentPutMutation(diaryId, comment.commentId);
// const parentCommentMutation = useParentCommentMutation(diaryId, comment.commentId);

const handleDelete = () => parentCommentMutation.mutate();
const handleEdit = () => {
setIsEditing(true);
onCloseToggle();
};
const handleCancel = () => setIsEditing(false);
// const handleDelete = () => parentCommentMutation.mutate();
// const handleEdit = () => {
// setIsEditing(true);
// onCloseToggle();
// };
// const handleCancel = () => setIsEditing(false);

const handleClickReply = () => {
setIsReplying(!isReplying);
};
// const handleClickReply = () => {
// setIsReplying(!isReplying);
// };

return (
<div className={styles.outer} key={comment.commentId}>
<div className={styles.commentProfile}>
<CalendarTodoProfile name={comment.commentAuthor} src={comment.commentAuthorImage} />
{comment.isMyComment && (
<DropdownMenu value={{ isOpen, onCloseToggle, onOpenToggle }}>
<DropdownMenu.Kebab />
<div style={{ position: 'relative', right: '2px' }}>
<DropdownMenu.Content>
<DropdownMenu.Item onClick={handleEdit}>수정</DropdownMenu.Item>
<DropdownMenu.Item onClick={handleDelete}>삭제</DropdownMenu.Item>
</DropdownMenu.Content>
</div>
</DropdownMenu>
)}
</div>
<p className={styles.commentDate}>{comment.date}</p>
{isEditing ? (
<DiaryCommentEdit
defaultValue={comment.comment}
mutationFn={commentPutMutation.mutate}
onCancel={handleCancel}
/>
) : (
<p className={styles.commentContent}>{comment.comment}</p>
)}
<button onClick={handleClickReply} className={styles.commentReply}>
답글 {comment.children.length}
</button>
{isReplying && (
<>
{comment.children.map((child) => (
<DiaryCommentReply key={child.commentId} comment={child} diaryId={diaryId} />
))}
<div style={{ width: '100%', marginBottom: '10px' }}></div>
<DiaryCommentForm
mutateFn={commentPostMutation.mutate}
placeholder="답글 입력..."
parentCommentId={comment.commentId}
/>
</>
)}
</div>
);
}
// return (
// <div className={styles.outer} key={comment.commentId}>
// <div className={styles.commentProfile}>
// <CalendarTodoProfile name={comment.commentAuthor} src={comment.commentAuthorImage} />
// {comment.isMyComment && (
// <DropdownMenu value={{ isOpen, onCloseToggle, onOpenToggle }}>
// <DropdownMenu.Kebab />
// <div style={{ position: 'relative', right: '2px' }}>
// <DropdownMenu.Content>
// <DropdownMenu.Item onClick={handleEdit}>수정</DropdownMenu.Item>
// <DropdownMenu.Item onClick={handleDelete}>삭제</DropdownMenu.Item>
// </DropdownMenu.Content>
// </div>
// </DropdownMenu>
// )}
// </div>
// <p className={styles.commentDate}>{comment.date}</p>
// {isEditing ? (
// <DiaryCommentEdit
// defaultValue={comment.comment}
// mutationFn={commentPutMutation.mutate}
// onCancel={handleCancel}
// />
// ) : (
// <p className={styles.commentContent}>{comment.comment}</p>
// )}
// <button onClick={handleClickReply} className={styles.commentReply}>
// 답글 {comment.children.length}개
// </button>
// {isReplying && (
// <>
// {comment.children.map((child) => (
// <DiaryCommentReply key={child.commentId} comment={child} diaryId={diaryId} />
// ))}
// <div style={{ width: '100%', marginBottom: '10px' }}></div>
// <DiaryCommentForm
// mutateFn={commentPostMutation.mutate}
// placeholder="답글 입력..."
// parentCommentId={comment.commentId}
// />
// </>
// )}
// </div>
// );
// }
8 changes: 7 additions & 1 deletion components/diaries/diary-content/kebab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import DropdownMenu from '@/components/kebab/kebab';
import useToggle from '@/hooks/use-toggle';
import { deleteDiary } from '@/api/diaries';
import { useQueryClient } from '@tanstack/react-query';
import { useRouter } from 'next/router';

interface KebabProps {
diaryId: number;
Expand All @@ -12,6 +13,7 @@ interface KebabProps {
const Kebab: React.FC<KebabProps> = ({ diaryId }) => {
const { isToggle: isOpen, handleCloseToggle: onCloseToggle, handleOpenToggle: onOpenToggle } = useToggle();
const queryClient = useQueryClient();
const router = useRouter();

const handleDelete = async () => {
try {
Expand All @@ -24,12 +26,16 @@ const Kebab: React.FC<KebabProps> = ({ diaryId }) => {

const handleClick: MouseEventHandler = (e) => e.stopPropagation();

const updateFn = () => {
router.push(`/diaries/${diaryId}/edit`);
};

return (
<div className={styles.kebab} onClick={handleClick}>
<DropdownMenu value={{ isOpen, onOpenToggle, onCloseToggle }}>
<DropdownMenu.Kebab />
<DropdownMenu.Content>
<DropdownMenu.Item>수정</DropdownMenu.Item>
<DropdownMenu.Item onClick={updateFn}>수정</DropdownMenu.Item>
<DropdownMenu.Item onClick={handleDelete}>삭제</DropdownMenu.Item>
</DropdownMenu.Content>
</DropdownMenu>
Expand Down
Loading

0 comments on commit 65fd593

Please sign in to comment.