-
Notifications
You must be signed in to change notification settings - Fork 46
Solution: Jon Garcia y Sebastian Burpbacher #14
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
base: main
Are you sure you want to change the base?
Changes from all commits
72801e3
e4e8baa
ae04883
36cf745
cda414a
8b0b74a
415c6f7
29e44a5
022e123
02c3dd0
c026c4e
58281db
ac780f7
952931f
3de2587
252b8fb
78f752b
a72cda3
ee0e149
4297546
34da298
437546f
b5900ec
a527c07
14fb78d
0747cab
64e9b54
f653c88
e35c89d
3cfc2da
ca4e04f
0beb45b
34b13aa
665a0ad
8b6b8e7
9d697e6
c3a35e4
ec822cc
6990271
e2a328c
5618e88
2955859
8eea1f5
5dab6a7
efc95dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,154 @@ | ||
import React from "react"; | ||
|
||
function App() { | ||
return ( | ||
<main className="container mt-5"> | ||
<section className="row"> | ||
<div className="col col-12"> | ||
<h1>Hola mundo</h1> | ||
</div> | ||
</section> | ||
</main> | ||
); | ||
import React, { Component } from "react"; | ||
import { BrowserRouter, Route } from "react-router-dom"; | ||
import Home from "./components/pages/Home"; | ||
import Active from "./components/pages/Active"; | ||
import Completed from "./components/pages/Complete"; | ||
// import Todo from "./components/Todo"; | ||
|
||
import "./_App.scss"; | ||
|
||
const LOCAL_STORAGE_KEY = "react-sc-state"; | ||
|
||
function loadLocalStorage() { | ||
const json = localStorage.getItem(LOCAL_STORAGE_KEY); | ||
|
||
const state = JSON.parse(json); | ||
|
||
if (!state) { | ||
return { | ||
todos: [], | ||
}; | ||
} | ||
|
||
return state; | ||
} | ||
class App extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
todos: [], | ||
}; | ||
this.newTodo = this.newTodo.bind(this); | ||
this.handleDelete = this.handleDelete.bind(this); | ||
this.handleSelected = this.handleSelected.bind(this); | ||
this.clear = this.clear.bind(this); | ||
} | ||
|
||
componentDidMount() { | ||
const prevState = loadLocalStorage(); | ||
|
||
this.setState({ | ||
todos: prevState.todos, | ||
}); | ||
} | ||
|
||
componentDidUpdate() { | ||
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(this.state)); | ||
} | ||
|
||
handleSelected(itemId) { | ||
const { todos } = this.state; | ||
const bolTodo = todos.map((todo) => { | ||
if (todo.id === itemId) { | ||
// eslint-disable-next-line no-param-reassign | ||
return { ...todo, selected: !todo.selected }; | ||
} | ||
return todo; | ||
}); | ||
this.setState({ | ||
todos: bolTodo, | ||
}); | ||
} | ||
|
||
handleDelete(itemId) { | ||
const { todos } = this.state; | ||
const notDelete = todos.filter((el) => el.id !== itemId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Muy bien implementado! Es recomendable nombrar las variables con un nombre descriptivo para que se entienda exactamente qué es la variable. En este caso como mejora se podría llamar el argument |
||
this.setState({ | ||
todos: notDelete, | ||
}); | ||
} | ||
|
||
submitNewTitle = (newTitle, id) => { | ||
const { todos } = this.state; | ||
|
||
this.setState({ | ||
todos: todos.map((todo) => { | ||
if (todo.id === id) { | ||
// eslint-disable-next-line no-param-reassign | ||
todo.title = newTitle; | ||
} | ||
return todo; | ||
}), | ||
}); | ||
}; | ||
|
||
newTodo(item) { | ||
const { todos } = this.state; | ||
|
||
this.setState({ | ||
todos: [...todos, item], | ||
}); | ||
} | ||
|
||
clear() { | ||
const { todos } = this.state; | ||
const cleared = todos.filter((item) => item.selected !== true); | ||
this.setState({ | ||
todos: cleared, | ||
}); | ||
} | ||
|
||
render() { | ||
const { todos } = this.state; | ||
|
||
return ( | ||
<BrowserRouter> | ||
<Route | ||
exact | ||
path="/" | ||
render={(routeProps) => ( | ||
<Home | ||
clear={this.clear} | ||
submitNewTitle={this.submitNewTitle} | ||
todos={todos} | ||
newTodo={this.newTodo} | ||
handleDelete={this.handleDelete} | ||
handleSelected={this.handleSelected} | ||
{...routeProps} | ||
/> | ||
)} | ||
/> | ||
<Route | ||
exact | ||
path="/active" | ||
render={(routeProps) => ( | ||
<Active | ||
submitNewTitle={this.submitNewTitle} | ||
handleDelete={this.handleDelete} | ||
handleSelected={this.handleSelected} | ||
newTodo={this.newTodo} | ||
todos={todos.filter((item) => item.selected === false)} | ||
{...routeProps} | ||
/> | ||
)} | ||
/> | ||
<Route | ||
exact | ||
path="/completed" | ||
render={(routeProps) => ( | ||
<Completed | ||
clear={this.clear} | ||
submitNewTitle={this.submitNewTitle} | ||
handleDelete={this.handleDelete} | ||
handleSelected={this.handleSelected} | ||
newTodo={this.newTodo} | ||
todos={todos.filter((item) => item.selected === true)} | ||
{...routeProps} | ||
/> | ||
)} | ||
/> | ||
</BrowserRouter> | ||
); | ||
} | ||
} | ||
export default App; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// @use "./global.scss" as global; | ||
|
||
.background_container { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
width: 100%; | ||
} | ||
.parent_container { | ||
display: flex; | ||
position: fixed; | ||
background-image: linear-gradient( | ||
20deg, | ||
rgb(13, 13, 14), | ||
rgb(38, 44, 70), | ||
rgb(42, 79, 134), | ||
rgb(144, 174, 207), | ||
rgba(175, 194, 207, 0.8), | ||
rgba(238, 242, 247, 0.3) | ||
); | ||
top: 5%; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
height: 70%; | ||
width: 40%; | ||
flex-wrap: wrap; | ||
gap: 25px; | ||
border-radius: 10px; | ||
} | ||
h1 { | ||
height: 80px; | ||
width: 100%; | ||
letter-spacing: 10px; | ||
} | ||
|
||
Link:hover { | ||
color: red; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from "react"; | ||
import "./_Button.scss"; | ||
// import { Link } from "react-router-dom"; | ||
|
||
const Checkbox = ({ ...newers }) => { | ||
return <input className="check" type="checkbox" {...newers} />; | ||
}; | ||
|
||
function Button({ ...newers }) { | ||
return <input className="but" type="button" {...newers} />; | ||
} | ||
function ClearBut({ ...newers }) { | ||
return <input className="butClear" type="button" {...newers} />; | ||
} | ||
export { Button, Checkbox, ClearBut }; | ||
Comment on lines
+1
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Este fichero se debería extraer a varios componentes ya que el fichero se llama |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
@use "../../global.scss" as global; | ||
|
||
.check { | ||
max-width: 20px; | ||
margin-right: 20px; | ||
} | ||
|
||
.but { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Los nombres de clases deberían ser más descriptivos para evitar palabras que puedan significar otra cosas en inglés como |
||
position: absolute; | ||
max-width: 20px; | ||
max-height: 20px; | ||
right: 100px; | ||
} | ||
|
||
.butClear { | ||
height: 20px; | ||
width: 20px; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "./Button"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from "react"; | ||
import "./footer.scss"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Es recomendable ordenar los imports para tener los imports de librerías primero y luego los imports de dependencias propias. En este caso sería: import React from "react";
import { Link } from "react-router-dom";
import "./footer.scss";
import { ClearBut } from "../Button/Button"; |
||
import { Link } from "react-router-dom"; | ||
import { ClearBut } from "../Button/Button"; | ||
|
||
function Footer({ clear }) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Se entiende que el prop |
||
return ( | ||
<footer className="todo_footer"> | ||
<h6>5 items left</h6> | ||
<Link to="/" className="nav_links"> | ||
<h6>All</h6> | ||
</Link> | ||
<Link to="/active" className="nav_links"> | ||
<h6>Active</h6> | ||
</Link> | ||
<Link to="/completed" className="nav_links"> | ||
<h6>Completed</h6> | ||
</Link> | ||
<ClearBut onClick={clear} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sería recomendable renombrar este componente a |
||
</footer> | ||
); | ||
} | ||
|
||
export default Footer; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.todo_footer { | ||
display: flex; | ||
flex-direction: row; | ||
color: white; | ||
} | ||
|
||
h6 { | ||
margin: 0 25px 0 25px; | ||
} | ||
|
||
.nav_links { | ||
color: white; | ||
} | ||
.nav_links:hover { | ||
text-decoration: none; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "./Footer"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
es recomendable eliminar todo el código comentado que no se utiliza