From 0ca341ea392b520ba0e5fe444b450ecd2a841b21 Mon Sep 17 00:00:00 2001 From: hoj0806 <90647684+hoj0806@users.noreply.github.com> Date: Mon, 13 May 2024 13:32:16 +0900 Subject: [PATCH 01/14] =?UTF-8?q?refactor=20:=20queryProvider=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/layout.tsx | 6 ++++-- package-lock.json | 51 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 ++ util/Provder.tsx | 17 ++++++++++++++++ 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 util/Provder.tsx diff --git a/app/layout.tsx b/app/layout.tsx index c2551c870..4fc2da35b 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -2,7 +2,7 @@ import { Metadata } from "next"; import "../styles/global.css"; import { ReactNode } from "react"; - +import Provider from "@/util/Provder"; export const metadata: Metadata = { title: { template: "%s | Linkbrary", @@ -14,7 +14,9 @@ export const metadata: Metadata = { const RootLayout = ({ children }: { children: ReactNode }) => { return ( - {children} + + {children} + ); }; diff --git a/package-lock.json b/package-lock.json index eba7b7259..6563ae8d0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,8 @@ "name": "fe-weekly-mission", "version": "0.1.0", "dependencies": { + "@tanstack/react-query": "^5.36.0", + "@tanstack/react-query-devtools": "^5.36.0", "next": "^14.1.4", "react": "^18.2.0", "react-dom": "^18.2.0", @@ -640,6 +642,55 @@ "tslib": "^2.4.0" } }, + "node_modules/@tanstack/query-core": { + "version": "5.36.0", + "resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.36.0.tgz", + "integrity": "sha512-B5BD3pg/mztDR36i77hGcyySKKeYrbM5mnogOROTBi1SUml5ByRK7PGUUl16vvubvQC+mSnqziFG/VIy/DE3FQ==", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/tannerlinsley" + } + }, + "node_modules/@tanstack/query-devtools": { + "version": "5.32.1", + "resolved": "https://registry.npmjs.org/@tanstack/query-devtools/-/query-devtools-5.32.1.tgz", + "integrity": "sha512-7Xq57Ctopiy/4atpb0uNY5VRuCqRS/1fi/WBCKKX6jHMa6cCgDuV/AQuiwRXcKARbq2OkVAOrW2v4xK9nTbcCA==", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/tannerlinsley" + } + }, + "node_modules/@tanstack/react-query": { + "version": "5.36.0", + "resolved": "https://registry.npmjs.org/@tanstack/react-query/-/react-query-5.36.0.tgz", + "integrity": "sha512-BATvtM0rohwg7pRHUnxgeDiwLWRGZ8OM/4y8LImHVpecQWoH6Uhytu3Z8YV6V7hQ1sMQBFcUrGE1/e4MxR6YiA==", + "dependencies": { + "@tanstack/query-core": "5.36.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/tannerlinsley" + }, + "peerDependencies": { + "react": "^18.0.0" + } + }, + "node_modules/@tanstack/react-query-devtools": { + "version": "5.36.0", + "resolved": "https://registry.npmjs.org/@tanstack/react-query-devtools/-/react-query-devtools-5.36.0.tgz", + "integrity": "sha512-AxZSmM7CmjDQrcY9gceFBS+1DqkfTqAMpDCMltzIxMKvKn+ZhgBsV49aewhVXP1DgZzb+Is4f9HH2EMu//njXw==", + "dependencies": { + "@tanstack/query-devtools": "5.32.1" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/tannerlinsley" + }, + "peerDependencies": { + "@tanstack/react-query": "^5.36.0", + "react": "^18.0.0" + } + }, "node_modules/@types/json5": { "version": "0.0.29", "resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz", diff --git a/package.json b/package.json index 089b4bb84..914d8ff09 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,8 @@ "lint": "next lint" }, "dependencies": { + "@tanstack/react-query": "^5.36.0", + "@tanstack/react-query-devtools": "^5.36.0", "next": "^14.1.4", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/util/Provder.tsx b/util/Provder.tsx new file mode 100644 index 000000000..f02092d82 --- /dev/null +++ b/util/Provder.tsx @@ -0,0 +1,17 @@ +"use client"; + +import { ReactNode } from "react"; +import { QueryClientProvider, QueryClient } from "@tanstack/react-query"; +import { ReactQueryDevtools } from "@tanstack/react-query-devtools/production"; +import { useState } from "react"; + +export default function Provider({ children }: { children: ReactNode }) { + const [queryClient] = useState(() => new QueryClient()); + + return ( + + + {children} + + ); +} From 137ac17baade6c12467dbf47a0f0f10b8decb071 Mon Sep 17 00:00:00 2001 From: hoj0806 <90647684+hoj0806@users.noreply.github.com> Date: Mon, 13 May 2024 14:31:22 +0900 Subject: [PATCH 02/14] =?UTF-8?q?refactor=20:=20axios=20instance=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/auth.ts | 25 +++++ api/axiosInstance.ts | 6 ++ app/layout.tsx | 2 +- .../signInPage/SignInForm/SignInForm.tsx | 5 +- package-lock.json | 91 +++++++++++++++++++ package.json | 1 + util/{Provder.tsx => Provider.tsx} | 0 7 files changed, 127 insertions(+), 3 deletions(-) create mode 100644 api/auth.ts create mode 100644 api/axiosInstance.ts rename util/{Provder.tsx => Provider.tsx} (100%) diff --git a/api/auth.ts b/api/auth.ts new file mode 100644 index 000000000..4a759c88c --- /dev/null +++ b/api/auth.ts @@ -0,0 +1,25 @@ +import { instance } from "./axiosInstance"; + +const sendSignInRequest = async (email: string, password: string) => { + try { + const response = await instance.post( + "/auth/sign-in", + { + email: email, + password: password, + }, + { + headers: { + accept: "*/*", + "Content-Type": "application/json", + }, + } + ); + return response; + } catch (error) { + console.error("Error during sign-in:", error); + throw error; + } +}; + +export default sendSignInRequest; diff --git a/api/axiosInstance.ts b/api/axiosInstance.ts new file mode 100644 index 000000000..637bab73f --- /dev/null +++ b/api/axiosInstance.ts @@ -0,0 +1,6 @@ +import axios from "axios"; + +export const instance = axios.create({ + baseURL: "https://bootcamp-api.codeit.kr/api/linkbrary/v1", + withCredentials: true, +}); diff --git a/app/layout.tsx b/app/layout.tsx index 4fc2da35b..2210ca642 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -2,7 +2,7 @@ import { Metadata } from "next"; import "../styles/global.css"; import { ReactNode } from "react"; -import Provider from "@/util/Provder"; +import Provider from "@/util/Provider"; export const metadata: Metadata = { title: { template: "%s | Linkbrary", diff --git a/components/signInPage/SignInForm/SignInForm.tsx b/components/signInPage/SignInForm/SignInForm.tsx index c05a941b5..8771233db 100644 --- a/components/signInPage/SignInForm/SignInForm.tsx +++ b/components/signInPage/SignInForm/SignInForm.tsx @@ -33,7 +33,7 @@ const SignInForm = () => { const onSubmit = async (data: FormValueType) => { try { const response = await fetch( - "https://bootcamp-api.codeit.kr/api/sign-in", + "https://bootcamp-api.codeit.kr/api/linkbrary/v1/auth/sign-in", { method: "POST", headers: { @@ -52,7 +52,8 @@ const SignInForm = () => { return; } const json = await response.json(); - const accessToken = json.data.accessToken; + console.log(json); + const accessToken = json.accessToken; localStorage.setItem("accessToken", accessToken); router.push("/folder"); } catch (error) { diff --git a/package-lock.json b/package-lock.json index 6563ae8d0..c6acc8a5d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "dependencies": { "@tanstack/react-query": "^5.36.0", "@tanstack/react-query-devtools": "^5.36.0", + "axios": "^1.6.8", "next": "^14.1.4", "react": "^18.2.0", "react-dom": "^18.2.0", @@ -1079,6 +1080,11 @@ "has-symbols": "^1.0.3" } }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, "node_modules/available-typed-arrays": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz", @@ -1100,6 +1106,16 @@ "node": ">=4" } }, + "node_modules/axios": { + "version": "1.6.8", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz", + "integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==", + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/axobject-query": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-3.2.1.tgz", @@ -1244,6 +1260,17 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -1352,6 +1379,14 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/dequal": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz", @@ -2071,6 +2106,25 @@ "integrity": "sha512-36yxDn5H7OFZQla0/jFJmbIKTdZAQHngCedGxiMmpNfEZM0sdEeT+WczLQrjK6D7o2aiyLYDnkw0R3JK0Qv1RQ==", "dev": true }, + "node_modules/follow-redirects": { + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, "node_modules/for-each": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", @@ -2080,6 +2134,19 @@ "is-callable": "^1.1.3" } }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -2964,6 +3031,25 @@ "node": ">=8.6" } }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -3369,6 +3455,11 @@ "react-is": "^16.13.1" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", diff --git a/package.json b/package.json index 914d8ff09..a7527a03d 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "dependencies": { "@tanstack/react-query": "^5.36.0", "@tanstack/react-query-devtools": "^5.36.0", + "axios": "^1.6.8", "next": "^14.1.4", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/util/Provder.tsx b/util/Provider.tsx similarity index 100% rename from util/Provder.tsx rename to util/Provider.tsx From 497e37347337f35f090868101f70a98b1ab443e4 Mon Sep 17 00:00:00 2001 From: hoj0806 <90647684+hoj0806@users.noreply.github.com> Date: Mon, 13 May 2024 17:43:51 +0900 Subject: [PATCH 03/14] =?UTF-8?q?feat=20:=20=ED=8F=B4=EB=8D=94=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=EC=99=80=20=EB=8F=99=EC=8B=9C=EC=97=90=20?= =?UTF-8?q?=ED=8F=B4=EB=8D=94=20=EC=BF=BC=EB=A6=AC=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=20=EC=B5=9C=EC=8B=A0=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/auth.ts | 25 --------- api/axiosInstance.ts | 3 +- api/folder.ts | 25 +++++++++ api/folders.ts | 43 +++++++++++++++ api/links.ts | 24 ++++++++ api/shared.ts | 0 api/user.ts | 24 ++++++++ app/(FolderPage)/folder/[folderId]/page.tsx | 55 +++++++++++++++++++ app/(FolderPage)/folder/page.tsx | 41 ++++++++++---- app/(SharedPage)/shared/[folderId]/page.tsx | 13 +++++ .../FolderFilterBox/FolderFilterBox.tsx | 42 +++++++++----- .../FolderPageMain/FolderPageMain.tsx | 19 ++++++- components/folderPage/LinkList/LinkList.tsx | 14 ++++- .../LinkListByFolderId.module.css | 35 ++++++++++++ .../LinkListByFolderId/LinkListByFolderId.tsx | 55 +++++++++++++++++++ .../modal/AddFolderModal/AddFolderModal.tsx | 29 +++++++++- .../modal/ModalButton/ModalButton.tsx | 15 +++-- ...odule.css => SharePageLinkList.module.css} | 0 ...geFolderList.tsx => SharePageLinkList.tsx} | 1 - .../SharedPageMain/SharedPageMain.tsx | 2 +- .../signInPage/SignInForm/SignInForm.tsx | 1 - 21 files changed, 404 insertions(+), 62 deletions(-) delete mode 100644 api/auth.ts create mode 100644 api/folder.ts create mode 100644 api/folders.ts create mode 100644 api/links.ts create mode 100644 api/shared.ts create mode 100644 api/user.ts create mode 100644 app/(FolderPage)/folder/[folderId]/page.tsx create mode 100644 app/(SharedPage)/shared/[folderId]/page.tsx create mode 100644 components/folderPage/LinkListByFolderId/LinkListByFolderId.module.css create mode 100644 components/folderPage/LinkListByFolderId/LinkListByFolderId.tsx rename components/sharedPage/SharePageFolderList/{SharePageFolderList.module.css => SharePageLinkList.module.css} (100%) rename components/sharedPage/SharePageFolderList/{SharePageFolderList.tsx => SharePageLinkList.tsx} (90%) diff --git a/api/auth.ts b/api/auth.ts deleted file mode 100644 index 4a759c88c..000000000 --- a/api/auth.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { instance } from "./axiosInstance"; - -const sendSignInRequest = async (email: string, password: string) => { - try { - const response = await instance.post( - "/auth/sign-in", - { - email: email, - password: password, - }, - { - headers: { - accept: "*/*", - "Content-Type": "application/json", - }, - } - ); - return response; - } catch (error) { - console.error("Error during sign-in:", error); - throw error; - } -}; - -export default sendSignInRequest; diff --git a/api/axiosInstance.ts b/api/axiosInstance.ts index 637bab73f..90917e4bb 100644 --- a/api/axiosInstance.ts +++ b/api/axiosInstance.ts @@ -2,5 +2,6 @@ import axios from "axios"; export const instance = axios.create({ baseURL: "https://bootcamp-api.codeit.kr/api/linkbrary/v1", - withCredentials: true, }); + +axios.defaults.withCredentials = true; diff --git a/api/folder.ts b/api/folder.ts new file mode 100644 index 000000000..4555be7bb --- /dev/null +++ b/api/folder.ts @@ -0,0 +1,25 @@ +import axios from "axios"; +import { instance } from "./axiosInstance"; + +export const getAllLinks = async () => { + // 로컬 스토리지에서 엑세스 토큰을 가져옵니다. + const accessToken = localStorage.getItem("accessToken"); + + try { + const response = await instance.get( + "https://bootcamp-api.codeit.kr/api/linkbrary/v1/links", + { + headers: { + Authorization: `Bearer ${accessToken}`, // Bearer 토큰 추가 + }, + } + ); + + return response.data; + } catch (error) { + console.error("Error fetching links:", error); + throw error; + } +}; + +axios.defaults.withCredentials = true; diff --git a/api/folders.ts b/api/folders.ts new file mode 100644 index 000000000..c489a6085 --- /dev/null +++ b/api/folders.ts @@ -0,0 +1,43 @@ +import axios from "axios"; +import { instance } from "./axiosInstance"; + +export const getAllFolders = async () => { + const accessToken = localStorage.getItem("accessToken"); + try { + const response = await instance.get( + "https://bootcamp-api.codeit.kr/api/linkbrary/v1/folders", + { + headers: { + Authorization: `Bearer ${accessToken}`, // Bearer 토큰 추가 + }, + } + ); + + return response.data; + } catch (error) { + console.error("Error fetching links:", error); + throw error; + } +}; + +export const addFolder = async (folderName: string) => { + const accessToken = localStorage.getItem("accessToken"); + try { + const response = await instance.post( + "https://bootcamp-api.codeit.kr/api/linkbrary/v1/folders", + { + name: folderName, + }, + { + headers: { + Authorization: `Bearer ${accessToken}`, // Bearer 토큰 추가 + }, + } + ); + return response.data; + } catch (error) { + console.error("error"); + throw error; + } +}; +axios.defaults.withCredentials = true; diff --git a/api/links.ts b/api/links.ts new file mode 100644 index 000000000..fba2f6c36 --- /dev/null +++ b/api/links.ts @@ -0,0 +1,24 @@ +import axios from "axios"; +import { instance } from "./axiosInstance"; + +export const getLinksByFolderId = async (folderId: string) => { + const accessToken = localStorage.getItem("accessToken"); + + try { + const response = await instance.get( + `https://bootcamp-api.codeit.kr/api/linkbrary/v1/folders/${folderId}/links`, + { + headers: { + Authorization: `Bearer ${accessToken}`, // Bearer 토큰 추가 + }, + } + ); + + return response.data; + } catch (error) { + console.error("Error fetching links:", error); + throw error; + } +}; + +axios.defaults.withCredentials = true; diff --git a/api/shared.ts b/api/shared.ts new file mode 100644 index 000000000..e69de29bb diff --git a/api/user.ts b/api/user.ts new file mode 100644 index 000000000..1bcb93774 --- /dev/null +++ b/api/user.ts @@ -0,0 +1,24 @@ +import axios from "axios"; +import { instance } from "./axiosInstance"; + +export const getUserInfo = async () => { + // 로컬 스토리지에서 엑세스 토큰을 가져옵니다. + const accessToken = localStorage.getItem("accessToken"); + + try { + const response = await instance.get( + "https://bootcamp-api.codeit.kr/api/linkbrary/v1/users", + { + headers: { + Authorization: `Bearer ${accessToken}`, // Bearer 토큰 추가 + }, + } + ); + return response; + } catch (error) { + console.error("Error fetching links:", error); + throw error; + } +}; + +axios.defaults.withCredentials = true; diff --git a/app/(FolderPage)/folder/[folderId]/page.tsx b/app/(FolderPage)/folder/[folderId]/page.tsx new file mode 100644 index 000000000..b64986bbe --- /dev/null +++ b/app/(FolderPage)/folder/[folderId]/page.tsx @@ -0,0 +1,55 @@ +"use client"; + +import useModal from "@/hooks/useModal"; +import { useState } from "react"; +import AddLink from "@/components/folderPage/AddLink/AddLink"; +import FolderPageMain from "@/components/folderPage/FolderPageMain/FolderPageMain"; +import HeaderFooterLayout from "@/app/headerFooterLayout"; +import { getAllLinks } from "@/api/folder"; +import { useEffect } from "react"; +import { + dehydrate, + HydrationBoundary, + QueryClient, +} from "@tanstack/react-query"; +const FolderPage = () => { + const queryClient = new QueryClient(); + useEffect(() => { + const fetchLinks = async () => { + await queryClient.prefetchQuery({ + queryKey: ["links"], + queryFn: getAllLinks, + }); + }; + + fetchLinks(); + }, []); + const { + isShowModal: isShowAddLinkInFolderModal, + handleModalClick: handleAddLinkInFolderModalClick, + } = useModal(false); + + const [sharedUrl, setSharedUrl] = useState(""); + return ( + <> + Folder | Linkbrary + + + + + + + + + ); +}; + +export default FolderPage; diff --git a/app/(FolderPage)/folder/page.tsx b/app/(FolderPage)/folder/page.tsx index f1859f002..e01685f58 100644 --- a/app/(FolderPage)/folder/page.tsx +++ b/app/(FolderPage)/folder/page.tsx @@ -5,8 +5,27 @@ import { useState } from "react"; import AddLink from "@/components/folderPage/AddLink/AddLink"; import FolderPageMain from "@/components/folderPage/FolderPageMain/FolderPageMain"; import HeaderFooterLayout from "@/app/headerFooterLayout"; +import { getAllLinks } from "@/api/folder"; +import { useEffect } from "react"; +import { + dehydrate, + HydrationBoundary, + QueryClient, +} from "@tanstack/react-query"; + +export const queryClient = new QueryClient(); const FolderPage = () => { + useEffect(() => { + const fetchLinks = async () => { + await queryClient.prefetchQuery({ + queryKey: ["links"], + queryFn: getAllLinks, + }); + }; + + fetchLinks(); + }, []); const { isShowModal: isShowAddLinkInFolderModal, handleModalClick: handleAddLinkInFolderModalClick, @@ -18,16 +37,18 @@ const FolderPage = () => { Folder | Linkbrary - - + + + + ); diff --git a/app/(SharedPage)/shared/[folderId]/page.tsx b/app/(SharedPage)/shared/[folderId]/page.tsx new file mode 100644 index 000000000..fb1a42a33 --- /dev/null +++ b/app/(SharedPage)/shared/[folderId]/page.tsx @@ -0,0 +1,13 @@ +import Profile from "@/components/sharedPage/Profile/Profile"; +import SharedPageMain from "@/components/sharedPage/SharedPageMain/SharedPageMain"; +import HeaderFooterLayout from "@/app/headerFooterLayout"; + +export const metadata = { + title: "Shared", +}; + +const SharedPage = async ({ params }: { folderId: number }) => { + return
{params.folderId}
; +}; + +export default SharedPage; diff --git a/components/folderPage/FolderFilterBox/FolderFilterBox.tsx b/components/folderPage/FolderFilterBox/FolderFilterBox.tsx index 3d001904a..2aa2e3f47 100644 --- a/components/folderPage/FolderFilterBox/FolderFilterBox.tsx +++ b/components/folderPage/FolderFilterBox/FolderFilterBox.tsx @@ -3,7 +3,9 @@ import styles from "./FolderFilterBox.module.css"; import FolderFilterButton from "../FolderFilterButton/FolderFilterButton"; import ShowAllLinksButton from "../ShowAllLinkButton/ShowAllLinkButton"; import { FolderDataType } from "@/types/FolderDataTypes"; - +import { useQuery } from "@tanstack/react-query"; +import { getAllFolders } from "@/api/folders"; +import Link from "next/link"; interface FolderFilterBoxProps { folderData: FolderDataType | null; setFolderName: Dispatch>; @@ -23,6 +25,16 @@ const FolderFilterBox = ({ }: FolderFilterBoxProps) => { const [activeFilterId, setActiveFilterId] = useState("showAll"); + const { data, isLoading, error } = useQuery({ + queryKey: ["folders"], + queryFn: () => getAllFolders(), + }); + + if (isLoading) { + return
로딩중입니다
; + } + + if (error) return
{error.message}
; const handleClickFilterButton = (folderName: string, folderId: number) => { setIsShowFuncButtonBox(true); setFolderName(folderName); @@ -40,20 +52,24 @@ const FolderFilterBox = ({ }; return (
- handleClickShowAllLinksButton()} - /> + + handleClickShowAllLinksButton()} + /> + - {folderData?.data.map(({ name, id }) => { + {data.map(({ name, id }) => { return ( - handleClickFilterButton(name, id)} - /> + + handleClickFilterButton(name, id)} + /> + ); })}
diff --git a/components/folderPage/FolderPageMain/FolderPageMain.tsx b/components/folderPage/FolderPageMain/FolderPageMain.tsx index ee713701c..77c2247c5 100644 --- a/components/folderPage/FolderPageMain/FolderPageMain.tsx +++ b/components/folderPage/FolderPageMain/FolderPageMain.tsx @@ -1,6 +1,6 @@ "use client"; import styles from "./FolderPageMain.module.css"; -import LinkList from "../LinkList/LinkList"; +import LinkListByFolderId from "../LinkListByFolderId/LinkListByFolderId"; import { Dispatch, SetStateAction, useState, useEffect } from "react"; import LinkSearchInput from "@/components/common/LinkSearchInput/LinkSearchInput"; import useModal from "@/hooks/useModal"; @@ -15,6 +15,9 @@ import AddLinkInFolder from "../modal/AddLinkInFolder/AddLinkInFolder"; import ShareFolderModal from "../modal/ShareFolderModal/ShareFolderModal"; import LinkFuncButtonBox from "../LinkFuncButtonBox/LinkFuncButtonBox"; import ShowSearchData from "../ShowSearchData/ShowSearchData"; +import { useQuery } from "@tanstack/react-query"; +import { getAllLinks } from "@/api/folder"; +import { getUserInfo } from "@/api/user"; interface FolderPageMainProps { isShowAddLinkInFolderModal: boolean; @@ -31,6 +34,18 @@ const FolderPageMain = ({ sharedUrl, setSharedUrl, }: FolderPageMainProps) => { + const { data } = useQuery({ + queryKey: ["links"], + queryFn: getAllLinks, + }); + + const { data: userData } = useQuery({ + queryKey: ["user"], + queryFn: getUserInfo, + }); + + console.log(data); + const [linkData, setLinkData] = useState(null); const [folderId, setFolderId] = useState(""); @@ -126,7 +141,7 @@ const FolderPageMain = ({ /> )} - @@ -16,13 +17,22 @@ const LinkList = ({ setSharedUrl, linkData, }: LinkListProps) => { + + const { data, isLoading, error } = useQuery({ + queryKey: ["links"], + queryFn: () => getAllLinks(), + }); + + if (isLoading) return
Loading...
; + if (error) return
Error: {error.message}
; + console.log(data); return (
{linkData?.data.length === 0 ? (
저장된 링크가 없습니다
) : (
- {linkData?.data.map((item) => { + {data.map((item) => { return ( + ) => void; + setSharedUrl: Dispatch>; + linkData: LinkDataType | null; +} + +const LinkListByFolderId = ({ + handleAddLinkInFolderModalClick, + setSharedUrl, + linkData, + params, +}: LinkListProps) => { + const { data, isLoading, error } = useQuery({ + queryKey: ["links"], + queryFn: () => getLinksByFolderId(params.folderId), + }); + + if (isLoading) return
Loading...
; + if (error) return
Error: {error.message}
; + console.log(data); + return ( +
+ {linkData?.data.length === 0 ? ( +
저장된 링크가 없습니다
+ ) : ( +
+ {data.map((item) => { + return ( + + ); + })} +
+ )} +
+ ); +}; + +export default LinkListByFolderId; diff --git a/components/folderPage/modal/AddFolderModal/AddFolderModal.tsx b/components/folderPage/modal/AddFolderModal/AddFolderModal.tsx index e6fe3c8b7..27a94b79d 100644 --- a/components/folderPage/modal/AddFolderModal/AddFolderModal.tsx +++ b/components/folderPage/modal/AddFolderModal/AddFolderModal.tsx @@ -1,18 +1,41 @@ import styles from "./AddFolderModal.module.css"; import ModalButton from "../ModalButton/ModalButton"; import ModalWrapper from "../ModalWrapper/ModalWrapper"; +import { useState } from "react"; +import { useMutation, useQueryClient } from "@tanstack/react-query"; +import { addFolder } from "@/api/folders"; const AddFolderModal = ({ handleAddFolderModalClick, }: { handleAddFolderModalClick: (e: React.MouseEvent) => void; }) => { + const queryClient = useQueryClient(); + const [addFolderName, setAddFolderName] = useState(); + const addFolderByName = useMutation({ + mutationFn: addFolder, + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ["folders"] }); + }, + }); + const onChangeFolderNameInput = (e) => { + setAddFolderName(e.target.value); + }; + const handleAddModalClick = () => { + addFolderByName.mutate(addFolderName, {}); + handleAddFolderModalClick(); + }; return (
폴더 추가
- +
- 추가하기 + + 추가하기 +
); diff --git a/components/folderPage/modal/ModalButton/ModalButton.tsx b/components/folderPage/modal/ModalButton/ModalButton.tsx index 5e285200e..5fe76b00b 100644 --- a/components/folderPage/modal/ModalButton/ModalButton.tsx +++ b/components/folderPage/modal/ModalButton/ModalButton.tsx @@ -1,5 +1,12 @@ -import styles from './ModalButton.module.css'; -import { childrenProps } from '../ModalWrapper/ModalWrapper'; -export default function ModalButton({ children } : childrenProps) { - return ; +import styles from "./ModalButton.module.css"; +import { childrenProps } from "../ModalWrapper/ModalWrapper"; +export default function ModalButton({ + children, + handleAddModalClick, +}: childrenProps) { + return ( + + ); } diff --git a/components/sharedPage/SharePageFolderList/SharePageFolderList.module.css b/components/sharedPage/SharePageFolderList/SharePageLinkList.module.css similarity index 100% rename from components/sharedPage/SharePageFolderList/SharePageFolderList.module.css rename to components/sharedPage/SharePageFolderList/SharePageLinkList.module.css diff --git a/components/sharedPage/SharePageFolderList/SharePageFolderList.tsx b/components/sharedPage/SharePageFolderList/SharePageLinkList.tsx similarity index 90% rename from components/sharedPage/SharePageFolderList/SharePageFolderList.tsx rename to components/sharedPage/SharePageFolderList/SharePageLinkList.tsx index a4bdb87db..166c67692 100644 --- a/components/sharedPage/SharePageFolderList/SharePageFolderList.tsx +++ b/components/sharedPage/SharePageFolderList/SharePageLinkList.tsx @@ -1,4 +1,3 @@ -import styles from "./SharePageFolderList.module.css"; import { getSharedPageFolderData } from "@/api/sharedPageFolderData"; import SharePageFolderItem from "../SharPageFolderItem/SharePageFolderItem"; diff --git a/components/sharedPage/SharedPageMain/SharedPageMain.tsx b/components/sharedPage/SharedPageMain/SharedPageMain.tsx index 6b437d3d0..cfecc10d9 100644 --- a/components/sharedPage/SharedPageMain/SharedPageMain.tsx +++ b/components/sharedPage/SharedPageMain/SharedPageMain.tsx @@ -1,6 +1,6 @@ import styles from "./SharedPageMain.module.css"; import LinkSearchInput from "@/components/common/LinkSearchInput/LinkSearchInput"; -import SharePageFolderList from "../SharePageFolderList/SharePageFolderList"; +import SharePageFolderList from "../SharePageFolderList/SharePageLinkList"; const SharedPageMain = () => { return ( diff --git a/components/signInPage/SignInForm/SignInForm.tsx b/components/signInPage/SignInForm/SignInForm.tsx index 8771233db..1a50775dc 100644 --- a/components/signInPage/SignInForm/SignInForm.tsx +++ b/components/signInPage/SignInForm/SignInForm.tsx @@ -52,7 +52,6 @@ const SignInForm = () => { return; } const json = await response.json(); - console.log(json); const accessToken = json.accessToken; localStorage.setItem("accessToken", accessToken); router.push("/folder"); From 757f0251b67efe50028a276d7b34e297df0bb906 Mon Sep 17 00:00:00 2001 From: hoj0806 <90647684+hoj0806@users.noreply.github.com> Date: Mon, 13 May 2024 18:02:18 +0900 Subject: [PATCH 04/14] =?UTF-8?q?feat=20:=20=ED=8F=B4=EB=8D=94=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80=20=EB=B0=8F?= =?UTF-8?q?=20=ED=8F=B4=EB=8D=94=20=EC=82=AD=EC=A0=9C=EC=8B=9C=20/folder?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B4=EB=8F=99,=20=ED=8F=B4=EB=8D=94=20?= =?UTF-8?q?=EC=BF=BC=EB=A6=AC=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=B5=9C?= =?UTF-8?q?=EC=8B=A0=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/folders.ts | 18 +++++++++++++++ .../FolderPageMain/FolderPageMain.tsx | 1 + .../modal/DeleteButton/DeleteButton.tsx | 15 +++++++++---- .../DeleteFolderModal/DeleteFolderModal.tsx | 22 +++++++++++++++++-- 4 files changed, 50 insertions(+), 6 deletions(-) diff --git a/api/folders.ts b/api/folders.ts index c489a6085..43274a06f 100644 --- a/api/folders.ts +++ b/api/folders.ts @@ -40,4 +40,22 @@ export const addFolder = async (folderName: string) => { throw error; } }; + +export const deleteFolder = async (folderId: number) => { + const accessToken = localStorage.getItem("accessToken"); + + try { + const response = await instance.delete( + `https://bootcamp-api.codeit.kr/api/linkbrary/v1/folders/${folderId}`, + { + headers: { + Authorization: `Bearer ${accessToken}`, + }, + } + ); + } catch (error) { + console.error("error"); + throw error; + } +}; axios.defaults.withCredentials = true; diff --git a/components/folderPage/FolderPageMain/FolderPageMain.tsx b/components/folderPage/FolderPageMain/FolderPageMain.tsx index 77c2247c5..5c5d89bb6 100644 --- a/components/folderPage/FolderPageMain/FolderPageMain.tsx +++ b/components/folderPage/FolderPageMain/FolderPageMain.tsx @@ -165,6 +165,7 @@ const FolderPageMain = ({ )} {isShowAddFolderModal && ( diff --git a/components/folderPage/modal/DeleteButton/DeleteButton.tsx b/components/folderPage/modal/DeleteButton/DeleteButton.tsx index b12fc247b..f39f79568 100644 --- a/components/folderPage/modal/DeleteButton/DeleteButton.tsx +++ b/components/folderPage/modal/DeleteButton/DeleteButton.tsx @@ -1,5 +1,12 @@ -import styles from './DeleteButton.module.css'; -import { childrenProps } from '../ModalWrapper/ModalWrapper'; -export default function DeleteModalButton({ children }: childrenProps) { - return ; +import styles from "./DeleteButton.module.css"; +import { childrenProps } from "../ModalWrapper/ModalWrapper"; +export default function DeleteModalButton({ + children, + handleDeleteButton, +}: childrenProps) { + return ( + + ); } diff --git a/components/folderPage/modal/DeleteFolderModal/DeleteFolderModal.tsx b/components/folderPage/modal/DeleteFolderModal/DeleteFolderModal.tsx index 6855970c2..3c0b0be96 100644 --- a/components/folderPage/modal/DeleteFolderModal/DeleteFolderModal.tsx +++ b/components/folderPage/modal/DeleteFolderModal/DeleteFolderModal.tsx @@ -1,7 +1,9 @@ import styles from "./DeleteFolderModal.module.css"; import ModalWrapper from "../ModalWrapper/ModalWrapper"; import DeleteModalButton from "../DeleteButton/DeleteButton"; - +import { useMutation, useQueryClient } from "@tanstack/react-query"; +import { deleteFolder } from "@/api/folders"; +import { useRouter } from "next/navigation"; interface DeleteFolderModalProps { FolderModalValue: string; handleDeleteFolderModalClick: (e: React.MouseEvent) => void; @@ -9,7 +11,21 @@ interface DeleteFolderModalProps { const DeleteFolderModal = ({ FolderModalValue, handleDeleteFolderModalClick, + folderId, }: DeleteFolderModalProps) => { + const queryClient = useQueryClient(); + const router = useRouter(); + const deleteFolderById = useMutation({ + mutationFn: deleteFolder, + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ["folders"] }); + router.push("/folder"); + }, + }); + const handleDeleteButton = () => { + deleteFolderById.mutate(folderId.slice(10, folderId.length)); + handleDeleteFolderModalClick(); + }; return (
@@ -23,7 +39,9 @@ const DeleteFolderModal = ({ onClick={handleDeleteFolderModalClick} />
- 삭제하기 + + 삭제하기 +
); From 63e8b7d5cd59881c691cf2bdaf006845d7e2d210 Mon Sep 17 00:00:00 2001 From: hoj0806 <90647684+hoj0806@users.noreply.github.com> Date: Mon, 13 May 2024 19:56:58 +0900 Subject: [PATCH 05/14] =?UTF-8?q?feat=20:=20=EB=A7=81=ED=81=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=EA=B8=B0=EB=8A=A5=20=EC=99=84=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/links.ts | 23 +++++++++ app/(FolderPage)/folder/[folderId]/page.tsx | 1 + app/(SharedPage)/shared/[folderId]/page.tsx | 9 +++- components/common/Navigation/Navigation.tsx | 4 +- .../FolderFilterBox/FolderFilterBox.tsx | 6 ++- .../FolderPageMain/FolderPageMain.tsx | 25 +--------- .../AddLinkInFolder.module.css | 8 +++ .../modal/AddLinkInFolder/AddLinkInFolder.tsx | 49 ++++++++++++++++--- .../DeleteFolderModal/DeleteFolderModal.tsx | 1 + .../modal/ModalButton/ModalButton.tsx | 5 +- .../SharePageFolderList/SharePageLinkList.tsx | 21 +++++--- .../SharedPageMain/SharedPageMain.tsx | 4 +- 12 files changed, 108 insertions(+), 48 deletions(-) diff --git a/api/links.ts b/api/links.ts index fba2f6c36..b172dde9f 100644 --- a/api/links.ts +++ b/api/links.ts @@ -21,4 +21,27 @@ export const getLinksByFolderId = async (folderId: string) => { } }; +export const addLinkInFolder = async (url: string, folderId: number) => { + const accessToken = localStorage.getItem("accessToken"); + + try { + const response = await instance.post( + "https://bootcamp-api.codeit.kr/api/linkbrary/v1/links", + { + url: url, + folderId: folderId, + }, + { + headers: { + Authorization: `Bearer ${accessToken}`, + }, + } + ); + return response.data; + } catch (error) { + console.error("error"); + throw error; + } +}; + axios.defaults.withCredentials = true; diff --git a/app/(FolderPage)/folder/[folderId]/page.tsx b/app/(FolderPage)/folder/[folderId]/page.tsx index b64986bbe..09a14b7ea 100644 --- a/app/(FolderPage)/folder/[folderId]/page.tsx +++ b/app/(FolderPage)/folder/[folderId]/page.tsx @@ -12,6 +12,7 @@ import { HydrationBoundary, QueryClient, } from "@tanstack/react-query"; +import AddLinkInFolder from "@/components/folderPage/modal/AddLinkInFolder/AddLinkInFolder"; const FolderPage = () => { const queryClient = new QueryClient(); useEffect(() => { diff --git a/app/(SharedPage)/shared/[folderId]/page.tsx b/app/(SharedPage)/shared/[folderId]/page.tsx index fb1a42a33..630a5e949 100644 --- a/app/(SharedPage)/shared/[folderId]/page.tsx +++ b/app/(SharedPage)/shared/[folderId]/page.tsx @@ -6,8 +6,13 @@ export const metadata = { title: "Shared", }; -const SharedPage = async ({ params }: { folderId: number }) => { - return
{params.folderId}
; +const SharedPage = async ({ params }: { folderId: string }) => { + return ( + + + + + ); }; export default SharedPage; diff --git a/components/common/Navigation/Navigation.tsx b/components/common/Navigation/Navigation.tsx index f7e7fcb80..595007992 100644 --- a/components/common/Navigation/Navigation.tsx +++ b/components/common/Navigation/Navigation.tsx @@ -3,9 +3,7 @@ import { getUserData } from "@/api/userData"; import NavLoginButton from "../NavLoginButton/NavLoginButton"; import Link from "next/link"; import Image from "next/image"; -const Navigation = async () => { - const userData = await getUserData(); - +const Navigation = () => { return (
diff --git a/components/folderPage/FolderFilterBox/FolderFilterBox.tsx b/components/folderPage/FolderFilterBox/FolderFilterBox.tsx index 2aa2e3f47..b81491368 100644 --- a/components/folderPage/FolderFilterBox/FolderFilterBox.tsx +++ b/components/folderPage/FolderFilterBox/FolderFilterBox.tsx @@ -1,4 +1,4 @@ -import { SetStateAction, useState, Dispatch } from "react"; +import { SetStateAction, useState, Dispatch, useEffect } from "react"; import styles from "./FolderFilterBox.module.css"; import FolderFilterButton from "../FolderFilterButton/FolderFilterButton"; import ShowAllLinksButton from "../ShowAllLinkButton/ShowAllLinkButton"; @@ -22,8 +22,9 @@ const FolderFilterBox = ({ setIsShowFuncButtonBox, setFolderModalValue, setShareUrlFolderId, + params, }: FolderFilterBoxProps) => { - const [activeFilterId, setActiveFilterId] = useState("showAll"); + const [activeFilterId, setActiveFilterId] = useState(""); const { data, isLoading, error } = useQuery({ queryKey: ["folders"], @@ -35,6 +36,7 @@ const FolderFilterBox = ({ } if (error) return
{error.message}
; + const handleClickFilterButton = (folderName: string, folderId: number) => { setIsShowFuncButtonBox(true); setFolderName(folderName); diff --git a/components/folderPage/FolderPageMain/FolderPageMain.tsx b/components/folderPage/FolderPageMain/FolderPageMain.tsx index 5c5d89bb6..ac2c239d0 100644 --- a/components/folderPage/FolderPageMain/FolderPageMain.tsx +++ b/components/folderPage/FolderPageMain/FolderPageMain.tsx @@ -1,7 +1,7 @@ "use client"; import styles from "./FolderPageMain.module.css"; import LinkListByFolderId from "../LinkListByFolderId/LinkListByFolderId"; -import { Dispatch, SetStateAction, useState, useEffect } from "react"; +import { Dispatch, SetStateAction, useState } from "react"; import LinkSearchInput from "@/components/common/LinkSearchInput/LinkSearchInput"; import useModal from "@/hooks/useModal"; import { LinkDataType } from "@/types/LinkDataTypes"; @@ -50,29 +50,6 @@ const FolderPageMain = ({ const [folderId, setFolderId] = useState(""); const [folderData, setFolderData] = useState(null); - const getLinkData = async () => { - const response = await fetch( - `https://bootcamp-api.codeit.kr/api/users/3/links${folderId}` - ); - const json: LinkDataType = await response.json(); - setLinkData(json); - }; - - const getFolderData = async () => { - const response = await fetch( - "https://bootcamp-api.codeit.kr/api/users/3/folders" - ); - const json: FolderDataType = await response.json(); - setFolderData(json); - }; - - useEffect(() => { - getLinkData(); - }, [folderId]); - - useEffect(() => { - getFolderData(); - }, []); const [folderName, setFolderName] = useState(""); const [isShowFuncButtonBox, setIsShowFuncButtonBox] = useState(false); diff --git a/components/folderPage/modal/AddLinkInFolder/AddLinkInFolder.module.css b/components/folderPage/modal/AddLinkInFolder/AddLinkInFolder.module.css index 327aed0e7..8343a2d38 100644 --- a/components/folderPage/modal/AddLinkInFolder/AddLinkInFolder.module.css +++ b/components/folderPage/modal/AddLinkInFolder/AddLinkInFolder.module.css @@ -89,6 +89,14 @@ align-items: center; } +.list-item-wrapper-active { + display: flex; + gap: 0.8rem; + background: var(--Linkbrary-bg, #f0f6ff); + border-radius: 0.8rem; + align-items: center; +} + .link-count { color: #9fa6b2; font-family: var(--Pretendard-Regular); diff --git a/components/folderPage/modal/AddLinkInFolder/AddLinkInFolder.tsx b/components/folderPage/modal/AddLinkInFolder/AddLinkInFolder.tsx index 223269e42..8fc7298f7 100644 --- a/components/folderPage/modal/AddLinkInFolder/AddLinkInFolder.tsx +++ b/components/folderPage/modal/AddLinkInFolder/AddLinkInFolder.tsx @@ -2,6 +2,10 @@ import styles from "./AddLinkInFolder.module.css"; import ModalButton from "../ModalButton/ModalButton"; import ModalWrapper from "../ModalWrapper/ModalWrapper"; import { FolderDataType } from "@/types/FolderDataTypes"; +import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; +import { getAllFolders } from "@/api/folders"; +import { useState } from "react"; +import { addLinkInFolder } from "@/api/links"; interface isShowAddLinkInFolderProps { handleAddLinkInFolderModalClick: ( e: React.MouseEvent @@ -9,12 +13,33 @@ interface isShowAddLinkInFolderProps { folderData: FolderDataType | null; sharedUrl: string; } - const AddLinkInFolder = ({ handleAddLinkInFolderModalClick, - folderData, + sharedUrl, }: isShowAddLinkInFolderProps) => { + const { data } = useQuery({ + queryKey: ["folders"], + queryFn: getAllFolders, + }); + const queryClient = useQueryClient(); + const [selectFolder, setSelectFolder] = useState(""); + const [selectFolderId, setSelectFolderId] = useState(); + + const addLink = useMutation({ + mutationFn: ([url, folderId]: [string, number]) => + addLinkInFolder(url, folderId), + + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ["links"] }); + }, + }); + + console.log(selectFolderId); + const handleAddButton = () => { + addLink.mutate([sharedUrl, selectFolderId]); + handleAddLinkInFolderModalClick(); + }; return (
@@ -29,22 +54,32 @@ const AddLinkInFolder = ({ />
    - {folderData?.data.map(({ name, link }, i) => { + {data.map(({ name, link_count, id }, i) => { return ( -
  • +
  • { + setSelectFolderId(id); + }} + >

    {name}

    - {link.count === 0 ? ( + {data.count === 0 ? (

    링크가 없습니다
    ) : ( -
    {`${link.count}개 링크`}
    +
    {`${link_count}개 링크`}
    )}

  • ); })}
- 추가하기 + 추가하기
); diff --git a/components/folderPage/modal/DeleteFolderModal/DeleteFolderModal.tsx b/components/folderPage/modal/DeleteFolderModal/DeleteFolderModal.tsx index 3c0b0be96..470f42dbe 100644 --- a/components/folderPage/modal/DeleteFolderModal/DeleteFolderModal.tsx +++ b/components/folderPage/modal/DeleteFolderModal/DeleteFolderModal.tsx @@ -15,6 +15,7 @@ const DeleteFolderModal = ({ }: DeleteFolderModalProps) => { const queryClient = useQueryClient(); const router = useRouter(); + const deleteFolderById = useMutation({ mutationFn: deleteFolder, onSuccess: () => { diff --git a/components/folderPage/modal/ModalButton/ModalButton.tsx b/components/folderPage/modal/ModalButton/ModalButton.tsx index 5fe76b00b..6ae95f700 100644 --- a/components/folderPage/modal/ModalButton/ModalButton.tsx +++ b/components/folderPage/modal/ModalButton/ModalButton.tsx @@ -2,10 +2,11 @@ import styles from "./ModalButton.module.css"; import { childrenProps } from "../ModalWrapper/ModalWrapper"; export default function ModalButton({ children, - handleAddModalClick, + + handleAddButton, }: childrenProps) { return ( - ); diff --git a/components/sharedPage/SharePageFolderList/SharePageLinkList.tsx b/components/sharedPage/SharePageFolderList/SharePageLinkList.tsx index 166c67692..6417c2520 100644 --- a/components/sharedPage/SharePageFolderList/SharePageLinkList.tsx +++ b/components/sharedPage/SharePageFolderList/SharePageLinkList.tsx @@ -1,17 +1,26 @@ -import { getSharedPageFolderData } from "@/api/sharedPageFolderData"; -import SharePageFolderItem from "../SharPageFolderItem/SharePageFolderItem"; +"use client"; -const SharePageFolderList = async () => { - const folderData = await getSharedPageFolderData(); +import styles from "./SharePageLinkList.module.css"; +import { useQuery } from "@tanstack/react-query"; +import { getLinksByFolderId } from "@/api/links"; +const SharePageFolderList = ({ params }) => { + console.log(params); + + const { data } = useQuery({ + queryKey: ["shared"], + queryFn: () => getLinksByFolderId(params.folderId), + }); + + console.log(data); return (
- {folderData?.folder.links.map((data) => ( + {/* {folderData?.folder.links.map((data) => ( - ))} + ))} */}
); }; diff --git a/components/sharedPage/SharedPageMain/SharedPageMain.tsx b/components/sharedPage/SharedPageMain/SharedPageMain.tsx index cfecc10d9..cceb4e4a3 100644 --- a/components/sharedPage/SharedPageMain/SharedPageMain.tsx +++ b/components/sharedPage/SharedPageMain/SharedPageMain.tsx @@ -2,12 +2,12 @@ import styles from "./SharedPageMain.module.css"; import LinkSearchInput from "@/components/common/LinkSearchInput/LinkSearchInput"; import SharePageFolderList from "../SharePageFolderList/SharePageLinkList"; -const SharedPageMain = () => { +const SharedPageMain = ({ params }) => { return (
{/* */} - +
); }; From 68f9e1a337e5cd6909187f840200e0fb91c568db Mon Sep 17 00:00:00 2001 From: hoj0806 <90647684+hoj0806@users.noreply.github.com> Date: Mon, 13 May 2024 20:27:36 +0900 Subject: [PATCH 06/14] =?UTF-8?q?feat=20:=20=EB=A7=81=ED=81=AC=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/links.ts | 18 ++++++++ app/(FolderPage)/folder/[folderId]/page.tsx | 12 +----- app/(FolderPage)/folder/page.tsx | 10 ----- .../FolderFilterBox/FolderFilterBox.tsx | 7 +--- .../FolderPageLinkItem/FolderPageLinkItem.tsx | 3 ++ .../FolderPageMain/FolderPageMain.tsx | 10 +---- .../LinkListByFolderId/LinkListByFolderId.tsx | 7 +++- .../modal/DeleteLinkModal/DeleteLinkModal.tsx | 42 ++++++++++++++----- 8 files changed, 63 insertions(+), 46 deletions(-) diff --git a/api/links.ts b/api/links.ts index b172dde9f..91cd078a3 100644 --- a/api/links.ts +++ b/api/links.ts @@ -44,4 +44,22 @@ export const addLinkInFolder = async (url: string, folderId: number) => { } }; +export const deleteLink = async (linkId: number) => { + const accessToken = localStorage.getItem("accessToken"); + + try { + const response = await instance.delete( + `https://bootcamp-api.codeit.kr/api/linkbrary/v1/links/${linkId}`, + { + headers: { + Authorization: `Bearer ${accessToken}`, + }, + } + ); + return response.data; + } catch (error) { + console.error("error"); + throw error; + } +}; axios.defaults.withCredentials = true; diff --git a/app/(FolderPage)/folder/[folderId]/page.tsx b/app/(FolderPage)/folder/[folderId]/page.tsx index 09a14b7ea..9493d3dfe 100644 --- a/app/(FolderPage)/folder/[folderId]/page.tsx +++ b/app/(FolderPage)/folder/[folderId]/page.tsx @@ -13,18 +13,9 @@ import { QueryClient, } from "@tanstack/react-query"; import AddLinkInFolder from "@/components/folderPage/modal/AddLinkInFolder/AddLinkInFolder"; -const FolderPage = () => { +const FolderPage = ({ params }: { folderId: string }) => { const queryClient = new QueryClient(); - useEffect(() => { - const fetchLinks = async () => { - await queryClient.prefetchQuery({ - queryKey: ["links"], - queryFn: getAllLinks, - }); - }; - fetchLinks(); - }, []); const { isShowModal: isShowAddLinkInFolderModal, handleModalClick: handleAddLinkInFolderModalClick, @@ -46,6 +37,7 @@ const FolderPage = () => { handleAddLinkInFolderModalClick={handleAddLinkInFolderModalClick} sharedUrl={sharedUrl} setSharedUrl={setSharedUrl} + params={params} /> diff --git a/app/(FolderPage)/folder/page.tsx b/app/(FolderPage)/folder/page.tsx index e01685f58..ca8d833e3 100644 --- a/app/(FolderPage)/folder/page.tsx +++ b/app/(FolderPage)/folder/page.tsx @@ -16,16 +16,6 @@ import { export const queryClient = new QueryClient(); const FolderPage = () => { - useEffect(() => { - const fetchLinks = async () => { - await queryClient.prefetchQuery({ - queryKey: ["links"], - queryFn: getAllLinks, - }); - }; - - fetchLinks(); - }, []); const { isShowModal: isShowAddLinkInFolderModal, handleModalClick: handleAddLinkInFolderModalClick, diff --git a/components/folderPage/FolderFilterBox/FolderFilterBox.tsx b/components/folderPage/FolderFilterBox/FolderFilterBox.tsx index b81491368..b82955e7b 100644 --- a/components/folderPage/FolderFilterBox/FolderFilterBox.tsx +++ b/components/folderPage/FolderFilterBox/FolderFilterBox.tsx @@ -65,12 +65,7 @@ const FolderFilterBox = ({ {data.map(({ name, id }) => { return ( - handleClickFilterButton(name, id)} - /> +
{name}
); })} diff --git a/components/folderPage/FolderPageLinkItem/FolderPageLinkItem.tsx b/components/folderPage/FolderPageLinkItem/FolderPageLinkItem.tsx index 9de5c0a42..3f6cfc321 100644 --- a/components/folderPage/FolderPageLinkItem/FolderPageLinkItem.tsx +++ b/components/folderPage/FolderPageLinkItem/FolderPageLinkItem.tsx @@ -14,6 +14,7 @@ interface FoldrPageLinkItemProps { ) => void; setSharedUrl: Dispatch>; date: string; + linkId: number; } const FolderPageLinkItem = ({ @@ -24,6 +25,7 @@ const FolderPageLinkItem = ({ handleAddLinkInFolderModalClick, setSharedUrl, date, + linkId, }: FoldrPageLinkItemProps) => { const { isShowModal: isShowKebabModal, @@ -87,6 +89,7 @@ const FolderPageLinkItem = ({ )} diff --git a/components/folderPage/FolderPageMain/FolderPageMain.tsx b/components/folderPage/FolderPageMain/FolderPageMain.tsx index ac2c239d0..169c62788 100644 --- a/components/folderPage/FolderPageMain/FolderPageMain.tsx +++ b/components/folderPage/FolderPageMain/FolderPageMain.tsx @@ -18,7 +18,6 @@ import ShowSearchData from "../ShowSearchData/ShowSearchData"; import { useQuery } from "@tanstack/react-query"; import { getAllLinks } from "@/api/folder"; import { getUserInfo } from "@/api/user"; - interface FolderPageMainProps { isShowAddLinkInFolderModal: boolean; handleAddLinkInFolderModalClick: ( @@ -33,19 +32,13 @@ const FolderPageMain = ({ handleAddLinkInFolderModalClick, sharedUrl, setSharedUrl, + params, }: FolderPageMainProps) => { - const { data } = useQuery({ - queryKey: ["links"], - queryFn: getAllLinks, - }); - const { data: userData } = useQuery({ queryKey: ["user"], queryFn: getUserInfo, }); - console.log(data); - const [linkData, setLinkData] = useState(null); const [folderId, setFolderId] = useState(""); @@ -122,6 +115,7 @@ const FolderPageMain = ({ handleAddLinkInFolderModalClick={handleAddLinkInFolderModalClick} setSharedUrl={setSharedUrl} linkData={linkData} + params={params} />
diff --git a/components/folderPage/LinkListByFolderId/LinkListByFolderId.tsx b/components/folderPage/LinkListByFolderId/LinkListByFolderId.tsx index a16721cbd..c069ef345 100644 --- a/components/folderPage/LinkListByFolderId/LinkListByFolderId.tsx +++ b/components/folderPage/LinkListByFolderId/LinkListByFolderId.tsx @@ -1,5 +1,5 @@ import styles from "./LinkListByFolderId.module.css"; -import { Dispatch, SetStateAction } from "react"; +import { Dispatch, SetStateAction, useEffect, useState } from "react"; import { LinkDataType } from "@/types/LinkDataTypes"; import FolderPageLinkItem from "../FolderPageLinkItem/FolderPageLinkItem"; import { useQuery } from "@tanstack/react-query"; @@ -11,6 +11,7 @@ interface LinkListProps { ) => void; setSharedUrl: Dispatch>; linkData: LinkDataType | null; + params: { folderId: string }; } const LinkListByFolderId = ({ @@ -23,9 +24,12 @@ const LinkListByFolderId = ({ queryKey: ["links"], queryFn: () => getLinksByFolderId(params.folderId), }); + const [paramsId, setParamsId] = useState(); + console.log(paramsId); if (isLoading) return
Loading...
; if (error) return
Error: {error.message}
; + console.log(data); return (
@@ -43,6 +47,7 @@ const LinkListByFolderId = ({ setSharedUrl={setSharedUrl} date={item.created_at.slice(0, 10)} key={item.id} + linkId={item.id} /> ); })} diff --git a/components/folderPage/modal/DeleteLinkModal/DeleteLinkModal.tsx b/components/folderPage/modal/DeleteLinkModal/DeleteLinkModal.tsx index 55cb92955..adb8ae691 100644 --- a/components/folderPage/modal/DeleteLinkModal/DeleteLinkModal.tsx +++ b/components/folderPage/modal/DeleteLinkModal/DeleteLinkModal.tsx @@ -1,31 +1,51 @@ -import ModalWrapper from '../ModalWrapper/ModalWrapper'; -import DeleteModalButton from '../DeleteButton/DeleteButton'; -import styles from './DeleteLinkModal.module.css'; - +import ModalWrapper from "../ModalWrapper/ModalWrapper"; +import DeleteModalButton from "../DeleteButton/DeleteButton"; +import styles from "./DeleteLinkModal.module.css"; +import { useMutation } from "@tanstack/react-query"; +import { deleteLink } from "@/api/links"; +import { useQueryClient } from "@tanstack/react-query"; interface DeleteLinkModalProps { url: string; handleDeleteLinkModalClick: React.MouseEventHandler; + linkId: number; } export default function DeleteLinkModal({ handleDeleteLinkModalClick, url, + linkId, }: DeleteLinkModalProps) { + const queryClient = useQueryClient(); + + const deleteLinks = useMutation({ + mutationFn: ([linkId]: [number]) => deleteLink(linkId), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ["links"] }); + }, + }); + + const handleDeleteButton = () => { + deleteLinks.mutate([linkId]); + handleDeleteLinkModalClick(); + }; + return ( -
-
-
링크 삭제
-
{url}
- +
+
+
링크 삭제
+
{url}
+ {linkId} modal-close-icon
- 삭제하기 + + 삭제하기 +
); From 440117cf92ebde66e625c4dae7a2524daf55ba2e Mon Sep 17 00:00:00 2001 From: hoj0806 <90647684+hoj0806@users.noreply.github.com> Date: Mon, 13 May 2024 20:48:07 +0900 Subject: [PATCH 07/14] =?UTF-8?q?refactor=20:=20=EC=9D=B4=EB=A9=94?= =?UTF-8?q?=EC=9D=BC=20=EC=A4=91=EB=B3=B5=20=EC=B2=B4=ED=81=AC=20url=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/signupPage/SignupForm.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/signupPage/SignupForm.tsx b/components/signupPage/SignupForm.tsx index 23ce0f17b..f04a9765d 100644 --- a/components/signupPage/SignupForm.tsx +++ b/components/signupPage/SignupForm.tsx @@ -45,7 +45,7 @@ const SignUpForm = () => { ): Promise => { try { const response = await fetch( - "https://bootcamp-api.codeit.kr/api/check-email", + "https://bootcamp-api.codeit.kr/api/linkbrary/v1/users/check-email", { method: "POST", headers: { From a2eae1b2ca0720da20dc362ce97903905ac274b7 Mon Sep 17 00:00:00 2001 From: hoj0806 <90647684+hoj0806@users.noreply.github.com> Date: Mon, 13 May 2024 20:53:59 +0900 Subject: [PATCH 08/14] =?UTF-8?q?refactor=20:=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EA=B0=80=EC=9E=85=20url=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/folderPage/modal/ModalButton/ModalButton.tsx | 4 ++-- components/signupPage/SignupForm.tsx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/folderPage/modal/ModalButton/ModalButton.tsx b/components/folderPage/modal/ModalButton/ModalButton.tsx index 6ae95f700..067135db6 100644 --- a/components/folderPage/modal/ModalButton/ModalButton.tsx +++ b/components/folderPage/modal/ModalButton/ModalButton.tsx @@ -3,10 +3,10 @@ import { childrenProps } from "../ModalWrapper/ModalWrapper"; export default function ModalButton({ children, - handleAddButton, + handleAddModalClick, }: childrenProps) { return ( - ); diff --git a/components/signupPage/SignupForm.tsx b/components/signupPage/SignupForm.tsx index f04a9765d..ce96350b2 100644 --- a/components/signupPage/SignupForm.tsx +++ b/components/signupPage/SignupForm.tsx @@ -68,7 +68,7 @@ const SignUpForm = () => { const onSignUp = async (data: FormValueType) => { try { const response = await fetch( - "https://bootcamp-api.codeit.kr/api/sign-up", + "https://bootcamp-api.codeit.kr/api/linkbrary/v1/auth/sign-up", { method: "POST", headers: { @@ -82,7 +82,7 @@ const SignUpForm = () => { } ); const json = await response.json(); - const accessToken = json.data.accessToken; + const accessToken = json.accessToken; if (response.ok) { localStorage.setItem("accessToken", accessToken); router.push("folder"); From ee86a7fdbfe36669c8f2619b8f8304cdde86aa32 Mon Sep 17 00:00:00 2001 From: hoj0806 <90647684+hoj0806@users.noreply.github.com> Date: Mon, 13 May 2024 23:01:39 +0900 Subject: [PATCH 09/14] =?UTF-8?q?feat=20:=20=ED=8F=B4=EB=8D=94=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EB=B3=80=EA=B2=BD=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/folders.ts | 21 ++++++++++ api/links.ts | 24 +++++++++++ .../FolderFilterBox/FolderFilterBox.tsx | 19 ++++----- .../FolderPageLinkItem/FolderPageLinkItem.tsx | 42 ++++++++++++++++--- .../FolderPageLinkitem.module.css | 1 + .../FolderPageMain/FolderPageMain.tsx | 35 +++++++++++----- .../LinkListByFolderId/LinkListByFolderId.tsx | 22 +++++----- .../ShowAllLinkButton/ShowAllLinkButton.tsx | 15 +++---- .../modal/AddFolderModal/AddFolderModal.tsx | 6 +-- .../modal/AddLinkInFolder/AddLinkInFolder.tsx | 9 +++- .../DeleteFolderModal/DeleteFolderModal.tsx | 6 ++- .../modal/ModalButton/ModalButton.tsx | 4 +- .../RenameFolderNameModal.tsx | 32 ++++++++++++-- public/assets/images/favortie_link.svg | 10 +++++ 14 files changed, 186 insertions(+), 60 deletions(-) create mode 100644 public/assets/images/favortie_link.svg diff --git a/api/folders.ts b/api/folders.ts index 43274a06f..d03b8bec2 100644 --- a/api/folders.ts +++ b/api/folders.ts @@ -58,4 +58,25 @@ export const deleteFolder = async (folderId: number) => { throw error; } }; + +export const renameFolder = async (folderName: string, folderId: number) => { + const accessToken = localStorage.getItem("accessToken"); + + try { + const response = await instance.put( + `https://bootcamp-api.codeit.kr/api/linkbrary/v1/folders/${folderId}`, + { + name: folderName, + }, + { + headers: { + Authorization: `Bearer ${accessToken}`, + }, + } + ); + } catch (error) { + console.error("error"); + throw error; + } +}; axios.defaults.withCredentials = true; diff --git a/api/links.ts b/api/links.ts index 91cd078a3..20d7c242f 100644 --- a/api/links.ts +++ b/api/links.ts @@ -62,4 +62,28 @@ export const deleteLink = async (linkId: number) => { throw error; } }; + +export const favoriteLink = async ( + linkId: number, + favortieBoolean: boolean +) => { + const accessToken = localStorage.getItem("accessToken"); + + try { + const response = await instance.put( + `https://bootcamp-api.codeit.kr/api/linkbrary/v1/links/${linkId}`, + { + favorite: favortieBoolean, + }, + { + headers: { + Authorization: `Bearer ${accessToken}`, + }, + } + ); + return response.data; + } catch (error) { + console.error("error"); + } +}; axios.defaults.withCredentials = true; diff --git a/components/folderPage/FolderFilterBox/FolderFilterBox.tsx b/components/folderPage/FolderFilterBox/FolderFilterBox.tsx index b82955e7b..3ee1f28f3 100644 --- a/components/folderPage/FolderFilterBox/FolderFilterBox.tsx +++ b/components/folderPage/FolderFilterBox/FolderFilterBox.tsx @@ -16,9 +16,6 @@ interface FolderFilterBoxProps { } const FolderFilterBox = ({ - folderData, - setFolderName, - setFolderId, setIsShowFuncButtonBox, setFolderModalValue, setShareUrlFolderId, @@ -39,33 +36,35 @@ const FolderFilterBox = ({ const handleClickFilterButton = (folderName: string, folderId: number) => { setIsShowFuncButtonBox(true); - setFolderName(folderName); - setFolderId("?folderId=" + String(folderId)); setActiveFilterId(folderId.toString()); setFolderModalValue(folderName); setShareUrlFolderId(folderId.toString()); }; const handleClickShowAllLinksButton = () => { - setFolderName("전체"); setIsShowFuncButtonBox(false); - setFolderId(""); + setActiveFilterId("showAll"); }; return (
handleClickShowAllLinksButton()} /> - {data.map(({ name, id }) => { + {data.map(({ name, id }, index) => { return ( -
{name}
+ handleClickFilterButton(name, id)} + /> ); })} diff --git a/components/folderPage/FolderPageLinkItem/FolderPageLinkItem.tsx b/components/folderPage/FolderPageLinkItem/FolderPageLinkItem.tsx index 3f6cfc321..b03c13fcd 100644 --- a/components/folderPage/FolderPageLinkItem/FolderPageLinkItem.tsx +++ b/components/folderPage/FolderPageLinkItem/FolderPageLinkItem.tsx @@ -3,7 +3,9 @@ import * as functions from "@/functions/formatTimeAgo"; import KebabModal from "../modal/KebabModal/KebabModal"; import useModal from "@/hooks/useModal"; import DeleteLinkModal from "../modal/DeleteLinkModal/DeleteLinkModal"; -import { Dispatch, SetStateAction } from "react"; +import { Dispatch, SetStateAction, useState } from "react"; +import { useMutation, useQueryClient } from "@tanstack/react-query"; +import { favoriteLink } from "@/api/links"; interface FoldrPageLinkItemProps { description: string; image_source: string; @@ -15,6 +17,7 @@ interface FoldrPageLinkItemProps { setSharedUrl: Dispatch>; date: string; linkId: number; + favorite: boolean; } const FolderPageLinkItem = ({ @@ -26,17 +29,33 @@ const FolderPageLinkItem = ({ setSharedUrl, date, linkId, + favorite, }: FoldrPageLinkItemProps) => { const { isShowModal: isShowKebabModal, handleModalClick: handleClickKebabModal, } = useModal(false); + const queryClient = useQueryClient(); const { isShowModal: isShowDeleteLinkModal, handleModalClick: handleDeleteLinkModalClick, } = useModal(false); + const makeFavortie = useMutation({ + mutationFn: ([linkId, favortieBoolean]: [number, boolean]) => { + favoriteLink(linkId, favortieBoolean); + }, + + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ["links"] }); + }, + }); + + const handleStarIcon = () => { + console.log(linkId); + makeFavortie.mutate([linkId, !favorite]); + }; return ( <>
@@ -57,11 +76,22 @@ const FolderPageLinkItem = ({ )}
- card_star_icon + {favorite === true ? ( + card_star_icon + ) : ( + card_star_icon + )} +
{functions.formatTimeAgo(created_at)} diff --git a/components/folderPage/FolderPageLinkItem/FolderPageLinkitem.module.css b/components/folderPage/FolderPageLinkItem/FolderPageLinkitem.module.css index a001a4a45..7c2023bcf 100644 --- a/components/folderPage/FolderPageLinkItem/FolderPageLinkitem.module.css +++ b/components/folderPage/FolderPageLinkItem/FolderPageLinkitem.module.css @@ -64,6 +64,7 @@ position: absolute; right: 1.5rem; top: 1.5rem; + cursor: pointer; } .item_card_kebab_icon { diff --git a/components/folderPage/FolderPageMain/FolderPageMain.tsx b/components/folderPage/FolderPageMain/FolderPageMain.tsx index 169c62788..5b82e16f0 100644 --- a/components/folderPage/FolderPageMain/FolderPageMain.tsx +++ b/components/folderPage/FolderPageMain/FolderPageMain.tsx @@ -1,7 +1,7 @@ "use client"; import styles from "./FolderPageMain.module.css"; import LinkListByFolderId from "../LinkListByFolderId/LinkListByFolderId"; -import { Dispatch, SetStateAction, useState } from "react"; +import { Dispatch, SetStateAction, useEffect, useState } from "react"; import LinkSearchInput from "@/components/common/LinkSearchInput/LinkSearchInput"; import useModal from "@/hooks/useModal"; import { LinkDataType } from "@/types/LinkDataTypes"; @@ -18,6 +18,7 @@ import ShowSearchData from "../ShowSearchData/ShowSearchData"; import { useQuery } from "@tanstack/react-query"; import { getAllLinks } from "@/api/folder"; import { getUserInfo } from "@/api/user"; +import LinkList from "../LinkList/LinkList"; interface FolderPageMainProps { isShowAddLinkInFolderModal: boolean; handleAddLinkInFolderModalClick: ( @@ -38,9 +39,14 @@ const FolderPageMain = ({ queryKey: ["user"], queryFn: getUserInfo, }); + const [folderId, setFolderId] = useState(""); + + useEffect(() => { + params !== undefined ? setFolderId(params.folderId) : setFolderId("전체"); + }, []); + console.log(folderId); const [linkData, setLinkData] = useState(null); - const [folderId, setFolderId] = useState(""); const [folderData, setFolderData] = useState(null); @@ -92,10 +98,10 @@ const FolderPageMain = ({

{folderName}

- {isShowFuncButtonBox && ( + {params && ( )}
- + {folderId === "전체" ? ( + + ) : ( + + )}
{isShowShareFolderModal && ( @@ -130,6 +144,7 @@ const FolderPageMain = ({ )} {isShowDeleteFolderModal && ( diff --git a/components/folderPage/LinkListByFolderId/LinkListByFolderId.tsx b/components/folderPage/LinkListByFolderId/LinkListByFolderId.tsx index c069ef345..f90d8fd2b 100644 --- a/components/folderPage/LinkListByFolderId/LinkListByFolderId.tsx +++ b/components/folderPage/LinkListByFolderId/LinkListByFolderId.tsx @@ -24,21 +24,21 @@ const LinkListByFolderId = ({ queryKey: ["links"], queryFn: () => getLinksByFolderId(params.folderId), }); + const [paramsId, setParamsId] = useState(); - console.log(paramsId); if (isLoading) return
Loading...
; if (error) return
Error: {error.message}
; console.log(data); return (
- {linkData?.data.length === 0 ? ( -
저장된 링크가 없습니다
- ) : ( -
- {data.map((item) => { - return ( + <> + {data.length === 0 ? ( +
저장된 링크가 없습니다
+ ) : ( +
+ {data.map((item) => ( - ); - })} -
- )} + ))} +
+ )} +
); }; diff --git a/components/folderPage/ShowAllLinkButton/ShowAllLinkButton.tsx b/components/folderPage/ShowAllLinkButton/ShowAllLinkButton.tsx index 786227836..0127f381c 100644 --- a/components/folderPage/ShowAllLinkButton/ShowAllLinkButton.tsx +++ b/components/folderPage/ShowAllLinkButton/ShowAllLinkButton.tsx @@ -1,27 +1,22 @@ import styles from "./ShowAllLinksButton.module.css"; interface ShowAllLinksButtonProps { name: string; - activeFilterId: string; - handleClick: () => void; } const ShowAllLinksButton = ({ - name, - activeFilterId, - handleClick + handleClick, + isActive, }: ShowAllLinksButtonProps) => { - const isFilterShowAll = activeFilterId === "showAll"; - return ( ); }; diff --git a/components/folderPage/modal/AddFolderModal/AddFolderModal.tsx b/components/folderPage/modal/AddFolderModal/AddFolderModal.tsx index 27a94b79d..2f0bc8507 100644 --- a/components/folderPage/modal/AddFolderModal/AddFolderModal.tsx +++ b/components/folderPage/modal/AddFolderModal/AddFolderModal.tsx @@ -21,7 +21,7 @@ const AddFolderModal = ({ const onChangeFolderNameInput = (e) => { setAddFolderName(e.target.value); }; - const handleAddModalClick = () => { + const handleAddButton = () => { addFolderByName.mutate(addFolderName, {}); handleAddFolderModalClick(); }; @@ -43,9 +43,7 @@ const AddFolderModal = ({ onClick={handleAddFolderModalClick} />
- - 추가하기 - + 추가하기
); diff --git a/components/folderPage/modal/AddLinkInFolder/AddLinkInFolder.tsx b/components/folderPage/modal/AddLinkInFolder/AddLinkInFolder.tsx index 8fc7298f7..ffd2592cf 100644 --- a/components/folderPage/modal/AddLinkInFolder/AddLinkInFolder.tsx +++ b/components/folderPage/modal/AddLinkInFolder/AddLinkInFolder.tsx @@ -6,6 +6,7 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { getAllFolders } from "@/api/folders"; import { useState } from "react"; import { addLinkInFolder } from "@/api/links"; +import { useRouter } from "next/navigation"; interface isShowAddLinkInFolderProps { handleAddLinkInFolderModalClick: ( e: React.MouseEvent @@ -23,15 +24,19 @@ const AddLinkInFolder = ({ queryFn: getAllFolders, }); const queryClient = useQueryClient(); - const [selectFolder, setSelectFolder] = useState(""); + const [selectFolderId, setSelectFolderId] = useState(); + const router = useRouter(); + + const addLink = useMutation({ mutationFn: ([url, folderId]: [string, number]) => addLinkInFolder(url, folderId), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ["links"] }); + router.push(`${selectFolderId}`); }, }); @@ -59,7 +64,7 @@ const AddLinkInFolder = ({
  • { const queryClient = useQueryClient(); const router = useRouter(); - + const deleteFolderById = useMutation({ mutationFn: deleteFolder, onSuccess: () => { @@ -23,8 +23,10 @@ const DeleteFolderModal = ({ router.push("/folder"); }, }); + + console.log(folderId); const handleDeleteButton = () => { - deleteFolderById.mutate(folderId.slice(10, folderId.length)); + deleteFolderById.mutate(folderId); handleDeleteFolderModalClick(); }; return ( diff --git a/components/folderPage/modal/ModalButton/ModalButton.tsx b/components/folderPage/modal/ModalButton/ModalButton.tsx index 067135db6..6ae95f700 100644 --- a/components/folderPage/modal/ModalButton/ModalButton.tsx +++ b/components/folderPage/modal/ModalButton/ModalButton.tsx @@ -3,10 +3,10 @@ import { childrenProps } from "../ModalWrapper/ModalWrapper"; export default function ModalButton({ children, - handleAddModalClick, + handleAddButton, }: childrenProps) { return ( - ); diff --git a/components/folderPage/modal/RenameFolderNameModal/RenameFolderNameModal.tsx b/components/folderPage/modal/RenameFolderNameModal/RenameFolderNameModal.tsx index 8886ffa75..276a6fb99 100644 --- a/components/folderPage/modal/RenameFolderNameModal/RenameFolderNameModal.tsx +++ b/components/folderPage/modal/RenameFolderNameModal/RenameFolderNameModal.tsx @@ -1,15 +1,40 @@ import styles from "./RenameFolderNameModal.module.css"; import ModalWrapper from "../ModalWrapper/ModalWrapper"; import ModalButton from "../ModalButton/ModalButton"; - +import { useState } from "react"; +import { useMutation } from "@tanstack/react-query"; +import { renameFolder } from "@/api/folders"; +import { useQueryClient } from "@tanstack/react-query"; interface RenameFolderNameProps { handleRenameFolderModalClick: (e: React.MouseEvent) => void; FolderModalValue: string; + folderId: number; } const RenameFolderNameModal = ({ handleRenameFolderModalClick, FolderModalValue, + folderId, }: RenameFolderNameProps) => { + const [folderName, setFolderName] = useState(""); + const queryClient = useQueryClient(); + + const onChangeInput = (e) => { + setFolderName(e.target.value); + }; + + const renameFolders = useMutation({ + mutationFn: ([folderName, folderId]: [string, number]) => + renameFolder(folderName, folderId), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ["folders"] }); + }, + }); + + console.log(folderId); + const handleAddButton = () => { + renameFolders.mutate([folderName, folderId]); + handleRenameFolderModalClick(); + }; return (
    @@ -18,7 +43,8 @@ const RenameFolderNameModal = ({ modal-close-icon
    - 확인하기 + 확인하기
  • ); diff --git a/public/assets/images/favortie_link.svg b/public/assets/images/favortie_link.svg new file mode 100644 index 000000000..f68490c1d --- /dev/null +++ b/public/assets/images/favortie_link.svg @@ -0,0 +1,10 @@ + + + + + + + + + + From 155b08d7aee0082c0161e4085ab2756ae4a935c4 Mon Sep 17 00:00:00 2001 From: hoj0806 <90647684+hoj0806@users.noreply.github.com> Date: Tue, 14 May 2024 00:44:56 +0900 Subject: [PATCH 10/14] =?UTF-8?q?feat=20:=20shared=20=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=20=EC=99=84=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/folders.ts | 19 +++++++ api/user.ts | 2 +- app/(FolderPage)/folder/[folderId]/page.tsx | 2 + app/(SharedPage)/shared/[folderId]/page.tsx | 14 +++++- app/(SharedPage)/shared/page.tsx | 11 +--- components/folderPage/LinkList/LinkList.tsx | 3 +- .../LinkListByFolderId/LinkListByFolderId.tsx | 27 +++++----- .../sharedPage/Profile/Profile.module.css | 1 + components/sharedPage/Profile/Profile.tsx | 50 +++++++++++++------ .../SharePageFolderItem.tsx | 6 +-- .../SharePageFolderList/SharePageLinkList.tsx | 17 ++++--- util/Provider.tsx | 1 - 12 files changed, 103 insertions(+), 50 deletions(-) diff --git a/api/folders.ts b/api/folders.ts index d03b8bec2..3d152e54d 100644 --- a/api/folders.ts +++ b/api/folders.ts @@ -20,6 +20,25 @@ export const getAllFolders = async () => { } }; +export const getFolderById = async (folderId: number) => { + const accessToken = localStorage.getItem("accessToken"); + + try { + const response = await instance.get( + `https://bootcamp-api.codeit.kr/api/linkbrary/v1/folders/${folderId}`, + { + headers: { + Authorization: `Bearer ${accessToken}`, // Bearer 토큰 추가 + }, + } + ); + return response.data; + } catch (error) { + console.error("Error"); + throw error; + } +}; + export const addFolder = async (folderName: string) => { const accessToken = localStorage.getItem("accessToken"); try { diff --git a/api/user.ts b/api/user.ts index 1bcb93774..69c691f7a 100644 --- a/api/user.ts +++ b/api/user.ts @@ -14,7 +14,7 @@ export const getUserInfo = async () => { }, } ); - return response; + return response.data; } catch (error) { console.error("Error fetching links:", error); throw error; diff --git a/app/(FolderPage)/folder/[folderId]/page.tsx b/app/(FolderPage)/folder/[folderId]/page.tsx index 9493d3dfe..b05c2b240 100644 --- a/app/(FolderPage)/folder/[folderId]/page.tsx +++ b/app/(FolderPage)/folder/[folderId]/page.tsx @@ -22,6 +22,8 @@ const FolderPage = ({ params }: { folderId: string }) => { } = useModal(false); const [sharedUrl, setSharedUrl] = useState(""); + + console.log(window.location.href.replaceAll("folder", "shared")); return ( <> Folder | Linkbrary diff --git a/app/(SharedPage)/shared/[folderId]/page.tsx b/app/(SharedPage)/shared/[folderId]/page.tsx index 630a5e949..366333257 100644 --- a/app/(SharedPage)/shared/[folderId]/page.tsx +++ b/app/(SharedPage)/shared/[folderId]/page.tsx @@ -1,16 +1,26 @@ import Profile from "@/components/sharedPage/Profile/Profile"; import SharedPageMain from "@/components/sharedPage/SharedPageMain/SharedPageMain"; import HeaderFooterLayout from "@/app/headerFooterLayout"; +import { useQuery } from "@tanstack/react-query"; +import { getFolderById } from "@/api/folders"; +import { + dehydrate, + HydrationBoundary, + QueryClient, +} from "@tanstack/react-query"; export const metadata = { title: "Shared", }; +export const queryClient = new QueryClient(); const SharedPage = async ({ params }: { folderId: string }) => { return ( - - + + + + ); }; diff --git a/app/(SharedPage)/shared/page.tsx b/app/(SharedPage)/shared/page.tsx index 62cb13236..be64243d5 100644 --- a/app/(SharedPage)/shared/page.tsx +++ b/app/(SharedPage)/shared/page.tsx @@ -1,18 +1,9 @@ -import Profile from "@/components/sharedPage/Profile/Profile"; -import SharedPageMain from "@/components/sharedPage/SharedPageMain/SharedPageMain"; -import HeaderFooterLayout from "@/app/headerFooterLayout"; - export const metadata = { title: "Shared", }; const SharedPage = async () => { - return ( - - - - - ); + return
    ; }; export default SharedPage; diff --git a/components/folderPage/LinkList/LinkList.tsx b/components/folderPage/LinkList/LinkList.tsx index c2f906838..f60a1dcc3 100644 --- a/components/folderPage/LinkList/LinkList.tsx +++ b/components/folderPage/LinkList/LinkList.tsx @@ -17,7 +17,6 @@ const LinkList = ({ setSharedUrl, linkData, }: LinkListProps) => { - const { data, isLoading, error } = useQuery({ queryKey: ["links"], queryFn: () => getAllLinks(), @@ -26,6 +25,7 @@ const LinkList = ({ if (isLoading) return
    Loading...
    ; if (error) return
    Error: {error.message}
    ; console.log(data); + console.log("전체 데이터입니다"); return (
    {linkData?.data.length === 0 ? ( @@ -42,6 +42,7 @@ const LinkList = ({ setSharedUrl={setSharedUrl} date={item.created_at.slice(0, 10)} key={item.id} + linkId={item.id} /> ); })} diff --git a/components/folderPage/LinkListByFolderId/LinkListByFolderId.tsx b/components/folderPage/LinkListByFolderId/LinkListByFolderId.tsx index f90d8fd2b..bcaca8b11 100644 --- a/components/folderPage/LinkListByFolderId/LinkListByFolderId.tsx +++ b/components/folderPage/LinkListByFolderId/LinkListByFolderId.tsx @@ -3,8 +3,8 @@ import { Dispatch, SetStateAction, useEffect, useState } from "react"; import { LinkDataType } from "@/types/LinkDataTypes"; import FolderPageLinkItem from "../FolderPageLinkItem/FolderPageLinkItem"; import { useQuery } from "@tanstack/react-query"; -import { getAllLinks } from "@/api/folder"; import { getLinksByFolderId } from "@/api/links"; + interface LinkListProps { handleAddLinkInFolderModalClick: ( e: React.MouseEvent @@ -24,21 +24,25 @@ const LinkListByFolderId = ({ queryKey: ["links"], queryFn: () => getLinksByFolderId(params.folderId), }); + const [linkDatas, setLinkData] = useState(); - const [paramsId, setParamsId] = useState(); + useEffect(() => { + if (data) { + setLinkData(data); + } + }, [data]); if (isLoading) return
    Loading...
    ; if (error) return
    Error: {error.message}
    ; - console.log(data); return (
    - <> - {data.length === 0 ? ( -
    저장된 링크가 없습니다
    - ) : ( -
    - {data.map((item) => ( + {linkDatas && linkDatas.length === 0 ? ( +
    저장된 링크가 없습니다
    + ) : ( +
    + {linkDatas && + linkDatas.map((item) => ( ))} -
    - )} - +
    + )}
    ); }; diff --git a/components/sharedPage/Profile/Profile.module.css b/components/sharedPage/Profile/Profile.module.css index 668d7121a..bed5de122 100644 --- a/components/sharedPage/Profile/Profile.module.css +++ b/components/sharedPage/Profile/Profile.module.css @@ -24,6 +24,7 @@ .profile-name { font-family: var(--Pretendard-Regular); line-height: 1.6rem; + font-size: 2rem; } .folder-name { diff --git a/components/sharedPage/Profile/Profile.tsx b/components/sharedPage/Profile/Profile.tsx index d36802b0d..f67f80007 100644 --- a/components/sharedPage/Profile/Profile.tsx +++ b/components/sharedPage/Profile/Profile.tsx @@ -1,23 +1,45 @@ +"use client"; + import styles from "./Profile.module.css"; -import { getSharedPageFolderData } from "@/api/sharedPageFolderData"; +import { useQuery } from "@tanstack/react-query"; +import { getUserInfo } from "@/api/user"; +import { getFolderById } from "@/api/folders"; +const Profile = ({ params }: { folderId: number }) => { + const { data } = useQuery({ + queryKey: ["users"], + queryFn: () => getUserInfo(), + }); -const Profile = async () => { - const folderData = await getSharedPageFolderData(); + const { data: folderData } = useQuery({ + queryKey: ["folder"], + queryFn: () => getFolderById(params.folderId), + }); + console.log(folderData); + return (
    -
    - profile_avatar_image -
    - {folderData?.folder.owner.name} -
    -
    -

    {folderData?.folder.name}

    + {data?.map((i) => { + return ( +
    + profile_avatar_image +
    {i.name}
    +
    + ); + })} + + {folderData?.map((i) => { + return ( +

    + {i.name} +

    + ); + })}
    ); diff --git a/components/sharedPage/SharPageFolderItem/SharePageFolderItem.tsx b/components/sharedPage/SharPageFolderItem/SharePageFolderItem.tsx index 561fffd01..79e4c925c 100644 --- a/components/sharedPage/SharPageFolderItem/SharePageFolderItem.tsx +++ b/components/sharedPage/SharPageFolderItem/SharePageFolderItem.tsx @@ -13,16 +13,16 @@ function SharePageFolderItem({ createdAt, url, title, - imageSource, + image_source, date, }: FolderDataType) { return (
    - {imageSource ? ( + {image_source ? (
    folder_image diff --git a/components/sharedPage/SharePageFolderList/SharePageLinkList.tsx b/components/sharedPage/SharePageFolderList/SharePageLinkList.tsx index 6417c2520..1ecd0544f 100644 --- a/components/sharedPage/SharePageFolderList/SharePageLinkList.tsx +++ b/components/sharedPage/SharePageFolderList/SharePageLinkList.tsx @@ -3,24 +3,29 @@ import styles from "./SharePageLinkList.module.css"; import { useQuery } from "@tanstack/react-query"; import { getLinksByFolderId } from "@/api/links"; -const SharePageFolderList = ({ params }) => { +import { getAllFolders } from "@/api/folders"; +import SharePageFolderItem from "../SharPageFolderItem/SharePageFolderItem"; +const SharePageFolderList = ({ params }: { folderId: string }) => { console.log(params); - const { data } = useQuery({ - queryKey: ["shared"], + const { data, isLoading, error } = useQuery({ + queryKey: ["links"], queryFn: () => getLinksByFolderId(params.folderId), }); + if (isLoading) return
    Loading...
    ; + if (error) return
    Error: {error.message}
    ; + console.log(data); return (
    - {/* {folderData?.folder.links.map((data) => ( + {data.map((data) => ( - ))} */} + ))}
    ); }; diff --git a/util/Provider.tsx b/util/Provider.tsx index f02092d82..338889226 100644 --- a/util/Provider.tsx +++ b/util/Provider.tsx @@ -7,7 +7,6 @@ import { useState } from "react"; export default function Provider({ children }: { children: ReactNode }) { const [queryClient] = useState(() => new QueryClient()); - return ( From e631a784ad7518ac01817a67f13e9871901d125d Mon Sep 17 00:00:00 2001 From: hoj0806 <90647684+hoj0806@users.noreply.github.com> Date: Tue, 14 May 2024 00:48:32 +0900 Subject: [PATCH 11/14] =?UTF-8?q?refactor=20:=20=ED=8F=B4=EB=8D=94=20?= =?UTF-8?q?=EA=B3=B5=EC=9C=A0=20=EA=B8=B0=EB=8A=A5=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/(FolderPage)/folder/[folderId]/page.tsx | 1 - .../FolderPageMain/FolderPageMain.tsx | 1 + .../ShareFolderModal/ShareFolderModal.js | 62 +++++++++---------- 3 files changed, 31 insertions(+), 33 deletions(-) diff --git a/app/(FolderPage)/folder/[folderId]/page.tsx b/app/(FolderPage)/folder/[folderId]/page.tsx index b05c2b240..9d070b8b5 100644 --- a/app/(FolderPage)/folder/[folderId]/page.tsx +++ b/app/(FolderPage)/folder/[folderId]/page.tsx @@ -23,7 +23,6 @@ const FolderPage = ({ params }: { folderId: string }) => { const [sharedUrl, setSharedUrl] = useState(""); - console.log(window.location.href.replaceAll("folder", "shared")); return ( <> Folder | Linkbrary diff --git a/components/folderPage/FolderPageMain/FolderPageMain.tsx b/components/folderPage/FolderPageMain/FolderPageMain.tsx index 5b82e16f0..439a615f0 100644 --- a/components/folderPage/FolderPageMain/FolderPageMain.tsx +++ b/components/folderPage/FolderPageMain/FolderPageMain.tsx @@ -138,6 +138,7 @@ const FolderPageMain = ({ handleShareFolderModalClick={handleShareFolderModalClick} FolderModalValue={FolderModalValue} ShareUrlFolderId={ShareUrlFolderId} + folderId={folderId} /> )} {isShowRenameFolderModal && ( diff --git a/components/folderPage/modal/ShareFolderModal/ShareFolderModal.js b/components/folderPage/modal/ShareFolderModal/ShareFolderModal.js index daf40c753..8c877d480 100644 --- a/components/folderPage/modal/ShareFolderModal/ShareFolderModal.js +++ b/components/folderPage/modal/ShareFolderModal/ShareFolderModal.js @@ -6,34 +6,35 @@ const ShareFolderModal = ({ handleShareFolderModalClick, FolderModalValue, ShareUrlFolderId, + folderId, }) => { - const { Kakao } = window; + // const { Kakao } = window; - useEffect(() => { - Kakao.cleanup(); - Kakao.init("9adbb4d8d436041f3eeadb2a25b525ec"); - }); - const shareKakao = () => { - Kakao.Share.sendDefault({ - objectType: "feed", - content: { - title: "Linkbrary", - description: "링크를 공유해보세요", - imageUrl: `${process.env.PUBLIC_URL}/assets/images/share_url_copy_url_icon.svg`, - link: { - mobileWebUrl: window.location.host + "/shared/" + ShareUrlFolderId, - }, - }, - buttons: [ - { - title: "나도 테스트 하러가기", - link: { - mobileWebUrl: window.location.host + "/shared/" + ShareUrlFolderId, - }, - }, - ], - }); - }; + // useEffect(() => { + // Kakao.cleanup(); + // Kakao.init("9adbb4d8d436041f3eeadb2a25b525ec"); + // }); + // const shareKakao = () => { + // Kakao.Share.sendDefault({ + // objectType: "feed", + // content: { + // title: "Linkbrary", + // description: "링크를 공유해보세요", + // imageUrl: `${process.env.PUBLIC_URL}/assets/images/share_url_copy_url_icon.svg`, + // link: { + // mobileWebUrl: window.location.host + "/shared/" + ShareUrlFolderId, + // }, + // }, + // buttons: [ + // { + // title: "나도 테스트 하러가기", + // link: { + // mobileWebUrl: window.location.host + "/shared/" + ShareUrlFolderId, + // }, + // }, + // ], + // }); + // }; return ( @@ -48,7 +49,6 @@ const ShareFolderModal = ({ kakao-talk-shared-icon

    카카오톡

    @@ -61,7 +61,7 @@ const ShareFolderModal = ({ "https://twitter.com/intent/tweet?text=" + window.location.host + "/shared/" + - ShareUrlFolderId + folderId ); }} /> @@ -74,11 +74,9 @@ const ShareFolderModal = ({ src='assets/images/share_url_copy_url_icon.svg' onClick={() => { window.navigator.clipboard - .writeText( - window.location.host + "/shared/" + ShareUrlFolderId - ) + .writeText(window.location.host + "/shared/" + folderId) .then(() => { - alert("링크 복사완료"); + alert("공유 링크가 복사되었습니다"); }); }} /> From 08df53c9067acf42628e64b0cd5fa48b9257e2b0 Mon Sep 17 00:00:00 2001 From: hoj0806 <90647684+hoj0806@users.noreply.github.com> Date: Tue, 14 May 2024 13:55:18 +0900 Subject: [PATCH 12/14] =?UTF-8?q?=EB=84=A4=EB=B9=84=EA=B2=8C=EC=9D=B4?= =?UTF-8?q?=EC=85=98=20=ED=94=84=EB=A1=9C=ED=95=84=EC=B0=BD=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=99=84=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/common/Navigation/Navigation.tsx | 44 ++++++++++++------- .../FolderPageMain/FolderPageMain.tsx | 1 - components/folderPage/LinkList/LinkList.tsx | 3 +- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/components/common/Navigation/Navigation.tsx b/components/common/Navigation/Navigation.tsx index 595007992..092fbd8fd 100644 --- a/components/common/Navigation/Navigation.tsx +++ b/components/common/Navigation/Navigation.tsx @@ -1,9 +1,19 @@ import styles from "./Navigation.module.css"; -import { getUserData } from "@/api/userData"; + import NavLoginButton from "../NavLoginButton/NavLoginButton"; import Link from "next/link"; import Image from "next/image"; +import { useQuery } from "@tanstack/react-query"; +import { getUserInfo } from "@/api/user"; const Navigation = () => { + const { data } = useQuery({ + queryKey: ["users"], + queryFn: () => getUserInfo(), + }); + + + const accessToken = localStorage.getItem("accessToken"); + return (
    @@ -17,22 +27,26 @@ const Navigation = () => { />
    - - - - - {/* {!userData.email ? ( - - ) : ( + {accessToken !== undefined ? ( <> - user_profile_image -

    {userData.email}

    + {data?.map((item) => { + return ( + <> + user_profile_image +

    {item?.email}

    + + ); + })} - )} */} + ) : ( + + + + )}
    diff --git a/components/folderPage/FolderPageMain/FolderPageMain.tsx b/components/folderPage/FolderPageMain/FolderPageMain.tsx index 439a615f0..cd7831940 100644 --- a/components/folderPage/FolderPageMain/FolderPageMain.tsx +++ b/components/folderPage/FolderPageMain/FolderPageMain.tsx @@ -45,7 +45,6 @@ const FolderPageMain = ({ params !== undefined ? setFolderId(params.folderId) : setFolderId("전체"); }, []); - console.log(folderId); const [linkData, setLinkData] = useState(null); const [folderData, setFolderData] = useState(null); diff --git a/components/folderPage/LinkList/LinkList.tsx b/components/folderPage/LinkList/LinkList.tsx index f60a1dcc3..4ddda4373 100644 --- a/components/folderPage/LinkList/LinkList.tsx +++ b/components/folderPage/LinkList/LinkList.tsx @@ -24,8 +24,7 @@ const LinkList = ({ if (isLoading) return
    Loading...
    ; if (error) return
    Error: {error.message}
    ; - console.log(data); - console.log("전체 데이터입니다"); + return (
    {linkData?.data.length === 0 ? ( From dc54ac2df0d0b80840c0d9d860cad5418ac1757b Mon Sep 17 00:00:00 2001 From: hoj0806 <90647684+hoj0806@users.noreply.github.com> Date: Tue, 14 May 2024 15:10:35 +0900 Subject: [PATCH 13/14] =?UTF-8?q?fix=20=EC=98=A4=EB=A5=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/common/Navigation/Navigation.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/common/Navigation/Navigation.tsx b/components/common/Navigation/Navigation.tsx index 092fbd8fd..7579aa869 100644 --- a/components/common/Navigation/Navigation.tsx +++ b/components/common/Navigation/Navigation.tsx @@ -1,3 +1,5 @@ +"use client"; + import styles from "./Navigation.module.css"; import NavLoginButton from "../NavLoginButton/NavLoginButton"; @@ -11,9 +13,8 @@ const Navigation = () => { queryFn: () => getUserInfo(), }); - const accessToken = localStorage.getItem("accessToken"); - + return (
    From 5e88df8dd8235d84355a20b0cdcbba184b66600e Mon Sep 17 00:00:00 2001 From: hoj0806 <90647684+hoj0806@users.noreply.github.com> Date: Tue, 14 May 2024 15:41:16 +0900 Subject: [PATCH 14/14] =?UTF-8?q?Fix=20:=EB=84=A4=EB=B9=84=EA=B2=8C?= =?UTF-8?q?=EC=9D=B4=EC=85=98=20=EB=8F=99=EC=9E=91=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/common/Navigation/Navigation.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/common/Navigation/Navigation.tsx b/components/common/Navigation/Navigation.tsx index 7579aa869..7972d5d31 100644 --- a/components/common/Navigation/Navigation.tsx +++ b/components/common/Navigation/Navigation.tsx @@ -28,7 +28,7 @@ const Navigation = () => { />
    - {accessToken !== undefined ? ( + {accessToken !== null ? ( <> {data?.map((item) => { return (