Skip to content

Commit

Permalink
Merge pull request #221 from ssu-student-union/feat/#148_jongse_qa_3
Browse files Browse the repository at this point in the history
Feat/#148 jongse qa 3
  • Loading branch information
jongse7 authored Oct 13, 2024
2 parents c42c619 + aa50ee2 commit fa3dd1c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/pages/main/containers/LostArticleSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const LostArticleSection = () => {
);

return (
<section>
<section className="w-full">
<div className="flex items-center">
<h1 className="text-[2rem] font-bold xs:text-[1.25rem]">분실물 현황</h1>
<ArrowUpRight
Expand Down
14 changes: 6 additions & 8 deletions src/pages/notice/hooks/useNoticeToday.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
import { useEffect, useState } from 'react';
import { useGetBoardPosts } from '@/hooks/useGetBoardPosts';
import { useNoticeCategory } from './useNoticeCategory';
import { Post } from '@/types/apis/get';
import { useRecoilState } from 'recoil';
import { todayPostCountState } from '@/recoil/atoms/atom';
import { useMemo } from 'react';
import { NoticeResponse } from '../types';

export function useTodayPosts(boardCode: string) {
const { category, subCategory } = useNoticeCategory();

export function useTodayPosts(boardCode: string, category: string, subCategory: string) {
const [todayPostCount, setTodayPostCount] = useRecoilState(todayPostCountState(category));
const [page, setPage] = useState<number>(0);
const [stopFetching, setStopFetching] = useState<boolean>(false);

const { data, isLoading, isError } = useGetBoardPosts<any>({
const { data, isLoading, isError } = useGetBoardPosts<NoticeResponse>({
boardCode,
take: 10,
page,
groupCode: category === '중앙' ? '중앙기구' : '단과대학생회',
memberCode: subCategory === '전체' ? '' : subCategory,
});

const posts: Post[] = data?.data?.postListResDto || [];
const posts: Post[] = useMemo(() => data?.data?.postListResDto || [], [data]);

const isPostToday = (dateString: string): boolean => {
const today = new Date();
Expand Down Expand Up @@ -68,7 +66,7 @@ export function useTodayPosts(boardCode: string) {
} else {
setStopFetching(true);
}
}, [posts]);
}, [posts, category, subCategory, setTodayPostCount]);

return {
todayPostCount,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/notice/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function NoticePage() {
category,
subCategory
);
const { todayPostCount, isLoading: isPostsLoading } = useTodayPosts(boardCode);
const { todayPostCount, isLoading: isPostsLoading } = useTodayPosts(boardCode, category, subCategory);

return (
<>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/partnership/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function PartnershipPage() {
}
}, [queryClient, refetch]);

const posts = data?.data.postListResDto || []; // 게시물 리스트
const posts = data?.data.postListResDto || [];
const partnershipCount = useMemo(() => {
if (isLoading) {
return 0;
Expand Down
3 changes: 2 additions & 1 deletion src/template/board/BoardContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import BoardContentLoading from './BoardContentLoading';
import { formatYYYYMMDD } from '@/utils/formatYYYYMMDD';
import { nameToUrl } from './boardData';

interface BoardContentProps {
boardName: string;
Expand Down Expand Up @@ -117,7 +118,7 @@ export function BoardContent({ boardName, data, isLoading }: BoardContentProps)
badgeType={status}
profileName={post.author}
className="cursor-pointer"
onClick={() => navigate(`/${boardName}/${post.postId}`, { state: { postId: post.postId } })}
onClick={() => navigate(`/${nameToUrl.get(boardName)}/${post.postId}`, { state: { postId: post.postId } })}
/>
</div>
);
Expand Down
5 changes: 5 additions & 0 deletions src/template/board/boardData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const nameToUrl: Map<string, string> = new Map([
['공지사항게시판', 'notice'],
['감사기구게시판', 'audit'],
['분실물게시판', 'lost-article'],
]);

0 comments on commit fa3dd1c

Please sign in to comment.