|
| 1 | +import { GetServerSidePropsContext } from "next"; |
| 2 | +import { LinkData } from "@/types/linkTypes"; |
| 3 | +import { getFolder } from "@/lib/api/folder"; |
| 4 | +import { getLink } from "../../lib/api/link"; |
| 5 | +import CardsLayout from "@/components/Layout/CardsLayout"; |
| 6 | +import Container from "@/components/Layout/Container"; |
| 7 | +import LinkCard from "@/components/Link/LinkCard"; |
| 8 | +import Pagination from "@/components/Pagination"; |
| 9 | + |
| 10 | +interface SharePageprops { |
| 11 | + folderName: string; |
| 12 | + linkList: LinkData[]; |
| 13 | + totalCount: number; |
| 14 | +} |
| 15 | + |
| 16 | +export const getServerSideProps = async ( |
| 17 | + context: GetServerSidePropsContext |
| 18 | +) => { |
| 19 | + const { page, pageSize } = context.query; |
| 20 | + const { folderId } = context.params!; |
| 21 | + |
| 22 | + const folderListData = await getLink( |
| 23 | + { page: page, pageSize: pageSize }, |
| 24 | + folderId |
| 25 | + ); |
| 26 | + |
| 27 | + const folderNameData = await getFolder(folderId); |
| 28 | + |
| 29 | + return { |
| 30 | + props: { |
| 31 | + folderName: folderNameData.name, |
| 32 | + linkList: folderListData.list, |
| 33 | + totalCount: folderListData.totalCount, |
| 34 | + }, |
| 35 | + }; |
| 36 | +}; |
| 37 | + |
| 38 | +const SharePage = ({ folderName, linkList, totalCount }: SharePageprops) => { |
| 39 | + return ( |
| 40 | + <> |
| 41 | + <div className="flex justify-center items-center sm:h-[117px] h-[219px] sm:mb-5 mb-10 bg-gray100 text-center"> |
| 42 | + <h2 className="text-[32px] md:text-[40px] font-semibold"> |
| 43 | + {folderName} |
| 44 | + </h2> |
| 45 | + </div> |
| 46 | + <Container> |
| 47 | + {linkList.length > 0 && ( |
| 48 | + <> |
| 49 | + <CardsLayout> |
| 50 | + {linkList.length > 0 |
| 51 | + ? linkList.map((link) => <LinkCard key={link.id} info={link} />) |
| 52 | + : null} |
| 53 | + </CardsLayout> |
| 54 | + <Pagination totalCount={totalCount} /> |
| 55 | + </> |
| 56 | + )} |
| 57 | + </Container> |
| 58 | + </> |
| 59 | + ); |
| 60 | +}; |
| 61 | + |
| 62 | +export default SharePage; |
0 commit comments