diff --git a/api/diaries/index.ts b/api/diaries/index.ts index 4a82dc7e..14128103 100644 --- a/api/diaries/index.ts +++ b/api/diaries/index.ts @@ -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[]; diff --git a/components/calendar-monthly/pet-checkbox.tsx b/components/calendar-monthly/pet-checkbox.tsx index b27da1ec..1127ba11 100644 --- a/components/calendar-monthly/pet-checkbox.tsx +++ b/components/calendar-monthly/pet-checkbox.tsx @@ -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: diff --git a/components/diaries/detail/add-comment/diary-detail-add-comment.tsx b/components/diaries/detail/add-comment/diary-detail-add-comment.tsx index b6684d56..9526d8ec 100644 --- a/components/diaries/detail/add-comment/diary-detail-add-comment.tsx +++ b/components/diaries/detail/add-comment/diary-detail-add-comment.tsx @@ -1,5 +1,4 @@ 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'; @@ -7,12 +6,12 @@ import useCommentPostMutation from '@/hooks/queries/diary/use-comment-post-mutat 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 = (event) => { event.preventDefault(); diff --git a/components/diaries/detail/diary-detail-post.tsx b/components/diaries/detail/diary-detail-post.tsx index b25cb64b..0fa76663 100644 --- a/components/diaries/detail/diary-detail-post.tsx +++ b/components/diaries/detail/diary-detail-post.tsx @@ -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; @@ -24,9 +22,9 @@ export default function DiaryDetailPost(props: StoryDetailPostProps) { <> {isImage && } - + - + ); } diff --git a/components/diaries/diary-content/comment/diary-comment-reply.tsx b/components/diaries/diary-content/comment/diary-comment-reply.tsx index 9b528f15..bb035b61 100644 --- a/components/diaries/diary-content/comment/diary-comment-reply.tsx +++ b/components/diaries/diary-content/comment/diary-comment-reply.tsx @@ -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 ( -
-
- - {comment.isMyComment && ( - - - - 수정 - 삭제 - - - )} -
- -

{comment.date}

- {isEditing ? ( - - ) : ( -

{comment.comment}

- )} -
- ); -} +// 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 ( +//
+//
+// +// {comment.isMyComment && ( +// +// +// +// 수정 +// 삭제 +// +// +// )} +//
+ +//

{comment.date}

+// {isEditing ? ( +// +// ) : ( +//

{comment.comment}

+// )} +//
+// ); +// } diff --git a/components/diaries/diary-content/comment/diary-comment.tsx b/components/diaries/diary-content/comment/diary-comment.tsx index 0055375b..5cefa66d 100644 --- a/components/diaries/diary-content/comment/diary-comment.tsx +++ b/components/diaries/diary-content/comment/diary-comment.tsx @@ -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 ( -
-
- - {comment.isMyComment && ( - - -
- - 수정 - 삭제 - -
-
- )} -
-

{comment.date}

- {isEditing ? ( - - ) : ( -

{comment.comment}

- )} - - {isReplying && ( - <> - {comment.children.map((child) => ( - - ))} -
- - - )} -
- ); -} +// return ( +//
+//
+// +// {comment.isMyComment && ( +// +// +//
+// +// 수정 +// 삭제 +// +//
+//
+// )} +//
+//

{comment.date}

+// {isEditing ? ( +// +// ) : ( +//

{comment.comment}

