forked from platzi/curso-react-intro
-
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.
adición de últimos detalles de lógica y + persistencia de datos y así ggg
- Loading branch information
1 parent
434b740
commit 1cd3682
Showing
31 changed files
with
480 additions
and
154 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,61 @@ | ||
import React from 'react'; | ||
import { ToDoCounter } from '../ToDoCounter'; | ||
import { ToDoSearch } from "../ToDoSearch"; | ||
import { ToDoList } from '../ToDoList'; | ||
import { ToDoItem } from '../ToDoItem'; | ||
import { CreateToDoButton } from '../CreateToDoButton' | ||
import { ToDosLoading } from "../ToDosLoading"; | ||
import { ToDosError } from "../ToDosError"; | ||
import { EmptyToDos } from "../EmptyToDos"; | ||
import { Modal } from "../Modal"; | ||
import { ToDoContext } from "../ToDoContext"; | ||
import { ToDoForm } from '../ToDoForm'; | ||
|
||
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 } |
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,13 @@ | ||
import React from 'react'; | ||
import { AppUI } from './AppUI'; | ||
import { ToDoProvider } from '../ToDoContext'; | ||
|
||
function App() { | ||
return ( | ||
<ToDoProvider> | ||
<AppUI /> | ||
</ToDoProvider> | ||
) | ||
} | ||
|
||
export default App; |
This file was deleted.
Oops, something went wrong.
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,14 @@ | ||
import './CreateToDoButton.css' | ||
|
||
function CreateToDoButton({ setOpenModal }) { | ||
return ( | ||
<button | ||
className="CreateToDoButton" | ||
onClick={() => { | ||
setOpenModal(state => !state) | ||
}} | ||
>+</button> | ||
); | ||
} | ||
|
||
export {CreateToDoButton} |
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 React from 'react' | ||
|
||
function EmptyToDos() { | ||
return ( | ||
<p>Crea tu primer To-Do!</p> | ||
); | ||
} | ||
|
||
export { EmptyToDos }; |
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,12 @@ | ||
.ModalBackground { | ||
background-color: rgba(32,35,41,.8); | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
color: white; | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
} |
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,14 @@ | ||
import React from "react"; | ||
import ReactDOM from "react-dom"; | ||
import "./Modal.css"; | ||
|
||
function Modal({ children }) { | ||
return ReactDOM.createPortal( | ||
<div className="ModalBackground"> | ||
{children} | ||
</div>, | ||
document.getElementById('modal') | ||
) | ||
} | ||
|
||
export { Modal } |
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,71 @@ | ||
import React from 'react'; | ||
import { useLocalStorage } from './useLocalStorage'; | ||
|
||
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.toLocaleLowerCase() | ||
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={{ | ||
loading, | ||
error, | ||
completedToDos, | ||
totalToDos, | ||
searchValue, | ||
setSearchValue, | ||
searchedToDos, | ||
completeToDo, | ||
deleteToDo, | ||
openModal, | ||
setOpenModal, | ||
addToDo, | ||
}}> | ||
{ children } | ||
</ToDoContext.Provider> | ||
) | ||
} | ||
|
||
export { ToDoContext, ToDoProvider } |
Oops, something went wrong.