Skip to content
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 src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import TodoEmpty from "./component/TodoEmpty"
import TodoHeader from "./component/TodoHeader"
import TodoList from "./component/TodoList"

Expand All @@ -7,6 +8,9 @@ function App() {
<div className="flex flex-col w-[640px] mt-[80px] ml-[445px] mr-[464px] gap-[22px]">
<TodoHeader />
<TodoList />

<TodoHeader />
<TodoEmpty />
Comment on lines 9 to +13
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

다음주에는 이 부분을 리스트의 길이에 따라 분기처리 해주시면 좋을것같아요

</div>
</>

Expand Down
10 changes: 10 additions & 0 deletions src/assets/Check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/assets/hero.png
Binary file not shown.
1 change: 0 additions & 1 deletion src/assets/react.svg

This file was deleted.

1 change: 0 additions & 1 deletion src/assets/vite.svg

This file was deleted.

34 changes: 31 additions & 3 deletions src/component/TodoCard.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
import { useState } from "react";
import checkIcon from "../assets/Check.svg";

interface TodoCardProps {
content: string;
checked?: boolean;
}

export default function TodoCard({ content }: TodoCardProps) {
export default function TodoCard({ content, checked = false }: TodoCardProps) {
const [isChecked, setIsChecked] = useState(checked)

const toggleCheck = () => {
setIsChecked(!isChecked);
};
Comment on lines +10 to +14
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

이번주 읽을 거리에서 다룬 내용은 아니긴 한데, 이전 상태를 기준으로 토글하는 업데이트라면 setIsChecked(!isChecked) 보다는 setIsChecked(prev => !prev) 형태가 의도도 더 분명하고 React 상태 업데이트 패턴에도 더 자연스럽습니다.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

오 좋은 정보 감사합니다~! 다음에 반영해보도록 하겠습니다!


return (
<li className="flex p-[16px] gap-[10px] items-start self-stretch bg-card rounded-[12px] shadow-[0_1px_3px_0_rgba(0,0,0,0.10)]">
<p className="text-body leading-[21px]">{content}</p>
<li
onClick={toggleCheck}
className="flex p-[16px] gap-[10px] items-center self-stretch bg-card rounded-[12px] shadow-[0_1px_3px_0_rgba(0,0,0,0.10)]"
>
<div className={`w-6 h-6 flex items-center justify-center border-[2px] rounded-full transition-colors ${
isChecked
? 'bg-primary/40 border-primary/0'
: 'bg-white border-border'
}`}>
{isChecked && (
<img src={checkIcon} alt="done" className="w-[14px] h-[10px]" />
)}

</div>
<p className={`text-body leading-[21px] transition-all ${
isChecked ? 'line-through text-gray-400 opacity-60' : 'text-gray-900'
}`}
>
{content}
</p>
</li>
Comment on lines +17 to 37
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

todolist의 완료 토글은 의미상 input type ckeckbox와 유사하여 input으로 리팩토링을 고려해보면 좋을 것같아요

)
}
10 changes: 10 additions & 0 deletions src/component/TodoEmpty.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default function TodoEmpty() {
return (
<div className="flex flex-col w-[640px] pt-[64px] h-[233px] gap-3 justify-start items-center bg-white rounded-[12px]">
<p className="text-[48px] leading-[72px]">📋</p>
<p className="text-gray-400 text-body leading-[21px]">
아직 할 일이 없어요
</p>
</div>
);
}
25 changes: 20 additions & 5 deletions src/component/TodoList.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
import TodoCard from "./TodoCard";
import TodoEmpty from "./TodoEmpty";

export default function TodoList() {

const todos = [
{ id: 1, content: "리액트 공식문서 읽기" },
{ id: 2, content: "알고리즘 문제 풀기" },
{ id: 3, content: "운동 30분 하기" },
{ id: 4, content: "프로젝트 회의 준비" },
];

if (todos.length === 0) {
return <TodoEmpty />;
}

return (
<ul className="flex flex-col items-start gap-[16px] self-stretch">
<TodoCard content="리액트 공식문서 읽기" />
<TodoCard content="알고리즘 문제 풀기" />
<TodoCard content="운동 30분 하기" />
<TodoCard content="프로젝트 회의 준비" />
<ul className="flex flex-col items-start gap-4 self-stretch">
{todos.map((todo) => (
<TodoCard
key={todo.id}
content={todo.content}
/>
))}
Comment on lines +6 to +24
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

이번 주 과제는 완료 여부를 props로 넘겨서 각 항목이 처음부터 다른 상태로 보이도록 만드는 것이 핵심인데, 현재 TodoCardchecked 값을 넘기지 않고 있어서 초기 렌더링에서는 모든 항목이 동일하게 보입니다. 완료/미완료 상태가 데이터 단계에서 바로 반영되도록 연결해주시면 좋겠습니다.

</ul>
)
}