Merge pull request #107 from TeamBNBN/fe/noticesListAPI

[Front-End] feat: 공지사항 목록 페이지 API 연결
This commit is contained in:
mauercho 2024-07-24 16:44:48 +09:00 committed by GitHub
commit abe506e0ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 18 deletions

View File

@ -2,12 +2,9 @@ import { useQuery } from '@tanstack/react-query';
import instance from '../../utils/axios/instance';
import { API_URL } from '../../constants';
export function useNotices(lectureId) {
// TODO: API url 업데이트
const response = useQuery({
queryKey: ['noticelist', lectureId],
queryFn: instance.get(`${API_URL}/notice/${lectureId}`),
export function useNotices(lectureId, page = 0) {
return useQuery({
queryKey: ['noticelist', lectureId, page],
queryFn: () => instance.get(`${API_URL}/board?lectureId=${lectureId}&category=announcement&pageNo=${page}`),
});
return response;
}

View File

@ -1,26 +1,23 @@
import { ArticleLink } from '../../components/ArticleLink';
import ArticleBoard from '../../components/ArticleBoard/ArticleBoard';
import { useNotices } from '../../hooks/api/useNotices';
import { useParams } from 'react-router-dom';
export default function NoticeListPage() {
const { data: notices } = {
data: [
{ id: 1, title: '공지사항1', sub: '7-12 오전 11:40:57' },
{ id: 2, title: '공지사하앙2', sub: '7-12 오전 11:40:57' },
{ id: 3, title: '공지사하앙33', sub: '7-15 오전 11:40:57' },
{ id: 4, title: '제목만 있는 경우' },
],
};
const { lectureId } = useParams();
const { data } = useNotices(lectureId);
const notices = data?.data;
return (
<ArticleBoard
title="공지사항"
canCreate={false}
>
{notices.map((notice) => (
{notices?.map((notice) => (
<ArticleLink
key={`${notice.title}${notice.sub}`}
key={`${notice.id}`}
title={notice.title}
sub={notice.sub}
sub={notice.date}
to={`${notice.id}`}
/>
))}