Skip to content
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

actualizando ficheros #30

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
1,120 changes: 1,030 additions & 90 deletions package-lock.json

Large diffs are not rendered by default.

21 changes: 20 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,25 @@
"name": "platzi-intro-react-base",
"version": "0.1.0",
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.5.1",
"@fortawesome/free-brands-svg-icons": "^6.5.1",
"@fortawesome/free-regular-svg-icons": "^6.5.1",
"@fortawesome/free-solid-svg-icons": "^6.5.1",
"@fortawesome/react-fontawesome": "^0.2.0",
"react": "^18",
"react-dom": "^18",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"eject": "react-scripts eject",
"sass": "sass --style=compressed src/scss:src/css",
"prefix": "npm run sass && postcss src/css/**/*.css --use=autoprefixer --dir src/css --map",
"build": "react-scripts build",
"eject": "react-scripts eject"
"predeploy": "npm run build",
"deploy": "gh-pages -d build"

},
"eslintConfig": {
"extends": [
Expand All @@ -28,5 +38,14 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"homepage": "https://Iaramirez88.github.io/curso-react-platzi",
"devDependencies": {
"autoprefixer": "^10.4.16",
"gh-pages": "^6.1.0",
"onchange": "^7.1.0",
"postcss": "^8.4.31",
"postcss-cli": "^10.1.0",
"sass": "^1.69.5"
}
}
3 changes: 2 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
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>
<title>TODO Machine</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<div id="modal"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
Expand Down
38 changes: 0 additions & 38 deletions src/App.css

This file was deleted.

27 changes: 8 additions & 19 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
import logo from './platzi.webp';
import './App.css';
import React from 'react';
import { AppUI } from './app/AppUI';
import { TodoProvider } from './components/TodoContext';

function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edita el archivo <code>src/App.js</code> y guarda para recargar.
</p>
<a
className="App-link"
href="https://platzi.com/reactjs"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>

return(
<TodoProvider>
<AppUI/>
</TodoProvider>
);
}

Expand Down
57 changes: 57 additions & 0 deletions src/app/AppUI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React from 'react';
import { TodoCounter } from '../components/TodoCounter';
import { TodoSearch } from '../components/TodoSearch';
import { TodoList } from '../components/TodoList';
import { TodoItem } from '../components/TodoItem';
import { TodosLoading } from '../components/TodosLoading';
import { TodosError } from '../components/TodosError';
import { EmptyTodos } from '../components/EmptyTodos';
import { CreateTodoButton } from '../components/CreateTodoButton';
import { TodoForm } from '../components/TodoForm';
import { Modal } from '../modal';
import { TodoContext } from '../components/TodoContext';

function AppUI(){
const {
loading,
error,
searchedTodos,
completeTodo,
deleteTodo,
openModal,
setOpenModal,
} = React.useContext(TodoContext);
return (
<>
<TodoCounter/>
<TodoSearch/>
<TodoList>
{loading && (
<>
<TodosLoading/>
<TodosLoading/>
<TodosLoading/>
</>
)}
{error && <TodosError/>}
{(!loading && searchedTodos.length === 0) && <EmptyTodos/>}
{searchedTodos.map(todo =>(
<TodoItem
key={todo.text}
text={todo.text}
completed={todo.completed}
onComplete={() => completeTodo(todo.text)}
onDelete={() => deleteTodo(todo.text)}
/>
))}
</TodoList>
<CreateTodoButton setOpenModal={setOpenModal}/>
{openModal && (
<Modal>
<TodoForm/>
</Modal>
)}
</>
);
}
export { AppUI };
14 changes: 14 additions & 0 deletions src/components/CreateTodoButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function CreateTodoButton({ setOpenModal }){
return (
<button
className="CreateTodoButton"
onClick={
()=>{
setOpenModal(state => !state);
}
}
>+</button>
);
}

export { CreateTodoButton };
9 changes: 9 additions & 0 deletions src/components/EmptyTodos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from "react";
function EmptyTodos(){

return (
<p>¡Crea tu primer TODO!</p>
);
}

