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

[2주차] 권가은 미션 제출합니다. #5

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 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
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": true,
"singleQuote": true
}
228 changes: 221 additions & 7 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"styled-components": "^5.3.9",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand Down
Binary file removed public/favicon.ico
Binary file not shown.
Binary file added public/favicon.png
Copy link
Member

Choose a reason for hiding this comment

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

약속의 파비콘ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ

이분꺼 업데이트된 (님들이) 만들어 쓰는 개발진스입니당

Copy link
Member

Choose a reason for hiding this comment

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

ㅋㅋㅋㅋㅋㅋ 파비콘 보자마자 리뷰하러 왔는데 역씨... 😸

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 2 additions & 25 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,19 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<link rel="icon" href="%PUBLIC_URL%/favicon.png" />
Copy link
Member

Choose a reason for hiding this comment

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

파비콘을 쓸 때는 png를 넣는것보다 확장자 변경 사이트에서 ico 확장자로 변경해서 넣는게 좋다고합니다!!
링크

Copy link
Member Author

Choose a reason for hiding this comment

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

오 ico 확장자를 사용해서 여러개 사이즈를 정해두면 해상도 문제 없이 사용할 수 있겠네요!
자료 첨부까지 감사합니다 👍👍

Choose a reason for hiding this comment

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

우와웅 저도 이건 처음 알았어요!! 좋은 정보 감사합니다💪🏻

<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
11 changes: 5 additions & 6 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import styled from 'styled-components';
import TodoList from './pages/TodoList';

function App() {
return (
<div>
<h1>17기 프론트 화이팅~ 우하하</h1>
</div>
);
return <TodoList />;
}

export default App;
export default App;
100 changes: 100 additions & 0 deletions src/components/ListContainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import PropTypes from 'prop-types';
import styled from 'styled-components';
import { TODOKEY } from '../constants/TODOKEY';