+// )} +// +// {isReplying && ( +// <> +// {comment.children.map((child) => ( +// +// ))} +//
+// +// +// )} +//
+// ); +// } diff --git a/components/diaries/diary-content/kebab/index.tsx b/components/diaries/diary-content/kebab/index.tsx index 3b938e59..aa0d1b2d 100644 --- a/components/diaries/diary-content/kebab/index.tsx +++ b/components/diaries/diary-content/kebab/index.tsx @@ -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; @@ -12,6 +13,7 @@ interface KebabProps { const Kebab: React.FC = ({ diaryId }) => { const { isToggle: isOpen, handleCloseToggle: onCloseToggle, handleOpenToggle: onOpenToggle } = useToggle(); const queryClient = useQueryClient(); + const router = useRouter(); const handleDelete = async () => { try { @@ -24,12 +26,16 @@ const Kebab: React.FC = ({ diaryId }) => { const handleClick: MouseEventHandler = (e) => e.stopPropagation(); + const updateFn = () => { + router.push(`/diaries/${diaryId}/edit`); + }; + return (
- 수정 + 수정 삭제 diff --git a/components/diaries/diary-create/diary-create.module.scss b/components/diaries/diary-create/diary-create.module.scss deleted file mode 100644 index c4b37018..00000000 --- a/components/diaries/diary-create/diary-create.module.scss +++ /dev/null @@ -1,215 +0,0 @@ -.container { - padding: 54px 0 100px; -} - -.petSelect { - padding: 0 24px; - margin-top: 30px; -} - -.pets { - display: flex; - gap: 15px; -} - -.content { - font-size: 14px; - display: block; - width: 100%; - height: 160px; - padding: 0 24px; - margin-top: 22px; - margin-bottom: 30px; - border: none; - resize: none; - &::placeholder { - font-weight: 500; - line-height: 21px; - color: var(--text-color-gray); - } - &:focus { - outline: none; - } -} - -.division { - margin: 0px auto 30px; - width: 382px; - border: 1px solid #d5d9dc; -} - -.weatherContainer { - padding: 0 24px; - margin-bottom: 30px; -} - -.weather { - display: flex; - align-items: center; - gap: 5px; - margin-bottom: 12px; - font-size: 14px; - color: var(--text-color-gray); -} -.weatherIcons { - display: flex; - justify-content: space-between; - - button { - height: 40px; - background: none; - border: none; - cursor: pointer; - - img { - width: 40px; - height: 40px; - } - } -} - -.imagesContainer { - display: flex; - gap: 10px; - padding: 0 24px; - margin-bottom: 30px; - overflow-x: scroll; - -ms-overflow-style: none; - scrollbar-width: none; -} - -.imagesContainer::-webkit-scrollbar { - display: none; -} - -.images { - width: 110px; - height: 110px; - object-fit: cover; - border-radius: 10px; - cursor: pointer; -} - -.button { - padding: 0 24px; -} - -.storyshareContainer { - display: flex; - align-items: center; - justify-content: space-between; - height: 22px; - padding: 0 24px; - margin-bottom: 30px; -} - -.storyshare { - display: flex; - align-items: center; - gap: 5px; - font-size: 14px; - color: var(--text-color-gray); -} - -.toggle { - position: relative; - display: inline-block; - width: 37.69px; - height: 20px; -} - -.toggle input { - opacity: 0; - width: 0; - height: 0; -} - -.toggleSlide { - position: absolute; - cursor: pointer; - top: 0; - left: 0; - right: 0; - bottom: 0; - background-color: var(--disabled-color); - transition: 0.4s; - border-radius: 27px; -} - -.toggleSlide:before { - position: absolute; - content: ''; - height: 16.92px; - width: 16.92px; - left: 2px; - bottom: 1.54px; - background-color: white; - transition: 0.4s; - border-radius: 50%; -} - -input:checked + .toggleSlide { - background-color: var(--main-color); -} - -input:checked + .toggleSlide:before { - transform: translateX(16.92px); -} - -.dateContainer { - display: flex; - align-items: center; - justify-content: space-between; - padding: 0 24px; - margin-bottom: 30px; -} - -.date { - display: flex; - align-items: center; - justify-content: center; - width: 43px; - height: 28px; - border-radius: 4px; - font-size: 14px; - color: var(--white); - background-color: var(--main-color); -} - -.dateInput { - border: none; - width: 96px; - font-size: 14px; - font-weight: bold; - color: var(--text-color-gray); - - &::placeholder { - font-size: 14px; - font-weight: bold; - color: var(--text-color-gray); - } - &:focus { - outline: none; - } -} - -.submit { - width: 100%; - padding: 14px; - color: var(--button-color); - background-color: var(--main-color); - border-radius: 9999px; -} - -.disabled { - background-color: var(--disabled-color); - color: var(--white); -} - -.error { - padding: 0 24px; - margin-top: 8px; - margin-bottom: 30px; - font-weight: 400; - color: var(--input-error); -} diff --git a/components/diaries/diary-create/diary-create.tsx b/components/diaries/diary-create/diary-create.tsx deleted file mode 100644 index 1233ab59..00000000 --- a/components/diaries/diary-create/diary-create.tsx +++ /dev/null @@ -1,254 +0,0 @@ -import React, { useRef, useState, useEffect } from 'react'; -import { useForm, SubmitHandler, FieldValues } from 'react-hook-form'; -import classNames from 'classnames'; -import { WEATHER_TYPES } from '@/lib/constants/diaries-constants'; -import { postDiariesImage, postDiaries } from '@/api/diaries/'; -import styles from './diary-create.module.scss'; -import useCalenderDateStore from '@/store/calendar.store'; -import { convertToLocalDate } from '@/utils/convert-local-date'; -import usePetsQuery from '@/hooks/queries/calendar/use-pets-query'; -import { useQueryClient } from '@tanstack/react-query'; -import PetSelect from '@/components/diaries/pet-select'; -import PetCheckbox from '@/components/diaries/pet-checkbox'; -import ImageSkeleton from '@/components/skeleton/image/'; -import { useRouter } from 'next/router'; -import WeatherItem from '../jihye/diary-edit-weather'; - -export interface DiaryData { - content: string; - weather: string; - isShare: boolean; - date: string; - pets: number[]; - images: number[]; -} - -const DiaryCreate: React.FC = () => { - const { - register, - handleSubmit, - watch, - setValue, - formState: { errors, isValid }, - resetField, - } = useForm({ - defaultValues: { - content: '', - weather: '', - isShare: false, - date: '', - pets: [], - images: [], - }, - }); - - const queryClient = useQueryClient(); - const router = useRouter(); - - const year = useCalenderDateStore.use.year().toString(); - const month = (useCalenderDateStore.use.month() + 1).toString().padStart(2, '0'); - const date = useCalenderDateStore.use.date().toString().padStart(2, '0'); - const localDate = convertToLocalDate({ year, month, day: date }); - - useEffect(() => { - setValue('date', localDate); - }, [localDate, setValue]); - - const selectedWeather = watch('weather'); - const [imagePreviews, setImagePreviews] = useState([]); - const [imageIds, setImageIds] = useState([]); - const fileInputRefs = useRef([]); - - const watchDate = watch('date'); - useEffect(() => { - if (watchDate) { - const [year, month, day] = watchDate.split('-'); - const convertedDate = convertToLocalDate({ year, month, day }); - setValue('date', convertedDate); - } - }, [watchDate, setValue]); - - const handleImageChange = (index: number) => async (event: React.ChangeEvent) => { - const files = event.target.files; - if (files && files.length > 0) { - const fileArray = Array.from(files); - - try { - const response = await postDiariesImage({ images: fileArray }); - const newImageIds = [...imageIds]; - newImageIds[index] = response.data[0]; - setImageIds(newImageIds); - - const fileReader = new FileReader(); - fileReader.onload = () => { - const newImagePreviews = [...imagePreviews]; - newImagePreviews[index] = fileReader.result as string; - setImagePreviews(newImagePreviews); - }; - fileReader.readAsDataURL(files[0]); - } catch (error) { - console.error('failed to upload image:', error); - } - } - }; - - const onSubmit: SubmitHandler = async (data) => { - console.log(data); - const completeData = { ...data, images: imageIds }; - try { - const response = await postDiaries(completeData); - console.log('Diary posted successfully:', response); - queryClient.invalidateQueries({ queryKey: ['diaries'] }); - router.push('/diaries'); - } catch (error) { - console.error('failed to post diary:', error); - } - }; - - const { data: pets, isLoading, isError, error } = usePetsQuery(); - const [selectedPets, setSelectedPets] = useState([]); - - if (isError) return

Error: {error.message}

; - - const handleTogglePet = (petId: number) => { - setSelectedPets((prevSelectedPets) => - prevSelectedPets.includes(petId) ? prevSelectedPets.filter((id) => id !== petId) : [...prevSelectedPets, petId], - ); - }; - - const handleClickAll = () => { - if (selectedPets.length === pets.length) { - setSelectedPets([]); - resetField('pets'); - } else { - const allPetIds = pets.map((pet) => pet.petId); - setSelectedPets(allPetIds); - setValue('pets', allPetIds); - } - }; - - return ( -
-
-
- -
- {isLoading ? ( - - ) : ( - pets.map((pet) => ( - - )) - )} -
-
-
- -