export { EmptyTodos };
75 changes: 75 additions & 0 deletions src/components/TodoContext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import React from 'react';
import { useLocalStorage } from '../hooks/localStorage';

const TodoContext = React.createContext();

function TodoProvider({children}){
const {
item: todos,
saveItem: saveTodos,
loading,
error,
} = useLocalStorage('TODOS_V1', []);
const [searchValue, setSearchValue] = React.useState('');
const [openModal, setOpenModal] = React.useState(false);
const completedTodos = todos.filter(
todo => !!todo.completed
).length;
const totalTodos = todos.length;
const searchedTodos = todos.filter(
(todo)=>{
const todoText = todo.text.toLowerCase();
const searchText = searchValue.toLowerCase();
return todoText.includes(searchText);
}
);

const addTodo = (text)=>{
const newTodos = [...todos];
newTodos.push({
text,
completed: false,
});
saveTodos(newTodos);
};

const completeTodo = (text) =>{
const newTodos = [...todos];
const todoIndex = newTodos.findIndex(
(todo) => todo.text === text
);
newTodos[todoIndex].completed = true;
saveTodos(newTodos);
};

const deleteTodo = (text) =>{
const newTodos = [...todos];
const todoIndex = newTodos.findIndex(
(todo) => todo.text === text
);
newTodos.splice(todoIndex, 1);
saveTodos(newTodos);
};

return (
<TodoContext.Provider value={{
addTodo,
loading,
error,
completedTodos,
totalTodos,
searchValue,
setSearchValue,
searchedTodos,
completeTodo,
deleteTodo,
openModal,
setOpenModal,
}}>
{children}
</TodoContext.Provider>
)

}

export { TodoContext, TodoProvider};
16 changes: 16 additions & 0 deletions src/components/TodoCounter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from "react";
import { TodoContext } from "./TodoContext";

function TodoCounter(){
const {
completedTodos,
totalTodos,
} = React.useContext(TodoContext);
return (
<h1 className="TodoCounter">
Has completado <span>{completedTodos}</span> de <span>{totalTodos}</span> Todos
</h1>
);
}

export { TodoCounter };
32 changes: 32 additions & 0 deletions src/components/TodoForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';
import { TodoContext } from './TodoContext';
function TodoForm(){
const{
addTodo,
setOpenModal,
} = React.useContext(TodoContext);
const [newTodoValue, setNewTodoValue] = React.useState('')
const onSubmit = (event)=>{
event.preventDefault();
addTodo(newTodoValue);
setOpenModal(false);
};
const onCancel = () =>{
setOpenModal(false);
}
const onChange = (event) =>{
setNewTodoValue(event.target.value);
}
return(
<form onSubmit={onSubmit}>
<label>Escribe tu nuevo TODO</label>
<textarea placeholder="Escribe tu tarea" value={newTodoValue} onChange={onChange}/>
<div className='TodoForm-buttonContainer'>
<button type="button" className='TodoForm-button TodoForm-button--cancel' onClick={onCancel}>Cancelar</button>
<button type="submit" className='TodoForm-button TodoForm-button--add'>Añadir</button>
</div>
</form>
);
}

export {TodoForm};
25 changes: 25 additions & 0 deletions src/components/TodoItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faCheck,faXmark } from '@fortawesome/free-solid-svg-icons'

function TodoItem(props){
return (
<li className='TodoItem'>
<span
className={`Icon Icon-check ${props.completed && "Icon-check--active"}`}
onClick={props.onComplete}>
<FontAwesomeIcon icon={faCheck} />
</span>
<p className={`TodoItem-p ${props.completed && "TodoItem-p--complete"}`}>
{props.text}
</p>
<span
className="Icon Icon-delete"
onClick={props.onDelete}>
<FontAwesomeIcon icon={faXmark} />
</span>
</li>
);
}

export { TodoItem };
9 changes: 9 additions & 0 deletions src/components/TodoList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function TodoList(props){
return (
<ul>
{props.children}
</ul>
);
}

export { TodoList };
Loading