Skip to content

Interview Challenge by Aldo Torres #30

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 6 commits into
base: master
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
6 changes: 6 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
"env",
"react"
]
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Dependency directories
node_modules/
6,217 changes: 6,217 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "interview-codingchallenge-fsjs",
"version": "1.0.0",
"description": "Hey, welcome to the first coding challenge of your interview process, you'll be presented with a set of steps to accomplish in order to get yourself graded on",
"main": "index.js",
"directories": {
"test": "test"
},
"scripts": {
"start": "node src/index.js",
"dev": "nodemon src/index.js",
"webpack": "webpack --mode development --watch"
},
"repository": {
"type": "git",
"url": "git+https://github.com/DanielTorresV/interview-codingchallenge-fsjs.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/DanielTorresV/interview-codingchallenge-fsjs/issues"
},
"homepage": "https://github.com/DanielTorresV/interview-codingchallenge-fsjs#readme",
"dependencies": {
"express": "^4.16.4",
"mongoose": "^5.3.15",
"morgan": "^1.9.1"
},
"devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"nodemon": "^1.18.7",
"react": "^16.6.3",
"react-dom": "^16.6.3",
"webpack": "^4.27.1",
"webpack-cli": "^3.1.2"
}
}
190 changes: 190 additions & 0 deletions src/client/app/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
import React, { Component } from 'react';

class App extends Component {
constructor(){
super();
this.state = {
listTitle: '',
listItem: '',
itemTitle: '',
lists: []
}
this.addList = this.addList.bind(this);
this.addItem = this.addItem.bind(this);
this.handleChange = this.handleChange.bind(this);
}

componentDidMount(){
this.getLists();
}

getLists() {
fetch('/api/lists')
.then(res => res.json())
.then(data => {
this.setState({lists: data});
});
}

addList(e){
var list = {
title: this.state.listTitle
}
fetch('/api/lists', {
method: 'POST',
body: JSON.stringify(list),
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
})
.then(res => res.json())
.then(data => {
M.toast({html: 'List saved'});
this.setState({listTitle: ''});
this.getLists();
})
.catch(err => console.log(err));
e.preventDefault();
}

addItem(e){
if(this.state.itemTitle != ''){
var item = {
title: this.state.itemTitle
}
fetch('/api/lists/item/'+this.state.listItem, {
method: 'POST',
body: JSON.stringify(item),
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
})
.then(res => res.json())
.then(data => {
M.toast({html: 'Item saved'});
this.setState({listItem: '', itemTitle: ''});
this.getLists();
})
.catch(err => console.log(err));
}
e.preventDefault();
}

handleChange(e) {
const { name, value } = e.target;
this.setState({
[name]: value
});

}

deleteList(id){
fetch('/api/lists/'+id,{
method: 'DELETE',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
})
.then(res => res.json())
.then(data => {
M.toast({html: 'List deleted'});
this.getLists();
})
.catch(err => console.log(err));
}

deleteItem(id, idItem){
fetch('/api/lists/item/'+id+'/'+idItem,{
method: 'DELETE',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
})
.then(res => res.json())
.then(data => {
M.toast({html: 'Item deleted'});
this.getLists();
})
.catch(err => console.log(err));
}

render() {
return (
<div>
{/* NAVIGATION */}
<nav className="amber accent-3">
<div className="container">
<a className="brand-logo" href="/">Favorites</a>
<ul id="nav-mobile" className="right">
<form onSubmit={this.addList}>
<li style={{marginRight:30}}>
<input name="listTitle" type="text" onChange={this.handleChange} style={{ color: '#000000', borderBottomWidth: 0, backgroundColor:'#FFFFFF', paddingLeft:10,paddingRight:10,borderRadius:3}} placeholder="New List"/>
</li>
<li>
<button type='submit' className='btn-floating btn-small waves-effect waves-light grey lighten-5'>
<i className='material-icons' style={{color:'#ffc400'}}>add</i>
</button>
</li>
</form>
</ul>
</div>
</nav>
<div className="container">
<div className="row">
{
this.state.lists.map(list =>{
return (
<div className="col s6" key={list._id}>
<div className="card">
<div className="card-content">
<div className="row">
<span className="card-title col s10" style={{ color: '#00000', borderBottomWidth: 0 }}>{list.title}</span>
<div className="col s2">
<button onClick={()=>this.deleteList(list._id)} className='btn-floating btn-small waves-effect waves-light grey lighten-5'>
<i className='material-icons' style={{ color: '#D1D1D1' }}>delete</i>
</button>
</div>
</div>
{
list.items.map(item =>{
return(
<div className="row" key={item._id}>
<div className="col s10" style={{ color: '#00000', borderBottomWidth: 0 }}>{item.title}</div>
<div className="col s2">
<button onClick={()=>this.deleteItem(list._id,item._id)} className='btn-floating btn-small transparent' style={{ borderWidth: 0, boxShadow: 0 }}>
<i className='material-icons' style={{ color: '#D1D1D1' }}>close</i>
</button>
</div>
</div>
)
})
}
<div className="row" style={{ marginTop: 30 }}>
<form onSubmit={this.addItem}>
<input name="itemTitle" type="text" onChange={this.handleChange} className="col s10" style={{ color: '#00000', borderBottomWidth: 0 }} placeholder="New item"/>
<div className="col s2">
<button type='submit' onClick={()=>this.setState({listItem:list._id})} className='btn-floating btn-small transparent' style={{ borderWidth: 0, boxShadow: 0 }}>
<i className='material-icons' style={{ color: '#D1D1D1' }}>add</i>
</button>
</div>
</form>
</div>
</div>
</div>
</div>
)
})
}

</div>
</div>
</div>
)
}
}

export default App;
6 changes: 6 additions & 0 deletions src/client/app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React, { Component } from 'react';
import { render } from 'react-dom';

import App from "./App";

render(<App/>, document.getElementById('app'));
Loading