Skip to content

Commit d489199

Browse files
authored
Feat: 공유 페이지 생성
Feat: 공유 페이지 생성
2 parents 4f56621 + e8624b3 commit d489199

File tree

4 files changed

+78
-12
lines changed

4 files changed

+78
-12
lines changed

components/Link/LinkCard.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const LinkCard = ({ info }: LinkCardProps) => {
3131
const createdTime = timeAgo(info.createdAt);
3232

3333
const router = useRouter();
34-
const isFavoritePage = router.pathname === "/favorite";
34+
const onlyLinkPage = router.pathname === "/link";
3535
const dropdownRef = useRef<HTMLDivElement | null>(null);
3636

3737
// 모달이 열릴 때 드롭다운 닫기
@@ -98,7 +98,7 @@ const LinkCard = ({ info }: LinkCardProps) => {
9898
fill
9999
/>
100100
{/* 즐겨찾기 페이지가 아닐 때에는 즐겨찾기 버튼 렌더링x */}
101-
{!isFavoritePage && (
101+
{onlyLinkPage && (
102102
<div
103103
onClick={handleFavoriteToggle}
104104
className="absolute top-[15px] right-[15px] z-1"
@@ -121,7 +121,7 @@ const LinkCard = ({ info }: LinkCardProps) => {
121121
{createdTime || "1일 전"}
122122
</span>
123123
{/* isFavoritePage일 때만 케밥 버튼 렌더링 */}
124-
{!isFavoritePage && (
124+
{onlyLinkPage && (
125125
<div className="relative" ref={dropdownRef}>
126126
<button
127127
className="relative w-[21px] h-[17px]"

lib/api/link.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@ interface putLinkFavoriteProps {
1414
}
1515

1616
// 폴더에 속한 링크 조회
17-
export const getLink = async (query: any, forderId: number) => {
18-
let queryString;
19-
query ? (queryString = `?page=${query.page}&pageSize=${query.pageSize}`) : "";
20-
17+
export const getLink = async (
18+
query: any,
19+
forderId: string | string[] | undefined
20+
) => {
2121
try {
22-
const res = await axiosInstance.get(
23-
`/folders/${forderId}/links${queryString}`
24-
);
22+
const res = await axiosInstance.get(`/folders/${forderId}/links`, {
23+
params: {
24+
page: query.page || 1,
25+
pageSize: query.pageSize || 10,
26+
},
27+
});
28+
2529
if (res.status >= 200 && res.status < 300) return res.data;
2630
} catch (err) {
2731
console.error("에러 메시지: ", err instanceof Error ? err.message : err);

pages/share/[folderId].tsx

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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;

util/shareSNS.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export const handleShareKakao = () => {
1414
description: "나에게 필요한 링크만 모아 두었어요!",
1515
imageUrl: "https://linkbrary-9-99.vercel.app/images/home_main.png", //배포 후 실제 도메인으로 변경 필요
1616
link: {
17-
mobileWebUrl: location.href,
18-
webUrl: location.href,
17+
mobileWebUrl: location.href.replace("link?", "share?"),
18+
webUrl: location.href.replace("link?", "share?"),
1919
},
2020
},
2121
});

0 commit comments

Comments
 (0)