const ListContainer = ({
title,
todoList,
setTodoList,
isDone,
setIsVisibleModal, // 컴포넌트 재사용성이 낮아지는 것 같은데.. 우짜지
setSelectedTodo, // 컴포넌트 재사용성이 낮아지는 것 같은데.. 우짜지
Copy link
Member

Choose a reason for hiding this comment

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

재사용성이 낮아진다는것...이 뭔지 저도 잘 모르겠어서 이번주 스터디까지 한번 공부해보고 얘기 해보면 좋을 것 같습니다...ㅎㅎ 댓글로 다른분들이 알려주시면 공부 해가도록 할게요 😄

Copy link
Member

Choose a reason for hiding this comment

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

좋은 방법인진 모르겠지만... setIsVisibleModal, setSelectedTodo 등의 함수를 사용하는 Listcontainer 컴포넌트의 부모 컴포넌트를 따로 만들고, ListContainer 컴포넌트에 prop으로 내려 주는 방법도 있을 것 같아요!

const ListContainer = ({ title, todoList, isDone, onToggleIsDone, onDeleteTodo }) => {
...
const ParentComponent = () => {
  const [isVisibleModal, setIsVisibleModal] = useState(false);
  const [selectedTodo, setSelectedTodo] = useState(null);
  const [todoList, setTodoList] = useState([]);

  const onToggleIsDone = (todo) => {
...

Copy link
Member Author

Choose a reason for hiding this comment

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

여러 페이지에서 재사용이 많이 되는 컴포넌트의 경우 이런식으로 분리해보면 좋을 것 같아요! 👍👍

}) => {
const toggleIsDone = (e) => {
const tempList = [...todoList];
tempList.forEach((todo) => {
if (todo.time === e.target.parentElement.id) {
todo.isDone = !todo.isDone;
}
});
setTodoList(tempList);

localStorage.setItem(TODOKEY, JSON.stringify(tempList));
Copy link
Member

Choose a reason for hiding this comment

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

옹... TODOKEY로 localStorage에 넣어주는 방법 되게 좋은 것 같아요..!

Copy link
Member Author

Choose a reason for hiding this comment

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

string value는 최대한 변수로 만들어두고 사용하는 게 오류 사전 방지, 유지보수 측면에서 좋은 것 같아 이렇게 사용하고 있습니다! ㅎㅎ

Choose a reason for hiding this comment

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

저도 string으로 사용했었는데 변수로 만들어 두는 것이 더 좋겠네요!! 이렇게 또 배워갑니다ㅠㅠ👏🏻👏🏻👏🏻

};

const handleBtnClick = (e) => {
setSelectedTodo(e.target.parentElement);
setIsVisibleModal(true);
};

return (
<Wrapper>
<Title>{title}</Title>
<Lists>
{todoList
.filter((todo) => todo.isDone === isDone)
.map((todo) => {
return (
<SingleList id={todo.time} key={todo.time}>
<span onClick={toggleIsDone}>{todo.text}</span>
<button onClick={handleBtnClick}>🗑</button>
</SingleList>
);
})}
</Lists>
</Wrapper>
);
};

ListContainer.propTypes = {
title: PropTypes.string,
todoList: PropTypes.array,
setTodoList: PropTypes.func,
isDone: PropTypes.bool,
setIsVisibleModal: PropTypes.func,
setSelectedTodo: PropTypes.func,
};
Comment on lines +49 to +56
Copy link
Member

Choose a reason for hiding this comment

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

propTypes를 쓰는 건 처음 봤네요. typesciprt에서만 사용하는 줄 알았는데 js에서도 사용할 수 있다는걸 알아갑니다!

Copy link
Member Author

Choose a reason for hiding this comment

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

TS를 사용하다가 이번 과제를 하며 JS로 하려니 역체감을 느꼈어요..
그래서 기존에 JS로 React 사용 시에는 propTypes 사용을 빼먹기도 했는데 이번에는 감사하며(?) 사용했습니다. 😂
타입 체크는 협업과 유지보수에도 특히 도움이 될 것 같습니다. ㅎㅎ

Copy link
Member

Choose a reason for hiding this comment

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

타입 체크까지... 짱~~ 앞으로 진행될 타입스크립트 과제들이 기대가 되네요 🥰


const Wrapper = styled.div`
height: 33%;
display: flex;
flex-direction: column;
`;

const Title = styled.span`
user-select: none;
`;

const Lists = styled.div`
padding: 0.6rem;
overflow: auto;
`;

const SingleList = styled.div`
width: 100%;
padding: 0.1rem 0;
display: flex;

&:hover {
border-radius: 0.3rem;
background-color: rgb(239, 239, 248);
}

span {
&:hover {
cursor: pointer;
}
}

button {
margin: 0 0 0 auto;
background-color: transparent;
border: none;

&:hover {
cursor: pointer;
}
}
`;

export default ListContainer;
2 changes: 2 additions & 0 deletions src/constants/TODOKEY.js
Copy link
Member

Choose a reason for hiding this comment

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

key를 따로 관리하는 방식 좋네요 🥰

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const TODOKEY = 'todo';
export { TODOKEY };
25 changes: 25 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@font-face {
font-family: 'Pretendard-Regular';
src: url('https://cdn.jsdelivr.net/gh/Project-Noonnu/[email protected]/Pretendard-Regular.woff')
format('woff');
}

body {
width: 100vw;
height: 100vh;
margin: 0;
background-color: lavender;

font-family: 'Pretendard-Regular';
font-weight: 400;
font-style: normal;
font-size: 1rem;
}
Comment on lines +7 to +17

Choose a reason for hiding this comment

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

가은님은 css 단위를 항상 잘 쓰시는 것 같아요!! vw부터 vh, rem 등등.. 저는 px, % 등의 익숙한 단위들만 사용하다 보니 종종 불편할 때가 있더라구요ㅠㅠ 가은님처럼 상황에 맞는 적절한 단위를 사용하는 것이 더 효율적일 것 같네요!!!👏🏻👏🏻


#root {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
11 changes: 6 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react';
import ReactDOM from 'react-dom';
import ReactDOM from 'react-dom/client';
import App from './App';

ReactDOM.render(
import './index.css';

ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
</React.StrictMode>
);
Loading