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주차] 노이진 미션 제출합니다. #4

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
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
Binary file added .DS_Store
Binary file not shown.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
/node_modules
package-lock.json
Copy link
Member

Choose a reason for hiding this comment

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

package-lock.json파일은 개인 프로젝트를 하는 경우(혼자 작업하는경우)에는 상관이 없지만
협업을 하는 경우에는 gitignore에 올리지 않는 것이 좋다고 합니다!!
참고자료 놓고 갈게요~!!

.DS_Store
Binary file added assets/.DS_Store
Binary file not shown.
Binary file added assets/fonts/Pretendard-Black.otf
Binary file not shown.
Binary file added assets/fonts/Pretendard-Bold.otf
Binary file not shown.
Binary file added assets/fonts/Pretendard-ExtraBold.otf
Binary file not shown.
Binary file added assets/fonts/Pretendard-ExtraLight.otf
Binary file not shown.
Binary file added assets/fonts/Pretendard-Light.otf
Binary file not shown.
Binary file added assets/fonts/Pretendard-Medium.otf
Binary file not shown.
Binary file added assets/fonts/Pretendard-Regular.otf
Binary file not shown.
Binary file added assets/fonts/Pretendard-SemiBold.otf
Binary file not shown.
Binary file added assets/fonts/Pretendard-Thin.otf
Binary file not shown.
Binary file added assets/fonts/PretendardVariable.ttf
Binary file not shown.
29,475 changes: 0 additions & 29,475 deletions package-lock.json

This file was deleted.

9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.4.2",
"@fortawesome/free-brands-svg-icons": "^6.4.2",
"@fortawesome/free-regular-svg-icons": "^6.4.2",
"@fortawesome/free-solid-svg-icons": "^6.4.2",
"@fortawesome/react-fontawesome": "^0.2.0",
"@react-navigation/native": "^6.1.7",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"date-fns": "^2.30.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.16.0",
"react-scripts": "5.0.1",
"styled-components": "^6.0.8",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand Down
Binary file modified public/favicon.ico
Copy link

Choose a reason for hiding this comment

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

파비콘이 귀엽습니다..!

Binary file not shown.
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
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`.
-->
<title>React App</title>
<title>react-todo-18th</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
10 changes: 5 additions & 5 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from "react";
import Todo from "./components/Todo";
import "./index.css";

function App() {
return (
<div>
<h1>18기 프론트 화이팅~ 푸하항ㅋ</h1>
</div>
);
return <Todo />;
}

export default App;
27 changes: 27 additions & 0 deletions src/components/Clock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React, { useEffect, useState } from "react";
import styled from "styled-components";
import { format } from "date-fns";
Copy link
Member

Choose a reason for hiding this comment

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

저는 Date, time관련해서는 moment 라이브러리를 애용하는데, date-fns는 처음 보는 라이브러리여서 흥미로워서 조금 찾아봤습니다. 리뷰하러오신 다른 분들을 위해 공식문서 놓고갈게요~!


const ClockText = styled.span`
font-family: "Pretendard-SemiBold";
font-size: 13px;
text-align: center;
line-height: 1.5em;
margin-top: 5px;
`;

export default function Clock() {
const [now, setNow] = useState(new Date());

//1초마다 now 다시 set
useEffect(() => {
const time = setInterval(() => {
setNow(new Date());
Copy link
Member

Choose a reason for hiding this comment

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

이 부분은 매초 Date객체를 생성하는데, 기존의 time에서 1초를 더해주는 코드로 대체해도 괜찮을 것 같아요~!

}, 1000);
return () => clearInterval(time);
}, []);

let clockFormat = format(now, "hh:mm aa");

return <ClockText>{clockFormat}</ClockText>;
}
41 changes: 41 additions & 0 deletions src/components/DailyDate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from "react";
import styled from "styled-components";
import { format } from "date-fns";

Choose a reason for hiding this comment

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

오오 date-fns 처음 보는데, 저도 다음에 한 번 date-fns 써봐야겠어요!


const DateField = styled.div`
display: flex;
width: 100%;
height: 10%;
background-color: #e0e0e0;
color: #302e2e;
border: 0.5px solid #736e6e;
margin-bottom: 5px;
border-radius: 10px;
align-items: center;
justify-content: center;
box-sizing: border-box;
`;

const DateText = styled.span`
font-family: "Pretendard-SemiBold";
letter-spacing: 1px;

Choose a reason for hiding this comment

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

디테일....👍🏻

