Skip to content

Commit

Permalink
develop a frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
rylandg committed Jan 31, 2019
1 parent 69c9317 commit 7071818
Show file tree
Hide file tree
Showing 11 changed files with 264 additions and 0 deletions.
26 changes: 26 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

package-lock.json
yarn.lock
30 changes: 30 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"author": "Ryland Goldstein",
"dependencies": {
"@material-ui/core": "^3.9.1",
"@material-ui/icons": "^3.0.2",
"react": "^16.7.0",
"react-dom": "^16.7.0",
"react-scripts": "2.1.3",
"url-join": "^4.0.0",
"uuid": "^3.3.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
Binary file added frontend/public/favicon.ico
Binary file not shown.
41 changes: 41 additions & 0 deletions frontend/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<meta name="theme-color" content="#000000" />
<!--
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
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>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
15 changes: 15 additions & 0 deletions frontend/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"short_name": "Todo App",
"name": "Binaris Todo App",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
48 changes: 48 additions & 0 deletions frontend/src/Todo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React, { Component } from 'react';
import Typography from '@material-ui/core/Typography';
import uuidv4 from 'uuid/v4';

import './index.css';

import TodoList from './TodoList';
import TodoForm from './TodoForm';

class Todo extends Component {
constructor(props) {
super(props);
this.state = { todos: {} };
}

createTodo = async todoText => {
const uniqueID = uuidv4();
this.setState({
todos: {
...this.state.todos,
[uniqueID]: todoText,
},
});
}

removeTodo = async todoID => {
const todos = { ...this.state.todos };
delete todos[todoID];
this.setState({ todos });
}

render() {
return (
<div className="Todo">
<Typography variant="h2">
Todo
</Typography>
<TodoForm createTodo={this.createTodo} />
<TodoList
todos={this.state.todos}
removeTodo={this.removeTodo}
/>
</div>
);
}
}

export default Todo;
53 changes: 53 additions & 0 deletions frontend/src/TodoForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React, { Component } from 'react';

import AddIcon from '@material-ui/icons/Add';
import IconButton from '@material-ui/core/IconButton';
import TextField from '@material-ui/core/TextField';

const EMPTY_TODO = {
todoText: '',
};

class TodoForm extends Component {
constructor(props) {
super(props);
this.state = Object.assign({}, EMPTY_TODO);
}

updateTodoText = event => {
const { value } = event.target;
this.setState({ todoText: value });
}

addTodo = (event) => {
event.preventDefault();
if (this.state.todoText === '') return
this.props.createTodo(this.state.todoText);
this.setState(EMPTY_TODO);
}

render() {
const { todoText } = this.state;
return(
<form
onSubmit={this.addTodo}
style={{ marginLeft: 48 }}
>
<TextField
variant="outlined"
type="text"
placeholder="Add todo"
value={todoText}
onChange={this.updateTodoText}/>
<IconButton
aria-label="Add"
onClick={this.addTodo}
>
<AddIcon/>
</IconButton>
</form>
);
}
}

export default TodoForm;
35 changes: 35 additions & 0 deletions frontend/src/TodoList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, { Component } from 'react';

import CheckIcon from '@material-ui/icons/Check';
import IconButton from '@material-ui/core/IconButton';
import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem';
import ListItemSecondaryAction from '@material-ui/core/ListItemSecondaryAction';
import ListItemText from '@material-ui/core/ListItemText';

class TodoList extends Component {
render() {
const { removeTodo, todos } = this.props;
return(
<List>
{
Object.keys(todos).map(todoID => (
<ListItem key={todoID}>
<ListItemText primary={todos[todoID]} />
<ListItemSecondaryAction>
<IconButton
aria-label="Remove"
onClick={() => removeTodo(todoID)}
>
<CheckIcon />
</IconButton>
</ListItemSecondaryAction>
</ListItem>
))
}
</List>
);
}
}

export default TodoList;
4 changes: 4 additions & 0 deletions frontend/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.Todo {
font-family: fantasy;
text-align: center;
}
5 changes: 5 additions & 0 deletions frontend/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';
import ReactDOM from 'react-dom';
import Todo from './Todo';

ReactDOM.render(<Todo />, document.getElementById('root'));
7 changes: 7 additions & 0 deletions frontend/src/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7071818

Please sign in to comment.