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

Part2 장성훈 week12 #406

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
4 changes: 4 additions & 0 deletions .gitignore → 1-weekly-mission-week9-main/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

# misc
.DS_Store
.env
.env.local
.env.development.local
.env.test.local
Expand All @@ -21,3 +22,6 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# editor directories and files
.vscode
File renamed without changes.
480 changes: 245 additions & 235 deletions package-lock.json → ...ekly-mission-week9-main/package-lock.json

Large diffs are not rendered by default.

20 changes: 15 additions & 5 deletions package.json → 1-weekly-mission-week9-main/package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
{
"name": "1-weekly-mission",
"name": "weekly-mission-react",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"date-fns": "^3.6.0",
"axios": "^1.5.1",
"classnames": "^2.3.2",
"date-fns": "^2.30.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^5.0.1",
"react-router-dom": "^6.22.3",
"react-router-dom": "^6.17.0",
"react-scripts": "5.0.1",
"styled-components": "^6.1.8"
"sass": "^1.69.4",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
Expand All @@ -37,5 +39,13 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@babel/preset-typescript": "^7.24.1",
"@types/node": "^20.12.11",
"@types/react": "^18.3.1",
"@types/react-dom": "^18.3.0",
"typescript": "^5.4.5"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions 1-weekly-mission-week9-main/public/images/check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions 1-weekly-mission-week9-main/public/images/close.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions 1-weekly-mission-week9-main/public/images/facebook.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions 1-weekly-mission-week9-main/public/images/instagram.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions 1-weekly-mission-week9-main/public/images/kebab.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions 1-weekly-mission-week9-main/public/images/link.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions 1-weekly-mission-week9-main/public/images/pen.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions 1-weekly-mission-week9-main/public/images/search.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions 1-weekly-mission-week9-main/public/images/share.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions 1-weekly-mission-week9-main/public/images/star.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions 1-weekly-mission-week9-main/public/images/trash.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions 1-weekly-mission-week9-main/public/images/twitter.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions 1-weekly-mission-week9-main/public/images/youtube.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions 1-weekly-mission-week9-main/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8" />
<title>Linkbrary</title>
<meta property="og:title" content="Linkbrary" key="title" />
<meta
name="description"
property="og:description"
content="세상의 모든 정보를 쉽게 저장하고 관리해 보세요"
key="description"
/>
<meta
property="og:image"
content="https://visitbusan.net/uploadImgs/files/cntnts/20211130150754165_wufrotr"
key="image"
/>
<meta
name="viewport"
content="width=device-width,minimum-scale=1,initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<link
rel="stylesheet"
type="text/css"
href="https://cdn.jsdelivr.net/gh/orioncactus/pretendard/dist/web/static/pretendard.css"
/>
</head>
<body>
<div id="root"></div>
</body>
</html>
17 changes: 17 additions & 0 deletions 1-weekly-mission-week9-main/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'sharing/styles/reset.css';
import { BrowserRouter, Route, Routes } from 'react-router-dom';
import { SharedPage } from 'pages/SharedPage';
import { FolderPage } from 'pages/FolderPage';

function App() {
return (
<BrowserRouter>
<Routes>
<Route path="/shared" element={<SharedPage />} />
<Route path="/folder" element={<FolderPage />} />
</Routes>
</BrowserRouter>
);
}

export default App;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./useGetFolder";
export * from "./useGetFolders";
Copy link
Collaborator

Choose a reason for hiding this comment

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

호오 hasOwnProperty 쓴거 좋습니다 ㅎ근데 위 조건일때만 값을 반환하는건 문제가 있을것 같아요
useGetFolder는 항상 loading, error, data상태는 반환해야 useGetFolder를 사용하는 쪽에서 문제가 없을것 같습니다
mapFolderData()를 꼭 사용해야만 한다면

if (data && data.hasOwnProperty('folder')) {
    const folderData = mapFolderData(data);
}

구문은 useGetFolder안이 아니라 useGetFolder 를 선언하는 쪽에서 사용하는게 좋을것 같네요 ㅎ

Component = ()=> {
const [folderData,setFolderData]=useState(null)
const {data,loading,error} = useGetFolder()

if (data && data.hasOwnProperty('folder')) {
    setFolderData(mapFolderData(data))
}

return <div> ...
}

이렇게요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { mapFolderData } from 'folder/util-map';
import { useAsync } from 'sharing/util';
import { axiosInstance } from 'sharing/util';
import { Folder } from 'sharing/util';

export const useGetFolder = () => {
const getFolder = () => axiosInstance.get('sample/folder');
const { loading, error, data } = useAsync<Folder>(getFolder);
if (data && data.hasOwnProperty('folder')) {
const folderData = mapFolderData(data);

return { loading, error, data: folderData };
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { axiosInstance } from 'sharing/util';
import { useAsync } from 'sharing/util';

export interface Folders {
data: {
id: number;
created_at: string;
name: string;
user_id: number;
favorite: boolean;
link: {
count: number;
};
}[];
}

export const useGetFolders = () => {
const getFolders = () => axiosInstance.get('users/1/folders');
const { loading, error, data } = useAsync<Folders>(getFolders);
if (data) {
const folders = data.data;
const sortedFolders = folders.sort((a, b) => a.id - b.id);

return { loading, error, data: sortedFolders };
}
return;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
@import "sharing/styles/global.scss";

.container {
display: flex;
flex-direction: column;
align-items: flex-start;
row-gap: 1.2rem;

@include tablet {
display: grid;
grid-template-areas:
"folders folders add-button"
"folder-name buttons buttons";
justify-content: space-between;
align-items: center;
row-gap: 2.4rem;
column-gap: 1.2rem;
}
}

.folders {
grid-area: folders;
display: flex;
flex-wrap: wrap;
column-gap: 0.8rem;
row-gap: 1.2rem;
flex-grow: 1;
}

.add-button {
grid-area: add-button;

position: fixed;
bottom: 10.1rem;
left: 50%;
transform: translateX(-50%);
z-index: $z-index-fab;

@include tablet {
justify-self: flex-end;

position: static;
transform: none;
}
}

.folder-name {
grid-area: folder-name;
margin-top: 1.6rem;
font-size: 2rem;
font-weight: 600;
letter-spacing: -0.02rem;

@include tablet {
margin-top: 0;
font-size: 2.4rem;
}
}

.buttons {
justify-self: flex-start;
grid-area: buttons;
display: flex;
column-gap: 1.2rem;

@include tablet {
justify-self: flex-end;
}
}
Loading
Loading