-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #625 from cindycho0423/Next.js-조현지-sprint10
[조현지] sprint10
- Loading branch information
Showing
59 changed files
with
1,438 additions
and
372 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import Image from 'next/image'; | ||
import icHeart from '@/public/images/icons/ic_heart.png'; | ||
import icProfile from '@/public/images/icons/ic_profile.png'; | ||
import icKebab from '@/public/images/icons/ic_kebab.svg'; | ||
import getFormatDate from '@/lib/utils/formatDate'; | ||
import { ArticleProps } from '@/types'; | ||
|
||
export default function ArticleDetail({ content, createdAt, image, likeCount, title, writer }: ArticleProps) { | ||
const createdDate = getFormatDate(createdAt); | ||
|
||
return ( | ||
<> | ||
<div className='flex justify-between mb-4'> | ||
<h1 className=''>{title}</h1> | ||
<Image src={icKebab} width={24} alt='케밥 메뉴' /> | ||
</div> | ||
<div className='mb-10'> | ||
<div className='flex items-center gap-4 mb-4'> | ||
<div className='flex items-center gap-2'> | ||
<Image src={icProfile} width={24} alt='프로필 기본 사진' /> | ||
<span className='text-[14px] text-cool-gray600'>{writer.nickname}</span> | ||
<span className='text-[12px] text-cool-gray400'>{createdDate}</span> | ||
</div> | ||
|
||
<div className='w-[1px] h-[24px] bg-cool-gray200'></div> | ||
|
||
<div className='flex items-center gap-1 text-[14px] text-cool-gray600'> | ||
<Image src={icHeart} width={24} height={24} alt='좋아요 하트' /> | ||
|
||
{likeCount} | ||
</div> | ||
</div> | ||
|
||
<div className='w-[343px] md:w-[696px] lg:w-[1200px] h-[1px] bg-cool-gray200 mb-4'></div> | ||
<div>{content}</div> | ||
</div> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { postComment } from '@/lib/api/postComment'; | ||
import SubmitButton from '@/components/submit-btn'; | ||
import { useState, useEffect, ChangeEvent, FormEvent } from 'react'; | ||
|
||
type Props = { | ||
id: string; | ||
onNewComment: () => void; | ||
}; | ||
|
||
export default function CommentForm({ id, onNewComment }: Props) { | ||
const [comment, setComment] = useState(''); | ||
const [token, setToken] = useState(''); | ||
|
||
useEffect(() => { | ||
const localToken = typeof window !== 'undefined' ? localStorage.getItem('accessToken') : null; | ||
if (localToken) { | ||
setToken(localToken); | ||
} | ||
}, []); | ||
|
||
const handleChange = (e: ChangeEvent<HTMLTextAreaElement>) => { | ||
setComment(e.target.value); | ||
}; | ||
|
||
const handleSubmit = async (e: FormEvent) => { | ||
e.preventDefault(); | ||
|
||
try { | ||
const response = await postComment(comment, id, token); | ||
if (response) { | ||
setComment(''); | ||
onNewComment(); | ||
} else { | ||
console.error('댓글 작성 실패'); | ||
} | ||
} catch (error) { | ||
console.error('댓글 작성 중 오류 발생:', error); | ||
} | ||
}; | ||
|
||
return ( | ||
<form onSubmit={handleSubmit}> | ||
<label className='font-semibold' htmlFor='comment'> | ||
댓글달기 | ||
</label> | ||
<textarea | ||
id='comment' | ||
value={comment} | ||
onChange={handleChange} | ||
className='w-[343px] md:w-[696px] lg:w-[1200px] min-w-[344px] h-[104px] rounded-2xl py-4 px-6 my-4' | ||
placeholder='댓글을 입력해주세요' | ||
/> | ||
<div className='flex justify-end'> | ||
<SubmitButton checkValue={comment.length > 0 ? true : false}>등록</SubmitButton> | ||
</div> | ||
</form> | ||
); | ||
} |
Oops, something went wrong.