-
+
폴더 추가 +
diff --git a/pages/index.tsx b/pages/index.tsx
index 1ddf2524a..04f134341 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -1,90 +1,7 @@
-import Footer from "@/components/sharing/Footer";
-import React, { useEffect, useState } from "react";
-import { getSampleFolder, getUser } from "@/utils/api";
-import SearchInputForm from "@/components/folder/input/SearchInputForm";
-import CardList from "@/components/folder/card/CardList";
-import FolderHeaderLayout from "@/components/folder/layout/FolderHeaderLayout";
-import MainLayout from "@/components/folder/layout/MainLayout";
-import styled from "styled-components";
-import { TSampleFolder, TUser } from "@/utils/types";
-import Header from "@/components/sharing/Header";
-import Avatar from "@/components/sharing/user/Avatar";
-import { useRouter } from "next/router";
-import { FILTER_LINKS } from "@/utils/constants";
-import { SearchMessage } from "@/pages/folder";
+import React from "react";
-export async function getServerSideProps() {
- const folderInfo = await getSampleFolder();
- const userInfo = await getUser();
-
- return {
- props: {
- folderInfo,
- userInfo,
- },
- };
+function Index() {
+ return
Index
;
}
-const FolderOwner = styled.div`
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: 12px;
-`;
-
-const Index = ({
- folderInfo,
- userInfo,
-}: {
- folderInfo: TSampleFolder;
- userInfo: TUser;
-}) => {
- const router = useRouter();
- const keyword = (router.query["keyword"] as string) || null;
- const [links, setLinks] = useState(folderInfo.links);
-
- const loadNewLinks = () => {
- if (keyword) {
- const loweredKeyword = keyword.toLowerCase();
- setLinks((prevState) => FILTER_LINKS(prevState, loweredKeyword));
- } else {
- setLinks(folderInfo.links);
- }
- };
-
- useEffect(() => {
- loadNewLinks();
- }, [keyword]);
- return (
- <>
-
-
-
-
-
- @{folderInfo.owner.name}
-
-
- {folderInfo?.name}
-
-
-
-
- {keyword ? (
-
- {keyword}
- 으로 검색한 결과입니다.
-
- ) : null}
-
-
-
-
- >
- );
-};
export default Index;
diff --git a/pages/shared/[folderId].tsx b/pages/shared/[folderId].tsx
new file mode 100644
index 000000000..b6752de72
--- /dev/null
+++ b/pages/shared/[folderId].tsx
@@ -0,0 +1,118 @@
+import Footer from "@/components/sharing/Footer";
+import React, { useEffect, useState } from "react";
+import { getFolderInfo, getSharedPageData, getUser } from "@/utils/api";
+import SearchInputForm from "@/components/folder/input/SearchInputForm";
+import FolderHeaderLayout from "@/components/folder/layout/FolderHeaderLayout";
+import MainLayout from "@/components/folder/layout/MainLayout";
+import styled from "styled-components";
+import { TFolder, TLink, TUser } from "@/utils/types";
+import Header from "@/components/sharing/Header";
+import Avatar from "@/components/sharing/user/Avatar";
+import { useRouter } from "next/router";
+import { SearchMessage } from "@/pages/folder/[folderId]";
+import CardList from "@/components/folder/card/CardList";
+import { useMyInfo } from "@/contexts/MyInfoContext";
+
+export async function getServerSideProps(context: any) {
+ const { folderId } = context.query;
+
+ return {
+ props: {
+ folderId,
+ },
+ };
+}
+
+const FolderOwner = styled.div`
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ gap: 12px;
+`;
+
+const Index = ({ folderId }: { folderId: number }) => {
+ const router = useRouter();
+ const keyword = (router.query["keyword"] as string) || null;
+ const [links, setLinks] = useState
();
+ const [folderInfo, setFolderInfo] = useState({
+ id: 0,
+ created_at: "",
+ name: "",
+ user_id: 0,
+ favorite: false,
+ });
+ const [ownerId, setOwnerId] = useState(0);
+ const [folderOwner, setFolderOwner] = useState();
+ const { myInfo } = useMyInfo();
+
+ const loadFolderInfo = async () => {
+ const res = await getFolderInfo(folderId);
+ setFolderInfo(res);
+ setOwnerId(res.user_id);
+ };
+
+ const loadUserInfo = async () => {
+ const res = await getUser(ownerId);
+ setFolderOwner(res);
+ };
+
+ const loadLinks = async () => {
+ const res = await getSharedPageData(ownerId, folderId);
+ setLinks(res);
+ };
+
+ // const loadNewLinks = () => {
+ // if (keyword) {
+ // const loweredKeyword = keyword.toLowerCase();
+ // setLinks((prevState: TLink[]) => FILTER_LINKS(prevState, loweredKeyword));
+ // } else {
+ // setLinks(folderInfo.links);
+ // }
+ // };
+
+ // useEffect(() => {
+ // loadNewLinks();
+ // }, [keyword]);
+
+ useEffect(() => {
+ loadFolderInfo();
+ }, []);
+
+ useEffect(() => {
+ loadUserInfo();
+ loadLinks();
+ }, [ownerId]);
+
+ return (
+ <>
+
+
+
+
+
+ @{folderOwner?.name}
+
+
+ {folderInfo?.name}
+
+
+
+
+ {keyword ? (
+
+ {keyword}
+ 으로 검색한 결과입니다.
+
+ ) : null}
+
+
+
+
+ >
+ );
+};
+export default Index;
diff --git a/pages/signin.tsx b/pages/signin.tsx
index 5bc83075c..77b2fe902 100644
--- a/pages/signin.tsx
+++ b/pages/signin.tsx
@@ -12,12 +12,19 @@ import {
INPUT_EMAIL_MESSAGE,
INPUT_PASSWORD_MESSAGE,
} from "@/utils/constants";
-import { postSignIn } from "@/utils/api";
+import { getMyInfo, postSignIn } from "@/utils/api";
import { useRouter } from "next/router";
+import { useMyInfo } from "@/contexts/MyInfoContext";
const SignIn = () => {
const router = useRouter();
const [loginError, setLoginError] = useState(false);
+ const { setMyInfo } = useMyInfo();
+
+ const loadMyInfo = async () => {
+ const res = await getMyInfo();
+ setMyInfo(res);
+ };
const {
register,
@@ -31,6 +38,7 @@ const SignIn = () => {
if (token) {
localStorage.setItem("accessToken", token.accessToken);
localStorage.setItem("refreshToken", token.refreshToken);
+ loadMyInfo();
router.push("/folder");
} else {
setLoginError(true);
diff --git a/utils/api.ts b/utils/api.ts
index 0e615b9ac..4f8784597 100644
--- a/utils/api.ts
+++ b/utils/api.ts
@@ -1,23 +1,19 @@
import axios from "@/utils/axios";
-import {
- TAuth,
- TFolder,
- TLink,
- TSampleFolder,
- TToken,
- TUser,
-} from "@/utils/types";
+import { TAuth, TFolder, TLink, TToken, TUser } from "@/utils/types";
import {
ERROR_400_MESSAGE,
ERROR_409_MESSAGE,
- FILTER_LINKS,
HTTP_ERROR,
NETWORK_ERROR,
} from "@/utils/constants";
+import { MyInfo } from "@/contexts/MyInfoContext";
+
+const ACCESS_TOKEN =
+ typeof window !== "undefined" ? localStorage.getItem("accessToken") : null;
-export const getUser = async (): Promise => {
+export const getUser = async (userId: number): Promise => {
return axios
- .get("/users/1")
+ .get(`/users/${userId}`)
.then((response) => {
const responseData = response.data;
return responseData.data[0];
@@ -27,12 +23,16 @@ export const getUser = async (): Promise => {
});
};
-export const getSampleFolder = async (): Promise => {
+export const getMyInfo = async (): Promise => {
return axios
- .get("/sample/folder")
+ .get(`/users`, {
+ headers: {
+ Authorization: `Bearer ${ACCESS_TOKEN}`,
+ },
+ })
.then((response) => {
const responseData = response.data;
- return responseData.folder;
+ return responseData.data[0];
})
.catch((error: Error) => {
throw HTTP_ERROR(error);
@@ -41,11 +41,12 @@ export const getSampleFolder = async (): Promise => {
export const getFolders = async (): Promise => {
return await axios
- .get("/users/1/folders")
- .then((response) => {
- const responseData = response.data;
- return responseData.data;
+ .get("/folders", {
+ headers: {
+ Authorization: `Bearer ${ACCESS_TOKEN}`,
+ },
})
+ .then((res) => res.data.data.folder)
.catch((error: Error) => {
throw HTTP_ERROR(error);
});
@@ -55,19 +56,22 @@ export const getLinks = async (
folderId: number,
keyword: string | null,
): Promise => {
- const URL =
- folderId === 1 ? `/users/1/links` : `/users/1/links?folderId=${folderId}`;
+ const URL = folderId === 1 ? `/links` : `/links?folderId=${folderId}`;
return axios
- .get(URL)
+ .get(URL, {
+ headers: {
+ Authorization: `Bearer ${ACCESS_TOKEN}`,
+ },
+ })
.then((response) => response.data)
.then((responseData) => {
const result = responseData.data;
- if (keyword) {
- const loweredKeyword = keyword.toLowerCase();
- return FILTER_LINKS(result, loweredKeyword);
- }
- return result;
+ // if (keyword) {
+ // const loweredKeyword = keyword.toLowerCase();
+ // return FILTER_LINKS(result, loweredKeyword);
+ // }
+ return result.folder;
})
.catch((error: Error) => {
throw HTTP_ERROR(error);
@@ -118,3 +122,24 @@ export const postSignUp = async (values: TAuth): Promise => {
throw NETWORK_ERROR(error);
});
};
+
+export const getSharedPageData = async (userId: number, folderId: number) => {
+ return await axios
+ .get(`/users/${userId}/links?folderId=${folderId}`, {
+ headers: {
+ Authorization: `Bearer ${ACCESS_TOKEN}`,
+ },
+ })
+ .then((res) => res.data.data);
+};
+
+export const getFolderInfo = async (folderId: number): Promise => {
+ return await axios
+ .get(`/folders/${folderId}`, {
+ headers: {
+ Authorization: `Bearer ${ACCESS_TOKEN}`,
+ },
+ })
+ .then((res) => res.data)
+ .then((data) => data.data[0]);
+};
diff --git a/utils/types.ts b/utils/types.ts
index abf16b826..3b94948cc 100644
--- a/utils/types.ts
+++ b/utils/types.ts
@@ -19,21 +19,21 @@ export type TUser = {
image_source?: string | null;
};
-export type TFolder = {
- id: number;
- created_at?: string;
- name?: string;
- user_id?: number;
- favorite?: boolean;
- link: { count: number };
-};
+// export type TFolder = {
+// id: number;
+// created_at?: string;
+// name?: string;
+// user_id?: number;
+// favorite?: boolean;
+// link: { count: number };
+// };
-export type TSampleFolder = {
+export type TFolder = {
id: number;
- name?: string;
- owner: TUser;
- links: TLink[];
- count: number;
+ created_at: string;
+ name: string;
+ user_id: number;
+ favorite: boolean;
};
export type TLink = {