Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[김준영] Week16 #1067

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 63 additions & 45 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 21 additions & 20 deletions components/folder/card/CardList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,31 @@ const CardList = ({ links }: { links: TLink[] | undefined }) => {
// loadLinks();
// }, [currentFolder, keyword]);

if (links?.length === 0) return <NoLink />;
if (!links || links?.length === 0) return <NoLink />;
return (
<CardListContainer>
{links?.map((link) => {
const createdAt = link.created_at || link.createdAt;
const imageSource = link.image_source || link.imageSource;
{links &&
links.map((link) => {
const createdAt = link.created_at || link.createdAt;
const imageSource = link.image_source || link.imageSource;
Comment on lines +48 to +51
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

뭔가 Prettier, Lint 룰이 변경되었나보군요!


const createdDate = new Date(createdAt as string);
const currentDate = new Date();
const createdDate = new Date(createdAt as string);
const currentDate = new Date();

return (
<Card
key={link.id}
id={link.id}
cardImage={imageSource}
cardTime={{
createdDateString: formatDate(createdDate),
timeDifference: getTimeDifference(createdDate, currentDate),
}}
cardDescription={link.description || ""}
cardUrl={link.url}
/>
);
})}
return (
<Card
key={link.id}
id={link.id}
cardImage={imageSource}
cardTime={{
createdDateString: formatDate(createdDate),
timeDifference: getTimeDifference(createdDate, currentDate),
}}
cardDescription={link.description || ""}
cardUrl={link.url}
/>
);
})}
Comment on lines +56 to +69
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

뭔가 Prettier, Lint 룰이 변경되었나보군요!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

들여쓰기 뎁스는 보통 실무에서 4보다는 2를 더 많이 사용하곤 합니다~

</CardListContainer>
);
};
Expand Down
22 changes: 19 additions & 3 deletions components/folder/tag/TagList.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from "react";
import React, { useEffect } from "react";
import Tag from "@/components/folder/tag/Tag";
import styled from "styled-components";
import { useFolder } from "@/contexts/FolderContext";
import { TFolder } from "@/utils/types";
import { getFolderInfo } from "@/utils/api";

const TagListContainer = styled.div`
width: 90%;
Expand All @@ -12,13 +13,28 @@ const TagListContainer = styled.div`
gap: 10px;
`;

const TagList = ({ foldersInfo }: { foldersInfo: TFolder[] }) => {
const TagList = ({
foldersInfo,
folderId,
}: {
foldersInfo: TFolder[];
folderId: number;
}) => {
const { currentFolder, setCurrentFolder } = useFolder();

const handleClickTag = (id: number, name: string) => {
setCurrentFolder({ id, name });
};

const loadFolder = async () => {
const res = await getFolderInfo(folderId);
setCurrentFolder({ id: res.id, name: res.name });
};

useEffect(() => {
loadFolder();
}, []);

return (
<TagListContainer>
<Tag
Expand All @@ -29,7 +45,7 @@ const TagList = ({ foldersInfo }: { foldersInfo: TFolder[] }) => {
>
전체
</Tag>
{foldersInfo.length !== 0
{foldersInfo
? foldersInfo.map((folder) => {
Comment on lines -32 to +48
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리뷰 반영 굳 입니다! 👍

return (
<Tag
Expand Down
1 change: 0 additions & 1 deletion components/sharing/modal/ModalFolderList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ function ModalFolderList() {
loadFolders();
}, []);

if (!folders) return <></>;
return (
<FolderList>
{folders.map((folder: TFolder) => (
Expand Down
58 changes: 58 additions & 0 deletions contexts/MyInfoContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React, {
createContext,
ReactNode,
useContext,
useMemo,
useState,
} from "react";

export type MyInfo = {
id: number;
created_at: string;
name: string;
image_source: string;
email: string;
auth_id: string;
};

type MyInfoContextValue = {
myInfo: MyInfo;
setMyInfo: (value: MyInfo) => void;
};

const MyInfoContext = createContext<MyInfoContextValue>({
myInfo: {
id: 0,
created_at: "",
name: "",
image_source: "",
email: "",
auth_id: "",
},
setMyInfo: () => {},
});

export const MyInfoProvider = ({ children }: { children: ReactNode }) => {
const [myInfo, setMyInfo] = useState({
id: 0,
created_at: "",
name: "",
image_source: "",
email: "",
auth_id: "",
});

const value = useMemo(() => ({ myInfo, setMyInfo }), [myInfo]);

return (
<MyInfoContext.Provider value={value}>{children}</MyInfoContext.Provider>
);
};

export const useMyInfo = () => {
const context = useContext(MyInfoContext);
if (!context) {
throw new Error("");
}
Comment on lines +54 to +56
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

에러 메시지에 "" 보다는 아래처럼 조금 더 구체적인 메시지가 담기면 향후 디버깅에 보다 수월할거에요~

if (!context) {
    throw new Error("MyInfoContext state error");
  }

return context;
};
17 changes: 1 addition & 16 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,10 @@
const nextConfig = {
reactStrictMode: true,
images: {
domains: [
"jasonwatmore.com",
"codeit-images.codeit.com",
"codeit-frontend.codeit.com",
"reactjs.org",
"assets.vercel.com",
"tanstack.com",
"storybook.js.org",
"testing-library.com",
"*.*",
"static.cdninstagram.com",
"s.pstatic.net",
],
remotePatterns: [
{
protocol: "https",
hostname: "bootcamp-api.codeit.kr",
port: "",
pathname: "/api/**", //**는 해당 경로 뒤에 모든 경로,
hostname: "**",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리뷰 반영 굳! 👍

},
],
},
Expand Down
25 changes: 14 additions & 11 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import "@/styles/globals.css";
import type {AppProps} from "next/app";
import {FolderProvider} from "@/contexts/FolderContext";
import type { AppProps } from "next/app";
import { FolderProvider } from "@/contexts/FolderContext";
import { MyInfoProvider } from "@/contexts/MyInfoContext";

declare global {
interface Window {
Kakao: any;
}
interface Window {
Kakao: any;
}
}

export default function App({Component, pageProps}: AppProps) {
return (
<FolderProvider>
<Component {...pageProps} />
</FolderProvider>
);
export default function App({ Component, pageProps }: AppProps) {
return (
<MyInfoProvider>
<FolderProvider>
<Component {...pageProps} />
</FolderProvider>
</MyInfoProvider>
);
}
Loading
Loading