-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
169 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import {Container} from "./Container"; | ||
import styled from "styled-components"; | ||
import {useState} from "react"; | ||
|
||
const ToDoItemContainer = styled(Container)` | ||
margin-bottom: 20px; | ||
align-item: middle; | ||
justify-content: space-between; | ||
input { | ||
color: palevioletred; | ||
height: 30px; | ||
font-size: 20px; | ||
font-weight: 500; | ||
border-radius: 5px; | ||
border: 0 solid palevioletred; | ||
max-width: 600px; | ||
width: 600px; | ||
padding-left: 5px; | ||
::placeholder { /* Chrome, Firefox, Opera, Safari 10.1+ */ | ||
color: palevioletred; | ||
opacity: 0.7; /* Firefox */ | ||
} | ||
:focus{ | ||
outline: none; | ||
} | ||
} | ||
button { | ||
text-align: right; | ||
color: white; | ||
background: palevioletred; | ||
border: none; | ||
border-radius: 8px; | ||
max-width: 200px; | ||
min-width: 100px; | ||
text-align: center; | ||
font-weight: 600; | ||
:hover { | ||
background: #ffa6c9; | ||
cursor: pointer; | ||
} | ||
} | ||
`; | ||
export default function AddToDoItem(props) { | ||
const {onChange} = props; | ||
const [inputValue, setInputValue] = useState(''); | ||
const buttonOnClick = () => { | ||
onChange && onChange(inputValue); | ||
setInputValue(''); | ||
} | ||
return (<ToDoItemContainer> | ||
<input type="text" placeholder="Add a task" autoFocus={true} value={inputValue} | ||
onChange={(event) => | ||
setInputValue(event.target.value) | ||
}/> | ||
<button onClick={buttonOnClick}>ADD</button> | ||
</ToDoItemContainer>) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import styled from "styled-components"; | ||
|
||
export const Container = styled.div` | ||
margin: 0 auto; | ||
color: palevioletred; | ||
background-color: white; | ||
padding: 10px 20px; | ||
display: flex; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,13 @@ | ||
import React, {useEffect, useState} from "react"; | ||
import React from "react"; | ||
import Item from "./Item"; | ||
|
||
export default function ItemList() { | ||
const [items, setItems] = useState([]); | ||
const onChange = (id) => { | ||
fetch('http://localhost:3001/done', { | ||
method: 'POST', | ||
headers: { | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify({id: id}) | ||
}).then(res => res.json()) | ||
.then( | ||
(result) => { | ||
setItems(result); | ||
}, | ||
(error) => { | ||
console.log(error); | ||
} | ||
) | ||
}; | ||
|
||
useEffect(() => { | ||
fetch("http://localhost:3001") | ||
.then(res => res.json()) | ||
.then( | ||
(result) => { | ||
console.log(result); | ||
setItems(result); | ||
}, | ||
(error) => { | ||
console.log(error); | ||
} | ||
) | ||
}, []); | ||
export default function ItemList(props) { | ||
const {items, onChange} = props; | ||
return (<> | ||
{items.length > 0 ? items.map((item) => { | ||
return (<Item key={item.id} item={item} onChange={() => onChange(item.id)}/>); | ||
}) : <div>You have done everything!</div>} | ||
{items.length > 0 | ||
? items.map((item) => | ||
(<Item key={item.id} item={item} onChange={() => onChange(item.id)}/>) | ||
) | ||
: <div>You have done everything!</div>} | ||
</>); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import styled from "styled-components"; | ||
import AddToDoItem from "./AddToDoItem"; | ||
import ItemList from "./ItemList"; | ||
import {useEffect, useState} from "react"; | ||
|
||
const TaskListContainer = styled.div` | ||
color: palevioletred; | ||
background-color: white; | ||
padding: 10px 20px; | ||
` | ||
const Title = styled.div` | ||
font-size: 26px; | ||
margin: 20px; | ||
line-height: 50px; | ||
height: 50px; | ||
text-align: center; | ||
` | ||
|
||
export default function ToDoList() { | ||
const [items, setItems] = useState([]); | ||
|
||
useEffect(() => { | ||
fetch("http://localhost:3001") | ||
.then(res => res.json()) | ||
.then( | ||
(result) => { | ||
console.log(result); | ||
setItems(result); | ||
}, | ||
(error) => { | ||
console.log(error); | ||
} | ||
) | ||
}, []); | ||
|
||
const onAdd = (task) => { | ||
fetch('http://localhost:3001/', { | ||
method: 'POST', | ||
headers: { | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify({task: task}) | ||
}).then(res => res.json()) | ||
.then( | ||
(result) => { | ||
setItems(result); | ||
}, | ||
(error) => { | ||
console.log(error); | ||
} | ||
) | ||
} | ||
const onChecked = (id) => { | ||
fetch('http://localhost:3001/done', { | ||
method: 'POST', | ||
headers: { | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify({id: id}) | ||
}).then(res => res.json()) | ||
.then( | ||
(result) => { | ||
setItems(result); | ||
}, | ||
(error) => { | ||
console.log(error); | ||
} | ||
) | ||
}; | ||
|
||
return (<> | ||
<Title>To-Do List</Title> | ||
<AddToDoItem onChange={onAdd}/> | ||
<TaskListContainer className="App"> | ||
<ItemList items={items} onChange={onChecked}/> | ||
</TaskListContainer> | ||
</>); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters