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주차] 변지혜 미션 제출합니다. #3

Open
wants to merge 11 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
482 changes: 449 additions & 33 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"@testing-library/user-event": "^13.5.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
Binary file not shown.
21 changes: 1 addition & 20 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,10 @@
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`.
-->
<title>React App</title>
<title>TODOLIST</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>
Binary file removed public/logo192.png
Binary file not shown.
Binary file removed public/logo512.png
Binary file not shown.
25 changes: 0 additions & 25 deletions public/manifest.json

This file was deleted.

3 changes: 0 additions & 3 deletions public/robots.txt

This file was deleted.

14 changes: 9 additions & 5 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import React from "react";
import styled from "styled-components";
import TodoTemplate from "./TodoTemplate";

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

export default App;
125 changes: 125 additions & 0 deletions src/TodoTemplate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import React, { useState } from "react";
import styled from "styled-components";
import GlobalStyle from "./styles/GlobalStyle";

import TodoTopbar from "./components/TodoTopbar";
import TodoListItem from "./components/TodoListItem";

function TodoTemplate() {
//todo
const initialTodoData = localStorage.getItem("list")
? JSON.parse(localStorage.getItem("list"))
: [];

const [list, setList] = useState(initialTodoData);
const [value, setValue] = useState("");

const deleteTodo = (id) => {
let deletedTodo = list.filter((data) => data.id !== id);
setList(deletedTodo);
localStorage.setItem("list", JSON.stringify(deletedTodo));
};

const toggleTodo = (id) => {
let toggledTodo = list.map((data) =>
data.id === id ? { ...data, completed: !data.completed } : data
);
setList(toggledTodo);
localStorage.setItem("list", JSON.stringify(toggledTodo));
};

return (
<>
<GlobalStyle />
<TodoTopbar
list={list}
value={value}
setList={setList}
setValue={setValue}
/>
<TodoContainer>
<article>
<h3 class="list-title">TODO</h3>
<div class="todo-list">
{list.map((data) =>
data.completed ? (
<></>
) : (
<TodoListItem
key={data.id}
todo={data}
deleteTodo={deleteTodo}
toggleTodo={toggleTodo}
/>
)
)}
Comment on lines +44 to +55
Copy link

Choose a reason for hiding this comment

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

저는 completed 기준으로 todolist, donelist 따로 array를 저장한 후에 map 함수를 사용하였는데, 삼항연산자를 이용해서 예외처리를 하는 방법도 좋은 방법인거 같습니다!

</div>
</article>
<article>
<h3 class="list-title">DONE</h3>
<div class="done-list">
{list.map((data) =>
data.completed ? (
<TodoListItem
key={data.id}
todo={data}
deleteTodo={deleteTodo}
toggleTodo={toggleTodo}
/>
) : (
<></>
)
)}
</div>
</article>
</TodoContainer>
</>
);
}

export default TodoTemplate;

const TodoContainer = styled.section`
display: grid;
grid-template-columns: 1fr 1fr;
justify-content: center;

min-height: 18.75em;
max-width: 60%;

border-radius: 2.125em;
border: 0.1875em solid #7adb84;
padding: 0.3125em 0.625em;
margin: 0.625em auto;

position: relative;

.list-title {
margin: 0.625em 0 0.625em 0.3125em;
font-family: "Pretendard-Regular";
color: #00c013;
}

.todo-list,
.done-list {
list-style: none;
margin: 0 0 0.625em;
padding: 0 1.875em 0 0.625em;

max-height: 18em;
overflow-y: scroll;

&::-webkit-scrollbar {
width: 5px;
}

&::-webkit-scrollbar-thumb {
background: #7adb84;
border-radius: 1.875em;
}
Comment on lines +116 to +119
Copy link

Choose a reason for hiding this comment

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

스크롤바까지 디테일 신경쓴게 아주 좋습니다!!


&::-webkit-scrollbar-track {
background-color: transparent;
}
}
`;
72 changes: 72 additions & 0 deletions src/components/TodoListItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import React from "react";
import styled from "styled-components";

import del from "../images/delete.png";
import check from "../images/checkbox.png";
import done from "../images/donebox.png";

function TodoListItem({ todo, deleteTodo, toggleTodo }) {
return (
<ListItem>
<IsDoneBox
onClick={() => toggleTodo(todo.id)}
src={todo.completed ? done : check}
></IsDoneBox>
<TodoText onClick={() => toggleTodo(todo.id)}>{todo.title}</TodoText>
<TodoDel src={del} onClick={() => deleteTodo(todo.id)} />
</ListItem>
);
}

export default TodoListItem;

const ListItem = styled.div`
display: flex;
justify-content: space-between;
align-items: center;

padding: 0.1875em 0;
transition: color 0.3s;
color: #000;
font-family: "SUITE-Regular";
font-size: 0.75em;
cursor: pointer;

&:hover {
color: #4caf50;
}
`;

const TodoText = styled.span`
width: 100%;
max-width: 100%;
white-space: normal;
overflow: hidden;
text-overflow: ellipsis;
`;

Choose a reason for hiding this comment

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

제가 리뷰받았던 내용인데, word-break: break-all;를 추가해 영어길이가 길어졌을 때, 깨지는 것을 방지하는 것이 좋을 것 같아요!

const IsDoneBox = styled.img`
width: 1.25em;
height: 1.25em;
padding-right: 1em;
border: none;
border-radius: 0.3125em;
background-color: transparent;
cursor: pointer;
`;

const TodoDel = styled.img`
width: 1.25em;
height: 1.25em;
padding: 0;
border: none;
border-radius: 0.3125em;
background-color: transparent;
cursor: pointer;

opacity: 0;
transition: opacity 0.3s;
${ListItem}:hover & {
opacity: 1;
}
`;

Choose a reason for hiding this comment

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

퍼센트와 rem을 잘 다루시는 것 같아요. 멋지고 부럽습니다

Loading