Skip to content

Commit dd0f330

Browse files
authored
Merge pull request #237 from codeitFE11-part3-team7/feature/#218_모든-로딩-상태-로딩-컴포넌트-사용
Feature/#218 모든 로딩 상태 로딩 컴포넌트 사용
2 parents 5b39492 + 5a877c4 commit dd0f330

File tree

3 files changed

+46
-22
lines changed

3 files changed

+46
-22
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default function CommentEmpty() {
2+
return (
3+
<div className="flex h-[192px] w-full flex-col items-center justify-center gap-[20px] rounded-custom text-gray-400 mo:h-[184px] mo:gap-[16px]">
4+
<div className="text-center text-16 mo:text-14">
5+
<p>아직 작성된 댓글이 없네요.</p>
6+
<p>댓글을 남겨주세요!</p>
7+
</div>
8+
</div>
9+
);
10+
}

pages/boards/[articleId].tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
import { CommentsData, CommentType } from 'types/board';
2929
import SnackBar, { SnackBarProps } from '@/components/SnackBar';
3030
import ModalDefault from '@/components/Modal/ModalDefault';
31+
import CommentEmpty from '@/components/boards.page/CommentEmpty';
3132

3233
export default function BoardsDetails() {
3334
const [boardData, setBoardData] = useState<ArticleData | null>(null);
@@ -272,7 +273,7 @@ export default function BoardsDetails() {
272273
))}
273274
</ul>
274275
) : (
275-
<div className="text-gray-500">작성된 댓글이 없습니다.</div>
276+
<CommentEmpty />
276277
)}
277278

278279
{/* 무한 스크롤 로더 */}

pages/boards/index.tsx

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { useProfileContext } from '@/hooks/useProfileContext';
1818
import SnackBar, { SnackBarProps } from '@/components/SnackBar';
1919
import Router from 'next/router';
2020
import EmptyList from '@/components/EmptyList';
21+
import Spinner from '@/components/Spinner';
2122

2223
const BoardCardList_Swiper = dynamic(
2324
() => import('@/components/boards.page/BoardCardList.swiper'),
@@ -81,6 +82,7 @@ export default function Boards({
8182
const [snackStyled, setSnackStyled] =
8283
useState<SnackBarProps['severity']>(undefined);
8384

85+
const [isLoading, setIsLoading] = useState(false);
8486
const isMobile = useCheckMobile();
8587
const PAGE_SIZE = 10;
8688

@@ -90,16 +92,19 @@ export default function Boards({
9092
useEffect(() => {
9193
const fetchBoards = async () => {
9294
const orderBy = selectedOption === '최신순' ? 'recent' : 'like';
93-
const res = await getBoards({
94-
orderBy,
95-
pageSize: PAGE_SIZE,
96-
page: currentPage,
97-
keyword: searchValue,
98-
});
99-
if (Array.isArray(res.list) && res.list.length > 0) {
95+
try {
96+
setIsLoading(true);
97+
const res = await getBoards({
98+
orderBy,
99+
pageSize: PAGE_SIZE,
100+
page: currentPage,
101+
keyword: searchValue,
102+
});
100103
setBoards(res.list);
101-
} else {
104+
} catch {
102105
setBoards([]);
106+
} finally {
107+
setIsLoading(false);
103108
}
104109
};
105110

@@ -177,23 +182,31 @@ export default function Boards({
177182

178183
{/* 게시글 목록 */}
179184
{boards.length > 0 ? (
180-
<BoardList data={boards} />
185+
<>
186+
{isLoading ? (
187+
<div className="flex h-[540px] items-center justify-center">
188+
<Spinner />
189+
</div>
190+
) : (
191+
<>
192+
<BoardList data={boards} />
193+
194+
{/* 페이지네이션 */}
195+
<div className="mt-[60px] mo:mt-8">
196+
<Pagination
197+
totalCount={totalCount}
198+
currentPage={currentPage}
199+
pageSize={PAGE_SIZE}
200+
onPageChange={(page) => setCurrentPage(page)}
201+
/>
202+
</div>
203+
</>
204+
)}
205+
</>
181206
) : (
182207
<EmptyList classNames="mt-[60px] mo:mt-10" text={emptyListText} />
183208
)}
184209
</div>
185-
186-
{/* 페이지네이션 */}
187-
{boards.length > 0 && (
188-
<div className="mo:-mt-2">
189-
<Pagination
190-
totalCount={totalCount}
191-
currentPage={currentPage}
192-
pageSize={PAGE_SIZE}
193-
onPageChange={(page) => setCurrentPage(page)}
194-
/>
195-
</div>
196-
)}
197210
</div>
198211
<SnackBar
199212
severity={snackStyled}

0 commit comments

Comments
 (0)