Skip to content

Solution: Brahim Benalia & Marc Solà Ramos #8

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

Open
wants to merge 42 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
e62f1b0
react jsx structure
bbenalia May 19, 2021
6dd2cd4
main styles uncomplete
bbenalia May 19, 2021
981ce8e
added header background
MarcSola May 19, 2021
5286b83
fused both parts
MarcSola May 19, 2021
d008242
added more styles
bbenalia May 19, 2021
d0c0d5e
main styles finished
bbenalia May 20, 2021
951c883
components
bbenalia May 20, 2021
46be3e4
components finished
bbenalia May 20, 2021
09b2b56
deleted main.scss
bbenalia May 20, 2021
76d3ee7
render componentes done
bbenalia May 20, 2021
8888a3a
remove TODO
bbenalia May 20, 2021
fe07b42
some styles
bbenalia May 20, 2021
f88be24
checkbox styles
bbenalia May 20, 2021
d6e71a4
items left
bbenalia May 20, 2021
adb06d1
added routes
bbenalia May 20, 2021
382eda3
fixed some styles in header.scss
bbenalia May 20, 2021
04c4cf0
added linethrough completed todo
bbenalia May 20, 2021
71d6f7b
First checkbox fixed
bbenalia May 21, 2021
8150b2f
Merge with filtering
bbenalia May 21, 2021
d123748
some stalls and installed formik & yup
bbenalia May 21, 2021
ca59f19
validation done!
bbenalia May 21, 2021
80a529e
api data & localstorage
bbenalia May 21, 2021
5396d33
Merge branch 'editing-todos' into extras1
bbenalia May 21, 2021
06c5687
added edit part, complete. Only final touches left
MarcSola May 21, 2021
9ae541b
header component
bbenalia May 21, 2021
3f52101
some todo edit styles
bbenalia May 21, 2021
b7e85e7
app footer and validation style edit todo
bbenalia May 21, 2021
c1e6af6
some cahnges
bbenalia May 22, 2021
17dc67c
added clear completed todos
MarcSola May 22, 2021
5cc9f99
styles to active route
bbenalia May 23, 2021
0366fd7
Fix checkbox rounded style
bbenalia May 23, 2021
9034f87
respponsive
bbenalia May 23, 2021
3057a70
added dark mode
MarcSola May 23, 2021
a1731a2
added dark mode to localstorage
MarcSola May 23, 2021
72e806f
added dark mode to localstorage 2
MarcSola May 23, 2021
8df14ad
Merge branches 'extras2' and 'extras2' of https://github.com/ibraslay…
MarcSola May 23, 2021
b92ec1c
Merge branch 'extras2' into extras1
MarcSola May 23, 2021
69b7cba
Fix clear completed
bbenalia May 24, 2021
fa18bf5
fix dark responsive
bbenalia May 24, 2021
475e27e
deleted comments
bbenalia May 24, 2021
5ce8f7f
Fix min height of div root
bbenalia May 24, 2021
3e512e6
darkmode in hero component
bbenalia May 25, 2021
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
78 changes: 76 additions & 2 deletions package-lock.json

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

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@
"@testing-library/react": "^11.2.6",
"@testing-library/user-event": "^13.1.5",
"bootstrap": "^4.6.0",
"classnames": "^2.3.1",
"formik": "^2.2.7",
"prop-types": "^15.7.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-icons": "^4.2.0",
"react-redux": "^7.2.3",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0",
"sass": "^1.32.11",
"web-vitals": "^1.1.1"
"uuid": "^8.3.2",
"web-vitals": "^1.1.1",
"yup": "^0.32.9"
},
"devDependencies": {
"@babel/core": "^7.13.16",
Expand Down
224 changes: 212 additions & 12 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,215 @@
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 classNames from "classnames";
import { Route } from "react-router-dom";
import { v4 as uuidv4 } from "uuid";

import TodoList from "./components/TodoList";
import * as api from "./api";
import AppHeader from "./components/AppHeader";

import { HOME, ACTIVE, COMPLETED } from "./constatnts/routes";

import "./app.scss";

const LOCAL_STORAGE_KEY = "todo-state";

function loadLocalStorageData() {
const prevItems = localStorage.getItem(LOCAL_STORAGE_KEY);

if (!prevItems) {
return null;
}

try {
return JSON.parse(prevItems);
} catch (error) {
return null;
}
}

class App extends Component {
constructor(props) {
super(props);
this.state = {
todos: [],
todoName: "",
currentTheme: false,
};
this.handleAddTodo = this.handleAddTodo.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
this.handleChange = this.handleChange.bind(this);
this.handleRemove = this.handleRemove.bind(this);
this.handleChangeCheck = this.handleChangeCheck.bind(this);
this.handleEdit = this.handleEdit.bind(this);
this.handleEditSubmit = this.handleEditSubmit.bind(this);
this.handleResetEdit = this.handleResetEdit.bind(this);
this.handleClearCompleted = this.handleClearCompleted.bind(this);
this.handleThemeClick = this.handleThemeClick.bind(this);
}

componentDidMount() {
const prevItems = loadLocalStorageData();

if (!prevItems || !prevItems.todos.length) {
api.getProducts().then((data) => {
this.setState({ todos: data });
});
return;
}
Comment on lines +53 to +58
Copy link
Contributor

Choose a reason for hiding this comment

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

Muy interesante el check para ver si el localstorage tiene todos o no.


this.setState({
todos: prevItems.todos,
currentTheme: prevItems.currentTheme,
});
}

componentDidUpdate() {
const { todos, currentTheme } = this.state;
localStorage.setItem(
LOCAL_STORAGE_KEY,
JSON.stringify({ todos, currentTheme }),
);
}

handleAddTodo(values) {
const { todos } = this.state;

const newTodo = {
id: uuidv4(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Muy buen uso de uuid para crear ids 👏🏻

name: values.name,
complete: false,
};

this.setState({ todos: [...todos, newTodo], todoName: "" });
}

handleSubmit(e) {
e.preventDefault();
this.handleAddTodo(this.state);
}

handleChange(e) {
this.setState({ todoName: e.target.value });
}

handleRemove(id) {
const { todos } = this.state;
const arr = todos.filter((todo) => todo.id !== id);
this.setState({ todos: arr });
}

handleChangeCheck(id) {
const { todos } = this.state;
const arr = todos.map((todo) => {
return todo.id === id ? { ...todo, complete: !todo.complete } : todo;
// return obj;
Copy link
Contributor

Choose a reason for hiding this comment

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

Este código comentado se debería eliminar ya que no se usa

});

this.setState({ todos: arr });
}

handleClearCompleted() {
const { todos } = this.state;
const arr = todos.filter((todo) => todo.complete === false);
this.setState({ todos: arr });
}

handleEdit(id) {
const { todos } = this.state;
const todoToEdit = todos.map((todo) => {
return todo.id === id ? { ...todo, edit: true } : todo;
Copy link
Contributor

Choose a reason for hiding this comment

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

Muy bueno uso del operador ternario para la comprobación 👏🏻

});
this.setState({ todos: todoToEdit });
}

handleEditSubmit(values, id) {
const { todos } = this.state;
const todoToEdit = todos.map((todo) => {
return todo.id === id
? { ...todo, name: values.name, edit: false }
: todo;
});
this.setState({ todos: todoToEdit });
}

handleResetEdit() {
const { todos } = this.state;
const todoToEdit = todos.map((todo) => {
return { ...todo, edit: false };
});
this.setState({ todos: todoToEdit });
}

handleThemeClick() {
const { currentTheme } = this.state;
this.setState({ currentTheme: !currentTheme });
}

render() {
const { todos, currentTheme } = this.state;
const appClasses = classNames({
globalContainer: true,
darkModeOpacity: currentTheme,
});

return (
<div className={appClasses}>
<AppHeader
handleAddTodo={this.handleAddTodo}
handleThemeClick={this.handleThemeClick}
currentTheme={currentTheme}
/>

<Route
path={ACTIVE}
exact
render={(routeProps) => (
<TodoList
{...routeProps}
handleChangeCheck={this.handleChangeCheck}
handleRemove={this.handleRemove}
todos={todos.filter((todo) => !todo.complete)}
handleClearCompleted={this.handleClearCompleted}
currentTheme={currentTheme}
/>
)}
/>

<Route
path={COMPLETED}
exact
render={(routeProps) => (
<TodoList
{...routeProps}
handleChangeCheck={this.handleChangeCheck}
handleRemove={this.handleRemove}
todos={todos.filter((todo) => todo.complete)}
handleClearCompleted={this.handleClearCompleted}
currentTheme={currentTheme}
/>
)}
/>

<Route
path={HOME}
exact
render={(routeProps) => (
<TodoList
{...routeProps}
handleChangeCheck={this.handleChangeCheck}
handleRemove={this.handleRemove}
handleEdit={this.handleEdit}
handleEditSubmit={this.handleEditSubmit}
handleResetEdit={this.handleResetEdit}
handleClearCompleted={this.handleClearCompleted}
todos={todos}
currentTheme={currentTheme}
/>
)}
/>
</div>
);
}
}

export default App;
Loading