Skip to content

react #15

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 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
2 changes: 2 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
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`.
-->
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<title>React App</title>
</head>
<body>
Expand Down
31 changes: 31 additions & 0 deletions src/AddToDo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React, { Component } from "react"

class AddToDo extends Component {
state = {
content: ''
}
handleChange = (e) => {
this.setState({
content: e.target.value
})
}
handleSubmit = (e) => {
e.preventDefault();
this.props.addToDo(this.state);
this.setState({
content: ''
})
}
render(){
return (
<div>
<form onSubmit={this.handleSubmit}>
<label>Add new todo:</label>
<input type="text" onChange={this.handleChange} value={this.state.content}/>
</form>
</div>
)
}
}

export default AddToDo
54 changes: 38 additions & 16 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,42 @@
import logo from './logo.svg';
import './App.css';
import Banner from './components/Banner/Banner';
import { Switch, Route } from "react-router-dom"
import TodoPage from './pages/TodoPage/TodoPage';
import FollowersPage from './pages/FollowersPage/FollowersPage';
import React, { Component } from "react";
import ToDos from "./ToDos";
import "./App.css";
import AddToDo from "./AddToDo";

function App() {
return (
<div className="App">
<Banner />
<Switch>
<Route strict exact path="/" component={TodoPage}/>
<Route strict exact path="/followers" component={FollowersPage}/>
</Switch>
</div>
);
class App extends Component {
state = {
todos: [
{ id: 1, content: "learn react" },
{ id: 2, content: "learn react again" },
],
};

deleteToDo = (id) => {
const todos = this.state.todos.filter(todo => {
return todo.id !== id;
});
this.setState({
todos,
})
}

addToDo = (todo) => {
todo.id = Math.random();
let todos = [...this.state.todos, todo];
this.setState({
todos
})
}

render() {
return (
<div className="todo-app container">
<h1 className="center purple-text">ToDo's</h1>
<ToDos todos={this.state.todos} deleteToDo={this.deleteToDo} />
<AddToDo addToDo={this.addToDo} />
</div>
);
}
}

export default App;
24 changes: 24 additions & 0 deletions src/ToDos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from "react";

const ToDos = ({ todos, deleteToDo }) => {
const todoList = todos.length ? (
todos.map((todo) => {
return (
<div className="collection-item" key={todo.id}>
<span
onClick={() => {
deleteToDo(todo.id);
}}
>
{todo.content}
</span>
</div>
);
})
) : (
<p className="center">You have nothing To Do!</p>
);
return <div className="todos collection">{todoList}</div>;
};

export default ToDos;
27 changes: 0 additions & 27 deletions src/components/AddInput/AddInput.css

This file was deleted.

10 changes: 0 additions & 10 deletions src/components/Banner/Banner.css

This file was deleted.

9 changes: 0 additions & 9 deletions src/components/Banner/Banner.js

This file was deleted.

3 changes: 0 additions & 3 deletions src/components/Followers/Followers.css

This file was deleted.

13 changes: 0 additions & 13 deletions src/components/Followers/Followers.js

This file was deleted.

35 changes: 0 additions & 35 deletions src/components/FollowersList/FollowersList.css

This file was deleted.

7 changes: 0 additions & 7 deletions src/components/Header/Header.css

This file was deleted.

3 changes: 0 additions & 3 deletions src/components/Todo/Todo.css

This file was deleted.

26 changes: 0 additions & 26 deletions src/components/Todo/Todo.js

This file was deleted.

15 changes: 0 additions & 15 deletions src/components/TodoFooter/TodoFooter.css

This file was deleted.

16 changes: 0 additions & 16 deletions src/components/TodoFooter/TodoFooter.js

This file was deleted.

27 changes: 0 additions & 27 deletions src/components/TodoList/TodoList.css

This file was deleted.

54 changes: 0 additions & 54 deletions src/components/TodoList/TodoList.js

This file was deleted.

1 change: 0 additions & 1 deletion src/logo.svg

This file was deleted.

Loading