-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notice 페이지 API 연동 및 컴포넌트 교체 #284
Changes from 4 commits
563eeb4
4f9d06a
af6cec8
613eb86
ab93be1
50bd316
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import axiosInstance from '@/lib/axios/axiosInstance'; | ||
import { NoticeListItemType } from '@/lib/types/noticeType'; | ||
|
||
const getNotices = async () => { | ||
const result = await axiosInstance.get<NoticeListItemType[]>('/admin/notices'); | ||
|
||
return result.data; | ||
}; | ||
|
||
export default getNotices; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 나현님, 해당 API 엔드포인트는 어드민 공지 조회로 보이는데 API가 잘못 연결된게 맞을까요? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,26 @@ | ||
'use client'; | ||
|
||
import Image from 'next/image'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { QUERY_KEYS } from '@/lib/constants/queryKeys'; | ||
import getNotices from '../_api/notice/getNotices'; | ||
|
||
import { NoticeListItemType } from '@/lib/types/noticeType'; | ||
import { NOTICE_LIST_MOCKDATA } from './mockdata'; | ||
|
||
import * as styles from './NoticeList.css'; | ||
import Link from 'next/link'; | ||
|
||
function NoticeList() { | ||
const { data: notices } = useQuery<NoticeListItemType[]>({ | ||
queryKey: [QUERY_KEYS.getAllNotices], | ||
queryFn: getNotices, | ||
staleTime: 1000 * 60 * 30, | ||
}); | ||
Comment on lines
+14
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 한가지 궁금한점이 NoticeListItemType 타입은 itemImageUrl 필드를 가지고 있는데, 해당 필드는 게시물을 생성할 때 콘텐츠블록에 이미지 블록을 의미하는 것이 맞을까요? 아니면 대표 이미지가 있는 것인지 해당 이미지가 UI상 노출되는 부분을 확인할 수 없어서 여쭤봅니다~! |
||
|
||
return ( | ||
<ul className={styles.noticeListWrapper}> | ||
{NOTICE_LIST_MOCKDATA?.map((item: NoticeListItemType) => ( | ||
<li key={item.id}> | ||
{notices?.map((item: NoticeListItemType, index) => ( | ||
<li key={index}> | ||
<NoticeListItem item={item} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. key를 index로 하신 이유가 있을까요?! 👀 사용자만큼은 아니지만 게시물도 생성 및 수정이 빈번하게 될 수 있기 때문에 id를 key값으로 지정하는 것이 더 안전해보입니다! |
||
</li> | ||
))} | ||
|
@@ -26,7 +36,7 @@ interface NoticeListItemProps { | |
|
||
function NoticeListItem({ item }: NoticeListItemProps) { | ||
return ( | ||
<Link href={`/notices/${item.id}`} className={styles.listItemWrapper}> | ||
<Link href={`/notice/${item.id}`} className={styles.listItemWrapper}> | ||
<div> | ||
<h3 className={styles.noticeTitle}>{item.title}</h3> | ||
<p className={styles.noticeDescription}>{item.description}</p> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
'use client'; | ||
|
||
import Link from 'next/link'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { usePathname } from 'next/navigation'; | ||
import { useRouter } from 'next/navigation'; | ||
|
||
import getNoticeDetail from '@/app/_api/notice/getNoticeDetail'; | ||
import { QUERY_KEYS } from '@/lib/constants/queryKeys'; | ||
import { NoticeDetailType } from '@/lib/types/noticeType'; | ||
|
||
import * as styles from './NoticeDetail.css'; | ||
import NoticeDetailInfo from '@/components/NoticeDetail/NoticeDetailInfo'; | ||
|
||
function NoticeDetailComponent() { | ||
const pathname = usePathname(); | ||
const noticeId = pathname?.split('/').pop(); | ||
const noticeIdNumber = noticeId ? Number(noticeId) : null; | ||
const router = useRouter(); | ||
|
||
const { | ||
data: notice, | ||
isLoading, | ||
isError, | ||
} = useQuery<NoticeDetailType>({ | ||
queryKey: [QUERY_KEYS.getNoticeDetail, noticeIdNumber], | ||
queryFn: () => getNoticeDetail(noticeIdNumber as number), | ||
enabled: noticeIdNumber !== null, // noticeIdNumber가 유효한 경우에만 실행 | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 나현님, Next.js의 Dynamic Routes의 경우에는 라우트(경로) 파라미터(slug)를
|
||
|
||
if (!notice) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<> | ||
<div className={styles.header}> | ||
<span className={styles.back} onClick={() => router.back()}> | ||
뒤로가기 | ||
</span> | ||
</div> | ||
<NoticeDetailInfo noticeData={notice} /> | ||
<section className={styles.signPostWrapper}> | ||
{notice?.prevNotice && ( | ||
<Link href={`/notice/${notice?.prevNotice.id}`}> | ||
<div className={styles.listItemWrapper}> | ||
<div className={styles.sign}>이전글</div> | ||
<div className={styles.noticeTitle}>{notice?.prevNotice?.title}</div> | ||
<p className={styles.noticeDescription}>{notice?.prevNotice?.description}</p> | ||
</div> | ||
</Link> | ||
)} | ||
{notice?.nextNotice && ( | ||
<Link href={`/notice/${notice?.nextNotice.id}`}> | ||
<div className={styles.listItemWrapper}> | ||
<div className={styles.sign}>다음글</div> | ||
<div className={styles.noticeTitle}>{notice?.nextNotice?.title}</div> | ||
<p className={styles.noticeDescription}>{notice?.nextNotice?.description}</p> | ||
</div> | ||
</Link> | ||
)} | ||
<Link href={'/notice'}> | ||
<button className={styles.link}>목록보기</button> | ||
</Link> | ||
</section> | ||
</> | ||
); | ||
} | ||
|
||
export default NoticeDetailComponent; |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📌 사용하지 않는 목업데이터는 삭제하면 좋을 것 같아요~! |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📌 |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ export const created = style({ | |
}); | ||
|
||
export const contents = style({ | ||
paddingTop: '2rem', | ||
padding: '2rem 1.6rem 0 1.6rem', | ||
|
||
Comment on lines
50
to
52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (의견) 나현님, 이 부분은 contents 자체에 패딩을 주기 보다는 NoticeDetailInfo 컴포넌트를 사용하는 곳에 div태그로 감싸고 여기에 패딩을 주면 어떨까요?! |
||
display: 'flex', | ||
flexDirection: 'column', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📌 public 안에있는 변경사항 파일은 PR에 포함되는 파일일까요?!