@@ -18,6 +18,7 @@ import { useProfileContext } from '@/hooks/useProfileContext';
1818import SnackBar , { SnackBarProps } from '@/components/SnackBar' ;
1919import Router from 'next/router' ;
2020import EmptyList from '@/components/EmptyList' ;
21+ import Spinner from '@/components/Spinner' ;
2122
2223const 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