Skip to content

Commit

Permalink
Merge pull request #282 from ssu-student-union/fix/#280_post_patch
Browse files Browse the repository at this point in the history
Fix/#280 post patch
  • Loading branch information
jongse7 authored Oct 24, 2024
2 parents f6d5f0f + b9733e2 commit 63dcfdc
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 15 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
1 change: 0 additions & 1 deletion src/apis/getBoardPostSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const getBoardPostSearch = async ({
q: q,
},
});
console.log(response);

return response.data;
};
5 changes: 4 additions & 1 deletion src/hooks/usePatchBoardPosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { useMutation, useQueryClient } from '@tanstack/react-query';
export const usePatchBoardPosts = () => {
const queryClient = useQueryClient();
return useMutation<patchBoardPostsResponse, Error, patchBoardPostProps>({
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'] });
Expand Down
18 changes: 6 additions & 12 deletions src/pages/notice/hooks/useNoticeToday.ts
Original file line number Diff line number Diff line change
@@ -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<number>(0);
const [page, setPage] = useState<number>(0);
const [stopFetching, setStopFetching] = useState<boolean>(false);

const { data, isLoading, isError } = useGetBoardPosts<any>({
const { data, isLoading, isError } = useGetBoardPostSearch<any>({
boardCode,
take: 10,
page,
Expand All @@ -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();
Expand All @@ -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;
}
}
Expand All @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/pages/notice/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export function NoticePage() {
);
const { todayPostCount, isLoading: isPostsLoading } = useTodayPosts(boardCode, category, subCategory);

console.log(todayPostCount);
console.log(category, subCategory);

return (
<>
<HeadLayout
Expand Down
2 changes: 1 addition & 1 deletion src/types/patchBoardPosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface patchBoardPostProps {
title: string;
content: string;
categoryCode?: string;
isNotice?: boolean;
isNotice?: boolean | null;
thumbnailImage: string | null;
postFileList: number[];
};
Expand Down

0 comments on commit 63dcfdc

Please sign in to comment.