diff --git a/.yarn/install-state.gz b/.yarn/install-state.gz index 850b3cba..46a17974 100644 Binary files a/.yarn/install-state.gz and b/.yarn/install-state.gz differ diff --git a/src/apis/getBoardPostSearch.ts b/src/apis/getBoardPostSearch.ts index 3d42a7cf..623b472c 100644 --- a/src/apis/getBoardPostSearch.ts +++ b/src/apis/getBoardPostSearch.ts @@ -24,7 +24,6 @@ export const getBoardPostSearch = async ({ q: q, }, }); - console.log(response); return response.data; }; diff --git a/src/hooks/usePatchBoardPosts.ts b/src/hooks/usePatchBoardPosts.ts index b2925870..c1bd1b38 100644 --- a/src/hooks/usePatchBoardPosts.ts +++ b/src/hooks/usePatchBoardPosts.ts @@ -5,7 +5,10 @@ import { useMutation, useQueryClient } from '@tanstack/react-query'; export const usePatchBoardPosts = () => { const queryClient = useQueryClient(); return useMutation({ - mutationFn: (patchData: patchBoardPostProps) => patchBoardPosts(patchData), + mutationFn: (patchData: patchBoardPostProps) => { + patchData.posts.isNotice = patchData.posts.isNotice ?? false; + return patchBoardPosts(patchData); + }, onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['getPetitionTopLiked'] }); queryClient.invalidateQueries({ queryKey: ['get-board-boardCode-posts'] }); diff --git a/src/pages/notice/hooks/useNoticeToday.ts b/src/pages/notice/hooks/useNoticeToday.ts index d04ba4d0..76a70221 100644 --- a/src/pages/notice/hooks/useNoticeToday.ts +++ b/src/pages/notice/hooks/useNoticeToday.ts @@ -1,15 +1,13 @@ import { useEffect, useState } from 'react'; -import { useGetBoardPosts } from '@/hooks/useGetBoardPosts'; import { Post } from '@/types/apis/get'; -import { useRecoilState } from 'recoil'; -import { todayPostCountState } from '@/recoil/atoms/atom'; +import { useGetBoardPostSearch } from '@/hooks/useGetBoardPostSearch'; export function useTodayPosts(boardCode: string, category: string, subCategory: string) { - const [todayPostCount, setTodayPostCount] = useRecoilState(todayPostCountState(category)); + const [todayPostCount, setTodayPostCount] = useState(0); const [page, setPage] = useState(0); const [stopFetching, setStopFetching] = useState(false); - const { data, isLoading, isError } = useGetBoardPosts({ + const { data, isLoading, isError } = useGetBoardPostSearch({ boardCode, take: 10, page, @@ -18,6 +16,7 @@ export function useTodayPosts(boardCode: string, category: string, subCategory: }); const posts: Post[] = data?.data?.postListResDto || []; + console.log(posts); const isPostToday = (dateString: string): boolean => { const today = new Date(); @@ -40,19 +39,14 @@ export function useTodayPosts(boardCode: string, category: string, subCategory: }; useEffect(() => { - setTodayPostCount(0); - if (posts.length > 0) { let count = 0; - let stopLoading = false; - // 긴급 공지 먼저 처리 + // 긴급 공지 처리 for (const post of posts) { if (post.status === '긴급공지' && isPostToday(post.date)) { count++; } else if (post.status === '긴급공지' && !isPostToday(post.date)) { - // 오늘 날짜가 아닌 긴급 공지가 있으면 중단 - stopLoading = true; break; } } @@ -66,7 +60,7 @@ export function useTodayPosts(boardCode: string, category: string, subCategory: setTodayPostCount(count); - if (stopLoading || posts.length < 10) { + if (posts.length < 10) { setStopFetching(true); } else { setPage((prevPage) => prevPage + 1); diff --git a/src/pages/notice/page.tsx b/src/pages/notice/page.tsx index ca28310b..ca743903 100644 --- a/src/pages/notice/page.tsx +++ b/src/pages/notice/page.tsx @@ -21,6 +21,9 @@ export function NoticePage() { ); const { todayPostCount, isLoading: isPostsLoading } = useTodayPosts(boardCode, category, subCategory); + console.log(todayPostCount); + console.log(category, subCategory); + return ( <>