font-size: 13px;
padding-top: 3px;
`;

export default function DailyDate() {
Copy link
Member

Choose a reason for hiding this comment

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

function문법도 문제 없지만 더 최신 문법인 ES6의 arrow function을 써보는 것을 추천드려요~!

const week = new Array("sun", "mon", "tue", "wed", "thu", "fri", "sat");

const now = new Date();
const day = week[now.getDay()];

let formatDate = format(now, "yyyy-MM-dd");

return (
<DateField>
<DateText>
{formatDate} {day}
</DateText>
</DateField>
);
}
79 changes: 79 additions & 0 deletions src/components/InputItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import React from "react";
Copy link
Member

Choose a reason for hiding this comment

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

REACT17이 release되면서 이제 더이상 모든 파일에서 React를 import하지 않아도 된다고 합니다 🚀
stack overflow
오히려 매 파일에서 react를 import하면 performance가 나빠질 수도 있다고 해요!

Choose a reason for hiding this comment

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

그렇군요.. 저도 배워갑니당:)

import styled from "styled-components";
import { useState, useCallback } from "react";

const Container = styled.form`
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 5px;
background-color: #e0e0e0;
border-radius: 10px;
padding: 5px;
height: 10%;
box-sizing: border-box;
border: 0.5px solid #736e6e;
`;

const InputField = styled.input`
width: 90%;
padding: 3px;
border: none;
border-bottom: 1px solid #555252;
background-color: transparent;
color: #555252;
font-family: "Pretendard-Regular";
margin-left: 3px;
box-sizing: border-box;
&:focus {
outline-style: none;
}
`;

const AddButton = styled.button`
margin-top: 3px;
width: 20px;
height: 30px;
background-color: transparent;
color: #555252;
border: none;
border-radius: 50%;
cursor: pointer;
`;

export default function TodoInput({ createTodo }) {
const [value, setValue] = useState("");

const onChange = useCallback(
Copy link

Choose a reason for hiding this comment

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

useCallback을 사용해본 적이 없는데, 앞으로 성능 측면도 고려하며 구현해보겠습니다! 새로 배워갑니다 👍

(e) => {
setValue(e.target.value);
},
[value]
);
Comment on lines +47 to +52
Copy link
Member

Choose a reason for hiding this comment

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

useCallback의 두번째 인자에 value를 dependency로 넣어주셨는데,
onChange가 value값에 의존하고 있지 않는 것 같아서 빈 배열을 넣어주거나,
useCallback을 제거하고 일반 함수로 써도 performance에 큰 영향을 주지 않을 것 같아요
set함수가 매우 가벼운 함수기도 해서요!!


const onSubmit = useCallback(
(e) => {
e.preventDefault();

//입력한 값이 없을 때 alert 추가
if (value.trim() == "") {
alert("할일을 입력해주세요.");
} else {
createTodo(value);
setValue("");
}
},
[value]
);

return (
<Container onSubmit={onSubmit}>
<InputField
onChange={onChange}
value={value}
placeholder="할 일을 입력하세요"
/>
<AddButton type="submit">+</AddButton>
</Container>
);
}
81 changes: 81 additions & 0 deletions src/components/ListItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import React from "react";
import styled from "styled-components";
import { faCircle, faCircleCheck } from "@fortawesome/free-regular-svg-icons";
import { faTrashCan, faRotateLeft } from "@fortawesome/free-solid-svg-icons";
Comment on lines +3 to +4
Copy link
Member

Choose a reason for hiding this comment

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

fa icon들을 더 편하게 불러올 수 있는 react-icons 라이브러리가 있답니다!! 이를 사용해도 좋을 것같아요!
공식 docs

import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";

const Item = styled.div`
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 5px;
Copy link
Member

Choose a reason for hiding this comment

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

사용자의 더 나은 경험 (UX)를 위해 최근 rem단위를 더 선호하고 있다고 합니다!
저도 처음에는 px단위를 쓰는것이 너무나 편했는데, 최근 rem이 더 선호되고 있다고 하니... 연습해보아도 좋을 것 같아요!
참고자료

Choose a reason for hiding this comment

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

리스트 아이템들이 이동 아이콘 바로 옆쪽에 왼쪽으로 정렬되면 더 보기 편할 것 같아요!

width: 100%;
box-sizing: border-box;
cursor: pointer;
`;

const ItemText = styled.span`
font-family: "Pretendard-Regular";
font-size: 13px;
margin: 3px 8px 0px 8px;
`;

const ClickedText = styled.span`
font-family: "Pretendard-Regular";
font-size: 13px;
margin: 3px 8px 0px 8px;
text-decoration: line-through;
Copy link
Member

Choose a reason for hiding this comment

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

취소선 디테일 좋습니다 👏👍

`;

const IconBox = styled.div`
display: flex;
`;

export default function ListItem({ input, onClick, isClicked, deleteList }) {
//삭제할 때 alert
const OpenConfirm = () => {
if (window.confirm("정말 삭제하시겠습니까?")) {
deleteList();
}
};
Comment on lines +36 to +40
Copy link

Choose a reason for hiding this comment

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

항상 alert를 이용해서 메세지 창을 띄웠는데 새로운 방법이네요! 또 배워갑니다 👍


return (
<Item>
{isClicked ? (
<FontAwesomeIcon icon={faCircleCheck} style={{ height: 13 }} />
) : (
<FontAwesomeIcon
onClick={onClick}
icon={faCircle}
style={{ height: 13 }}
/>
)}
{isClicked ? (
<ClickedText>{input}</ClickedText>
) : (
<ItemText>{input}</ItemText>
)}

{isClicked ? (
<IconBox>
<FontAwesomeIcon
icon={faRotateLeft}
style={{ height: 13, marginRight: 3 }}
onClick={onClick}
/>
<FontAwesomeIcon
icon={faTrashCan}
style={{ height: 13 }}
onClick={OpenConfirm}
/>
</IconBox>
) : (
<FontAwesomeIcon
icon={faTrashCan}
style={{ height: 13 }}
onClick={OpenConfirm}
/>
)}
</Item>
);
}
Loading