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

[ADD] #4

Open
wants to merge 6 commits 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
15 changes: 15 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"dependencies": {
"react": "^18",
"react-dom": "^18",
"react-icons": "^4.9.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
Expand Down
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<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.

25 changes: 0 additions & 25 deletions src/App.js

This file was deleted.

15 changes: 15 additions & 0 deletions src/App/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from "react";
import { Logica } from "./logica";
import {TodoProvider} from "../Contexts/todoContext"
function App() {

//se separan entre statefull y stateless
return (
<TodoProvider>
<Logica/>
</TodoProvider>

);
}

export default App;
9 changes: 9 additions & 0 deletions src/App/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 };
11 changes: 11 additions & 0 deletions src/App/Modal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { React} from 'react'
import {createPortal} from "react-dom"
import "../styles/modal.css"
const Modal = ({children})=>{
return createPortal(<div className='ModalBackground'>
{children}
</div>,
document.getElementById("modal"))
}

export {Modal}
9 changes: 9 additions & 0 deletions src/App/TodosError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';

function TodosError() {
return (
<p>Error...</p>
);
}

export { TodosError };
14 changes: 14 additions & 0 deletions src/App/TodosLoading.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import '../styles/TodosLoading.css';

function TodosLoading() {
return (
<div className="LoadingTodo-container">
<span className="LoadingTodo-completeIcon"></span>
<p className="LoadingTodo-text"></p>
<span className="LoadingTodo-deleteIcon"></span>
</div>
);
}

export { TodosLoading };
50 changes: 50 additions & 0 deletions src/App/logica.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from 'react'
import {NameCounter} from "../Components/NameCounter/index";
import { TodoFilter } from "../Components/TodoFilter/index";
import { TodoList } from "../Components/TodoList/index";
import {TodoItem} from "../Components/TodoItem/index";
import { CreateButton } from "../Components/CreateButton/index";
import {TodosLoading} from "./TodosLoading"
import {TodosError} from "./TodosError"
import {EmptyTodos} from "./EmptyTodos"
import { TodoContext } from "../Contexts/todoContext";
import { TodoForm } from '../Components/todoForm/todoForm';
import { Modal } from './Modal';
const Logica = ()=>{
const {completeTodo,deleteTodo,searchedTodos,setState, loading, error, openModal, setOpenModal} = React.useContext(TodoContext)

return( <>
<NameCounter />
<TodoFilter setState={setState}/>
<TodoList>
{loading && (
<>
<TodosLoading />
<TodosLoading />
<TodosLoading />
</>
)}
{error && <TodosError/>}
{(!loading && searchedTodos.length === 0) && <EmptyTodos />}

{searchedTodos.map(todo => (
<TodoItem
key={todo.text}
element={todo}
completed={todo.completed}
oncomplete={() => completeTodo(todo.text)}
onDelete={() => deleteTodo(todo.text)}
/>
))}
<CreateButton abrir={setOpenModal}/>

{
openModal && <Modal> <TodoForm/></Modal>
}

</TodoList>

</>)
}

export {Logica}
11 changes: 11 additions & 0 deletions src/Components/CreateButton/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import "../../styles/buttonStyle.css"

const CreateButton = ({abrir})=>{

return(
<button className="CreateTodoButton" onClick={()=>{abrir(e=>!e)}}>+</button>
)

}

export {CreateButton}
16 changes: 16 additions & 0 deletions src/Components/NameCounter/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react'
import "../../styles/nameCounter.css"
import { TodoContext } from '../../Contexts/todoContext'

const NameCounter = ()=>{
const {completedTodos, totalTodos} = React.useContext(TodoContext)

return(
<h1 className="TodoCounter">
has completado {completedTodos} de {totalTodos} ToDo's
</h1>
)

}

export {NameCounter}
14 changes: 14 additions & 0 deletions src/Components/TodoFilter/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from "react"
import "../../styles/todoFilter.css"
import { TodoContext } from "../../Contexts/todoContext"
const TodoFilter = ()=>{
const { searchValue,
setSearchValue,} = React.useContext(TodoContext)
return(
<> <input className="TodoSearch" placeholder="escribe algo" value={searchValue} onChange={(e)=>setSearchValue(e.target.value)}/></>
)

}

export {TodoFilter}

16 changes: 16 additions & 0 deletions src/Components/TodoItem/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import CompleteIcon from "../todoIcon/completeIcon.js";
import DeleteIcon from "../todoIcon/deleteIcon.js";
import "../../styles/todoItem.css";

const TodoItem = ({element, completed,onComplete, onDelete})=>{
return(
<li className="TodoItem">
<CompleteIcon complete={completed} oncomplete={onComplete}/>
<p className={`TodoItem-p ${element.completed&&"TodoItem-p--complete"}`}>{element.text}</p>
<DeleteIcon onDelete={onDelete}/>
</li>
)

}

export {TodoItem}
12 changes: 12 additions & 0 deletions src/Components/TodoList/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import "../../styles/todoList.css"

const TodoList = (props)=>{

return(
<ul className="TodoList">
{props.children}
</ul>
)
}

export {TodoList}
29 changes: 29 additions & 0 deletions src/Components/todoForm/todoForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react'
import "../../styles/todoForm.css"
import {TodoContext} from "../../Contexts/todoContext"
function TodoForm(){
const [newTodoValue, setNewTodoValue] = React.useState("")
const {setOpenModal,addTodo } = React.useContext(TodoContext)
const OnSubmit = e =>{
addTodo(newTodoValue)
e.preventDefault()
setOpenModal(false)
}

const OnCancel = () =>setOpenModal(false)
const OnChange = e=>{ setNewTodoValue(e.target.value)}
return(
<>
<form onSubmit={OnSubmit}>
<label>Escribe tu nuevo Todo</label>
<textarea placeholder='escribe aquí...' value={newTodoValue} onChange={OnChange}></textarea>
<div className='TodoForm-buttonContainer'>
<button className='TodoForm-button TodoForm-button--cancel' type='button' onClick={OnCancel}>cancelar</button>
<button className='TodoForm-button TodoForm-button--add' type='submit'>agregar</button>
</div>
</form>
</>
)
}

export {TodoForm}
9 changes: 9 additions & 0 deletions src/Components/todoIcon/completeIcon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {React} from 'react'
import TodoIcon from '.';
const completeIcon = ({complete, oncomplete}) => {
return (
<TodoIcon type="check" click={oncomplete} color={complete?"green":"gray"}/>
);
}

export default completeIcon
9 changes: 9 additions & 0 deletions src/Components/todoIcon/deleteIcon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {React} from 'react'
import TodoIcon from '.';
const deleteIcon = ({onDelete}) => {
return (
<TodoIcon type="delete" color="gray" click={onDelete}/>
);
}

export default deleteIcon
17 changes: 17 additions & 0 deletions src/Components/todoIcon/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {React} from 'react';
import { ReactComponent as CheckIcon} from '../../icons/check.svg';
import { ReactComponent as DeleteIcon } from '../../icons/delete.svg';
import "../../styles/todoIcon.css"
const todoIcon = ({type, color, click}) => {
const iconType = {
"check": color=><CheckIcon className="Icon-svg" fill={color}/>,
"delete": color =><DeleteIcon className="Icon-svg" fill={color}/>
}
return (
<span className={`Icon-container Icon-container-${type}`} onClick={()=>click()}>
{iconType[type](color)}
</span>
);
}

export default todoIcon;
Loading