From 79f9c722802e3dd95b19c822280ee0acb354b34d Mon Sep 17 00:00:00 2001 From: ssu-it-support Date: Thu, 10 Oct 2024 04:31:24 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=A0=9C=ED=9C=B4=20=EA=B2=8C=EC=8B=9C?= =?UTF-8?q?=ED=8C=90=20=EC=A0=9C=EC=99=B8=20=EC=A0=84=20=EA=B2=8C=EC=8B=9C?= =?UTF-8?q?=ED=8C=90=EC=97=90=20BoardContent=20=EB=A0=88=EC=9D=B4=EC=95=84?= =?UTF-8?q?=EC=9B=83=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/template/board/BoardContent.tsx | 125 +++++++++++++++++++++ src/template/board/BoardContentLoading.tsx | 44 ++++++++ 2 files changed, 169 insertions(+) create mode 100644 src/template/board/BoardContent.tsx create mode 100644 src/template/board/BoardContentLoading.tsx diff --git a/src/template/board/BoardContent.tsx b/src/template/board/BoardContent.tsx new file mode 100644 index 00000000..5dbd5d91 --- /dev/null +++ b/src/template/board/BoardContent.tsx @@ -0,0 +1,125 @@ +import { Size } from '@/components/PostCard/const/state'; +import { PostCardBasic } from '@/components/PostCard/PostCardBasicMissing'; +import { useResponseBoard } from '@/hooks/useResponseBoard'; +import { useEffect, useState } from 'react'; +import { useNavigate } from 'react-router-dom'; +import BoardContentLoading from './BoardContentLoading'; +import { formatYYYYMMDD } from '@/utils/formatYYYYMMDD'; + +interface BoardContentProps { + boardName: string; + data?: any[]; + className?: string; + isLoading: boolean; +} + +export function BoardContent({ boardName, data, isLoading }: BoardContentProps) { + const navigate = useNavigate(); + const { size } = useResponseBoard(); + const screenWidth: number = window.innerWidth; + const [posts, setPosts] = useState(data); + + useEffect(() => { + setPosts(data); + }, [data]); + + if (isLoading) { + return ; + } else { + if (!posts || posts.length === 0) { + return ( +
등록된 게시물이 없습니다
+ ); + } + if (screenWidth >= 1920) { + return ( +
+
+ {posts.slice(0, 3).map((post) => ( + + ))} +
+
+ {posts.slice(3, 6).map((post) => ( + + ))} +
+
+ {posts.slice(6, 9).map((post) => ( + + ))} +
+
+ ); + } else if (screenWidth >= 1440 && screenWidth < 1920) { + return ( +
+
+ {posts.slice(0, 2).map((post) => ( + + ))} +
+
+ {posts.slice(2, 4).map((post) => ( + + ))} +
+
+ {posts.slice(4, 6).map((post) => ( + + ))} +
+
+ ); + } else { + return ( +
+ {posts.map((post) => ( + + ))} +
+ ); + } + } + + interface RenderCardProps { + post: any; + size: Size; + boardName: string; + } + + function RenderCard({ post, size, boardName }: RenderCardProps) { + const formattedDate = post.date ? formatYYYYMMDD(post.date) : ''; + let thumbnail = post.thumbNail || undefined; + + let status: 'Emergency' | 'New' | 'Default'; + if (post.status === '긴급공지') { + status = 'Emergency'; + } else if (post.status === '새로운') { + status = 'New'; + } else { + status = 'Default'; + } + if (status === 'Emergency' && thumbnail === undefined) { + thumbnail = `image/default/thumbnail/thumbnail_299px.png`; + } + return ( +
+ navigate(`/${boardName}/${post.postId}`, { state: { postId: post.postId } })} + /> +
+ ); + } +} diff --git a/src/template/board/BoardContentLoading.tsx b/src/template/board/BoardContentLoading.tsx new file mode 100644 index 00000000..af96749d --- /dev/null +++ b/src/template/board/BoardContentLoading.tsx @@ -0,0 +1,44 @@ +import { Skeleton } from '@/components/ui/skeleton'; + +interface BoardContentLoadingProps { + screenWidth: number; +} + +export default function BoardContentLoading({ screenWidth }: BoardContentLoadingProps) { + const emptyFive = Array(5).fill(null); + const emptyThree = Array(3).fill(null); + const emptyTwo = Array(2).fill(null); + if (screenWidth >= 1920) { + return ( +
+ {emptyThree.map((_, index) => ( +
+ {emptyThree.map((_, i) => ( + + ))} +
+ ))} +
+ ); + } else if (screenWidth >= 1440 && screenWidth < 1920) { + return ( +
+ {emptyThree.map((_, index) => ( +
+ {emptyTwo.map((_, i) => ( + + ))} +
+ ))} +
+ ); + } else { + return ( +
+ {emptyFive.map((_, index) => ( + + ))} +
+ ); + } +}