Skip to content
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 aula22/__MACOSX/._boiler-plate
Binary file not shown.
Binary file added aula22/__MACOSX/boiler-plate/._.DS_Store
Binary file not shown.
Binary file added aula22/__MACOSX/boiler-plate/._package-lock.json
Binary file not shown.
Binary file added aula22/__MACOSX/boiler-plate/._package.json
Binary file not shown.
Binary file added aula22/__MACOSX/boiler-plate/._public
Binary file not shown.
Binary file added aula22/__MACOSX/boiler-plate/._src
Binary file not shown.
Binary file added aula22/__MACOSX/boiler-plate/public/._index.html
Binary file not shown.
Binary file added aula22/__MACOSX/boiler-plate/src/._.DS_Store
Binary file not shown.
Binary file added aula22/__MACOSX/boiler-plate/src/._App.js
Binary file not shown.
Binary file added aula22/__MACOSX/boiler-plate/src/._index.js
Binary file not shown.
Binary file added aula22/__MACOSX/boiler-plate/src/._styles.css
Binary file not shown.
Binary file added aula22/boiler-plate.zip
Binary file not shown.
Binary file added aula22/boiler-plate/.DS_Store
Binary file not shown.
13,314 changes: 13,314 additions & 0 deletions aula22/boiler-plate/package-lock.json

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions aula22/boiler-plate/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "lista-tarefas",
"version": "1.0.0",
"description": "",
"keywords": [],
"main": "src/index.js",
"dependencies": {
"react": "16.8.6",
"react-dom": "16.8.6",
"react-scripts": "3.0.1",
"styled-components": "4.4.1"
},
"devDependencies": {
"typescript": "3.3.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
43 changes: 43 additions & 0 deletions aula22/boiler-plate/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<!--
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!--
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>
</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 added aula22/boiler-plate/src/.DS_Store
Binary file not shown.
127 changes: 127 additions & 0 deletions aula22/boiler-plate/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import React from 'react'
import styled from 'styled-components'
import './styles.css'

const TarefaList = styled.ul`
padding: 0;
width: 200px;
`

const Tarefa = styled.li`
text-align: left;
text-decoration: ${({completa}) => (completa ? 'line-through' : 'none')};
`

const InputsContainer = styled.div`
display: grid;
grid-auto-flow: column;
gap: 10px;
`

class App extends React.Component {
state = {
tarefas: [{
id: Date.now(),
texto: 'Texto da primeira tarefa',
completa: false
},
// {
// id: Date.now(), // Explicação abaixo
// texto: 'Texto da segunda tarefa',
// completa: true
// }
],
inputValue: '',
filtro: 'completas'
}

componentDidUpdate() {
localStorage.setItem('tarefas', JSON.stringify(this.state.tarefas)) // JSON.stringify converte um array em string
};

componentDidMount() {
const dados = localStorage.getItem('tarefas')
if(dados){
this.setState({...this.state, tarefas: JSON.parse(dados)}) // JSON.parse converte uma string em array
}
};

onChangeInput = (event) => {
this.setState({...this.state, inputValue: event.target.value})
}

criaTarefa = () => {
const tarefa = {
id: Date.now(),
texto: this.state.inputValue,
completa: false
}

const copiaDoEstado = [...this.state.tarefas, tarefa]
this.setState({...this.state, tarefas: copiaDoEstado})
}

selectTarefa = (id) => {
const copiaDoEstado = [...this.state.tarefas]

const arrayModificado = copiaDoEstado.map((item) => {
return {
...item,
completa: item.id === id ? !item.completa : item.completa,
}
})

this.setState({...this.state, tarefas: arrayModificado})
}

onChangeFilter = (event) => {
this.setState({...this.state, filtro: event.target.value})
}

render() {
const listaFiltrada = this.state.tarefas.filter(tarefa => {
switch (this.state.filtro) {
case 'pendentes':
return !tarefa.completa
case 'completas':
return tarefa.completa
default:
return true
}
})

return (
<div className="App">
<h1>Lista de tarefas</h1>
<InputsContainer>
<input value={this.state.inputValue} onChange={this.onChangeInput}/>
<button onClick={this.criaTarefa}>Adicionar</button>
</InputsContainer>
<br/>

<InputsContainer>
<label>Filtro</label>
<select value={this.state.filter} onChange={this.onChangeFilter}>
<option value="">Nenhum</option>
<option value="pendentes">Pendentes</option>
<option value="completas">Completas</option>
</select>
</InputsContainer>
<TarefaList>
{listaFiltrada.map(tarefa => {
return (
<Tarefa
completa={tarefa.completa}
onClick={() => this.selectTarefa(tarefa.id)}
>
{tarefa.texto}
</Tarefa>
)
})}
</TarefaList>
</div>
)
}
}

export default App
6 changes: 6 additions & 0 deletions aula22/boiler-plate/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from "react";
import ReactDOM from "react-dom";
import App from './App'

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
7 changes: 7 additions & 0 deletions aula22/boiler-plate/src/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.App {
font-family: sans-serif;
text-align: center;
display: flex;
flex-direction: column;
align-items: center;
}
3 changes: 3 additions & 0 deletions aula22/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.