Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
davimesquit committed Mar 19, 2023
1 parent 0f8d760 commit b985eea
Show file tree
Hide file tree
Showing 14 changed files with 253 additions and 67 deletions.
76 changes: 76 additions & 0 deletions package-lock.json

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

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.3.0",
"@fortawesome/free-regular-svg-icons": "^6.3.0",
"@fortawesome/free-solid-svg-icons": "^6.3.0",
"@fortawesome/react-fontawesome": "^0.2.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"iud": "^1.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"u": "^0.1.0",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
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>To-Do List</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
89 changes: 66 additions & 23 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,38 +1,81 @@
@import url('https://fonts.googleapis.com/css2?family=Poppins&display=swap');

* {
font-family: 'Poppins', sans-serif;
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
background: #8758ff;
display: flex;
justify-content: center;
align-items: center;
}

.App {
text-align: center;
}

.App-logo {
height: 40vmin;
pointer-events: none;
h1 {
color: #fff;
margin-bottom: 0.5rem;
font-size: 1.75rem;
}

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
.TodoWrapper {
background: #1A1A40;
margin-top: 5rem;
padding: 2rem;
border-radius: 5px;
}

.App-header {
background-color: #282c34;
min-height: 100vh;
.TodoForm {
width: 100%;
}

.todo-input {
outline: none;
background: none;
border: 1px solid #8758ff;
padding: 0.5rem 1rem;
margin-top: 1rem;
margin-bottom: 2rem;
width: 300px;
color: #fff;
}

.todo-input::placeholder {
color: #ffffff4d;
}

.todo-btn {
background: #8758ff;
color: #fff;
border: none;
padding: 0.55rem;
cursor: pointer;

}

.Todo {
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
background: #8758ff;
color: #fff;
padding: 0.75rem 1rem;
border-radius: 5px;
margin-bottom: 1rem;
cursor: pointer;
}

.App-link {
color: #61dafb;
.fa-trash {
margin-left: 0.75rem;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
.completed {
color: #c5aeff;
text-decoration: line-through;
}
18 changes: 3 additions & 15 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
import logo from './logo.svg';
import './App.css';
import { TodoWrapper } from './components/TodoWrapper';

function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
<TodoWrapper />

</div>
);
}
Expand Down
8 changes: 0 additions & 8 deletions src/App.test.js

This file was deleted.

19 changes: 19 additions & 0 deletions src/components/EditTodoForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React, {useState} from "react";

export const EditTodoForm = ({editTodo, task}) => {
const [value, setValue] = useState(task.task)

const handleSubmit = e => {
e.preventDefault();

editTodo(value, task.id);

setValue("")
}
return(
<form className='TodoForm' onSubmit={handleSubmit}>
<input type="text" className='todo-input' value={value} placeholder='Editar Tarefa' onChange={(e) => setValue(e.target.value)}/>
<button type='submit' className='todo-btn'>Editar</button>
</form>
)
}
16 changes: 16 additions & 0 deletions src/components/Todo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from "react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faPenToSquare } from "@fortawesome/free-regular-svg-icons";
import { faTrash } from "@fortawesome/free-solid-svg-icons";

export const Todo = ({task, toggleComplete, deleteTodo, editTodo}) => {
return(
<div className="Todo">
<p onClick={() => toggleComplete(task.id)} className={`${task.completed ? 'completed': ""}`}>{task.task}</p>
<div>
<FontAwesomeIcon icon={faPenToSquare} onClick={() => editTodo(task.id)}/>
<FontAwesomeIcon icon={faTrash} onClick={() => deleteTodo(task.id)}/>
</div>
</div>
)
}
19 changes: 19 additions & 0 deletions src/components/TodoFoms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React, {useState} from "react";

export const TodoForm = ({addTodo}) => {
const [value, setValue] = useState("")

const handleSubmit = e => {
e.preventDefault();

addTodo(value);

setValue("")
}
return(
<form className='TodoForm' onSubmit={handleSubmit}>
<input type="text" className='todo-input' value={value} placeholder='Tarefa' onChange={(e) => setValue(e.target.value)}/>
<button type='submit' className='todo-btn'>Add</button>
</form>
)
}
47 changes: 47 additions & 0 deletions src/components/TodoWrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React, {useState} from "react";
import { TodoForm } from "./TodoFoms";
import { EditTodoForm } from "./EditTodoForm";
import { v4 as uuidv4 } from 'uuid';
import { Todo } from "./Todo";
uuidv4();

export const TodoWrapper = () => {
const [todos, setTodos] = useState([])

const addTodo = todo => {
setTodos([...todos, {id: uuidv4(), task: todo, completed: false, isEditing: false}])
console.log(todos)
}

const toggleComplete = id => {
setTodos(todos.map(todo => todo.id === id ? {... todo, completed: !todo.completed} : todo))
}

const deleteTodo = id => {
setTodos(todos.filter(todo => todo.id !== id))
}

const editTodo = id => {
setTodos(todos.map(todo => todo.id === id ? {... todo, isEditing: !todo.isEditing} : todo))
}

const editTask = (task, id) => {
setTodos(todos.map(todo => todo.id === id ? {... todo, task, isEditing: !todo.isEditing} : todo))
}

return(
<div className='TodoWrapper'>
<h1>To-Do List</h1>
<TodoForm addTodo={addTodo}/>
{todos.map((todo, index) => (
todo.isEditing ? (
<EditTodoForm editTodo={editTask} task={todo}/>
) : (
<Todo task={todo} key={index} toggleComplete={toggleComplete} deleteTodo={deleteTodo} editTodo={editTodo} />
)

))}

</div>
)
}
Loading

0 comments on commit b985eea

Please sign in to comment.