Skip to content

Commit 6acfb90

Browse files
committed
Working: 링크 카드 눌렀을 때 수정하고, 삭제하는 기능 해야됨
2 parents e73b75d + fa6f135 commit 6acfb90

File tree

10 files changed

+30
-29
lines changed

10 files changed

+30
-29
lines changed

components/Folder/FolderActionsMenu.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import useRerenderFolderList from "../../hooks/useRerenderFolderList";
66
interface FolderActionsMenuProps {
77
setFolderList: React.Dispatch<React.SetStateAction<FolderData[]>>;
88
folderId: string | string[] | undefined;
9+
linkCount: number;
910
}
1011

1112
const FolderActionsMenu = ({
1213
setFolderList,
1314
folderId,
15+
linkCount,
1416
}: FolderActionsMenuProps) => {
1517
const { isOpen, openModal } = useModalStore();
1618

@@ -27,6 +29,7 @@ const FolderActionsMenu = ({
2729
case "삭제":
2830
openModal("DeleteFolderModal", {
2931
folderId: Number(folderId),
32+
linkCount: linkCount,
3033
});
3134
break;
3235
default:

components/Link/LinkCard.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ const LinkCard = ({ info }: LinkCardProps) => {
4141
const handleFavoriteToggle = async () => {
4242
setIsSubscribed((prev) => !prev);
4343
try {
44-
await putLinkFavorite(info.id, { favorite: !isSubscribed });
4544
updateFavorite(info.id, !isSubscribed);
4645
} catch (error) {
4746
console.error("즐겨찾기 설정 중 오류 발생:", error);

components/Search/SearchInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const SearchInput = () => {
2424
return (
2525
<form
2626
onSubmit={handleSubmit}
27-
className="flex gap-[8px] w-[1024px] h-[54px] items-center px-[16px] py-[15px] bg-gray-100 rounded-[10px] md:w-[704px] md:h-[54px] sm:w-[415px] sm:h-[43px] transition-all"
27+
className="flex gap-[8px] w-full h-[54px] items-center px-[16px] py-[15px] bg-gray-100 rounded-[10px] md:h-[54px] sm:h-[43px] transition-all"
2828
>
2929
<Image
3030
src="/icons/search.svg"

hooks/useFetchLinks.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { useEffect } from "react";
22
import { proxy } from "@/lib/api/axiosInstanceApi";
33
import { LinkData } from "@/types/linkTypes";
4-
import useViewport from "./useViewport";
54
import { ParsedUrlQuery } from "querystring";
5+
import useViewport from "./useViewport";
66

77
// 링크페이지의 query가 바뀌면 그에 맞는 링크들을 보여주는 훅
88
const useFetchLinks = (
9-
setLinkCardList: (list: LinkData[]) => void,
9+
setLinkCardList: React.Dispatch<React.SetStateAction<LinkData[]>>,
10+
setTotalCount: React.Dispatch<React.SetStateAction<number>>,
1011
query: ParsedUrlQuery,
1112
pathname: string
1213
) => {
@@ -29,8 +30,9 @@ const useFetchLinks = (
2930
search: query.search,
3031
},
3132
});
32-
console.log("폴더 눌렀을 때 다시 받아온 리스트:", res.data.list);
33+
console.log("query가 바뀌었을 때 다시 받아온 리스트:", res.data.list);
3334
setLinkCardList(res.data.list);
35+
setTotalCount(res.data.totalCount);
3436
};
3537
if (query) fetchLinks();
3638
}, [setLinkCardList, query, isTablet]);

next.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { NextConfig } from "next";
22

33
const nextConfig: NextConfig = {
44
/* config options here */
5-
reactStrictMode: true,
5+
reactStrictMode: false,
66
// 외부 이미지 도메인 추가
77
images: {
88
remotePatterns: [

pages/api/folders/[folderId]/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
5151
}
5252

5353
case "DELETE":
54+
console.log("너 왔니?");
5455
try {
5556
await axiosInstance.delete(`/folders/${folderId}`, {
5657
headers: {

pages/api/links/[linkId]/favorite.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
1515
switch (req.method) {
1616
case "PUT":
1717
const { favorite } = req.body;
18-
if (favorite === undefined) {
19-
return res.status(400).json({ message: "즐겨찾기 상태가 필요합니다." });
18+
19+
if (favorite === undefined || typeof favorite !== "boolean") {
20+
return res
21+
.status(400)
22+
.json({ message: "즐겨찾기 상태는 boolean이어야 합니다." });
2023
}
2124

2225
try {

pages/favorite/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const FavoritePage = ({ favoriteList, totalCount }: FavoriteProps) => {
5050
const [linkCardList, setLinkCardList] =
5151
useState<FavoriteDataType[]>(favoriteList);
5252

53-
useFetchLinks(router.query, setLinkCardList);
53+
useFetchLinks(setLinkCardList);
5454
return (
5555
<>
5656
<div className="page-title pt-[10px] md:pt-5 pb-10 md:pb-[60px] bg-gray100 text-center">

pages/link/index.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
import { useEffect, useState } from "react";
1+
import { useState } from "react";
22
import { GetServerSidePropsContext } from "next";
33
import { useRouter } from "next/router";
44
import { parse } from "cookie";
55
import { LinkData } from "@/types/linkTypes";
66
import { FolderData } from "@/types/folderTypes";
77
import { Modal } from "@/components/modal/modalManager/ModalManager";
8-
import { useLinkCardStore } from "@/store/useLinkCardStore";
98
import { SearchInput } from "../../components/Search/SearchInput";
109
import axiosInstance from "@/lib/api/axiosInstanceApi";
1110
import useModalStore from "@/store/useModalStore";
1211
import Pagination from "@/components/Pagination";
13-
import useFetchLinks from "@/hooks/useFetchLinks";
1412
import AddLinkInput from "@/components/Link/AddLinkInput";
1513
import Container from "@/components/Layout/Container";
1614
import SearchResultMessage from "@/components/Search/SearchResultMessage";
@@ -20,6 +18,7 @@ import FolderActionsMenu from "@/components/Folder/FolderActionsMenu";
2018
import CardsLayout from "@/components/Layout/CardsLayout";
2119
import LinkCard from "@/components/Link/LinkCard";
2220
import RenderEmptyLinkMessage from "@/components/Link/RenderEmptyLinkMessage";
21+
import useFetchLinks from "@/hooks/useFetchLinks";
2322
import useViewport from "@/hooks/useViewport";
2423

2524
interface LinkPageProps {
@@ -62,22 +61,18 @@ export const getServerSideProps = async (
6261
const LinkPage = ({
6362
linkList: initialLinkList,
6463
folderList: initialFolderList,
65-
totalCount,
64+
totalCount: initialTotalCount,
6665
}: LinkPageProps) => {
6766
const router = useRouter();
6867
const { search, folder } = router.query;
69-
const { linkCardList, setLinkCardList } = useLinkCardStore.getState();
7068
const { isOpen } = useModalStore();
7169
const { isMobile } = useViewport();
70+
const [linkCardList, setLinkCardList] = useState(initialLinkList);
7271
const [folderList, setFolderList] = useState(initialFolderList);
73-
74-
// 클라이언트에서 초기 목록을 설정
75-
useEffect(() => {
76-
setLinkCardList(initialLinkList);
77-
}, [initialLinkList, setLinkCardList]);
72+
const [totalCount, setTotalCount] = useState(initialTotalCount);
7873

7974
// 링크페이지의 query가 바뀌면 새로운 리스트로 업데이트 해주는 훅
80-
useFetchLinks(setLinkCardList, router.query, router.pathname);
75+
useFetchLinks(setLinkCardList, setTotalCount, router.query, router.pathname);
8176

8277
console.log(linkCardList);
8378

@@ -100,6 +95,7 @@ const LinkPage = ({
10095
<FolderActionsMenu
10196
setFolderList={setFolderList}
10297
folderId={folder}
98+
linkCount={totalCount}
10399
/>
104100
)}
105101
</div>

store/useLinkCardStore.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
deleteLinkURL,
3-
getLinks,
4-
putLinkFavorite,
5-
putLinkURL,
6-
} from "@/lib/api/link";
1+
import { deleteLinkURL, putLinkFavorite, putLinkURL } from "@/lib/api/link";
72
import { create } from "zustand";
83
import { LinkData } from "@/types/linkTypes";
94

@@ -13,17 +8,19 @@ interface UpdateLinkBody {
138

149
interface LinkCardStore {
1510
linkCardList: LinkData[];
16-
setLinkCardList: (list: LinkData[]) => void;
11+
setLinkCardList: (list: LinkData[], totalCount: number) => void;
1712
updateLink: (linkId: number, body: UpdateLinkBody) => Promise<void>;
1813
deleteLink: (linkId: number) => Promise<void>;
1914
updateFavorite: (linkId: number, favorite: boolean) => Promise<void>;
15+
totalCount: number | null;
2016
}
2117

2218
export const useLinkCardStore = create<LinkCardStore>((set) => ({
2319
linkCardList: [],
20+
totalCount: null,
2421

25-
setLinkCardList: (list: LinkData[]) => {
26-
set({ linkCardList: list });
22+
setLinkCardList: (list: LinkData[], totalCount: number) => {
23+
set({ linkCardList: list, totalCount: totalCount });
2724
},
2825

2926
// 수정 요청 보낸 후 목록 가져오기

0 commit comments

Comments
 (0)