1+ import { GetServerSideProps , GetServerSidePropsContext } from "next" ;
2+ import { proxy } from "@/lib/api/axiosInstanceApi" ;
3+ import LinkCard from "@/components/LinkCard" ;
14import CardsLayout from "@/components/Layout/CardsLayout" ;
25import Container from "@/components/Layout/Container" ;
36
4- const Favorite = ( ) => {
7+ interface FavoriteDataType {
8+ id : number ;
9+ favorite : boolean ;
10+ url : string ;
11+ title : string ;
12+ imageSource : string ;
13+ description : string ;
14+ createdAt : string ;
15+ }
16+
17+ interface FavoriteProps {
18+ totalCount : number ;
19+ favoriteList : FavoriteDataType [ ] ;
20+ }
21+
22+ export const getServerSideProps : GetServerSideProps = async (
23+ context : GetServerSidePropsContext
24+ ) => {
25+ const { req } = context ;
26+
27+ // 클라이언트의 쿠키 가져오기
28+ const cookies = req . headers . cookie || "" ;
29+
30+ try {
31+ const res = await proxy . get ( "/api/favorites" , {
32+ headers : {
33+ Cookie : cookies , // 쿠키를 그대로 포함시킴
34+ } ,
35+ } ) ;
36+
37+ const { list, totalCount } = res . data || { list : [ ] , totalCount : 0 } ;
38+ return { props : { favoriteList : list , totalCount } } ;
39+ } catch ( error ) {
40+ console . error ( "서버사이드에러" , error ) ;
41+ return { props : { favoriteList : [ ] , totalCount : 0 } } ;
42+ }
43+ } ;
44+
45+ const FavoritePage = ( { favoriteList, totalCount } : FavoriteProps ) => {
546 return (
647 < >
748 < div className = "page-title pt-[10px] md:pt-5 pb-10 md:pb-[60px] bg-gray100 text-center" >
@@ -11,17 +52,37 @@ const Favorite = () => {
1152 </ div >
1253 < Container >
1354 < CardsLayout >
14- { /* 카드 공통 컴포넌트로 구현 예정 */ }
15- < div className = "border border-red-800" > card</ div >
16- < div className = "border border-red-800" > card</ div >
17- < div className = "border border-red-800" > card</ div >
18- < div className = "border border-red-800" > card</ div >
19- < div className = "border border-red-800" > card</ div >
20- < div className = "border border-red-800" > card</ div >
55+ { favoriteList . length > 0
56+ ? favoriteList . map ( ( favorite ) => (
57+ < LinkCard
58+ key = { favorite . id }
59+ id = { favorite . id }
60+ url = { favorite . url }
61+ title = { favorite . title }
62+ imageSource = { favorite . imageSource }
63+ description = { favorite . description }
64+ createdAt = { favorite . createdAt }
65+ isFavoritePage = { true }
66+ />
67+ ) )
68+ : null }
2169 </ CardsLayout >
70+
71+ { /* 즐겨찾기 항목이 없을 때 보여줄 메시지 (공통 컴포넌트로 사용할 건지 논의 필요) */ }
72+ { favoriteList . length === 0 && (
73+ < div className = "flex flex-col justify-center items-center h-full p-10 bg-gray100 text-center text-gray600" >
74+ < div className = "text-2xl md:text-3xl font-semibold text-gray600" >
75+ < span className = "block mb-4" > ⭐️</ span >
76+ 즐겨찾기 항목이 없습니다.
77+ </ div >
78+ < div className = "text-sm text-purple100 mt-2" >
79+ 저장한 즐겨찾기 항목을 추가해보세요.
80+ </ div >
81+ </ div >
82+ ) }
2283 </ Container >
2384 </ >
2485 ) ;
2586} ;
2687
27- export default Favorite ;
88+ export default FavoritePage ;
0 commit comments