Skip to content

Commit

Permalink
did the selector shit
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee Rouse authored and Lee Rouse committed Oct 19, 2017
1 parent 9e3f0af commit 6a78a80
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 39 deletions.
2 changes: 1 addition & 1 deletion potluck/public/index.html
Expand Up @@ -8,7 +8,7 @@
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" type="image/gif">
<link rel="shortcut icon" href="%PUBLIC_URL%/nicky_cage.gif">
<!--
Notice the use of %PUBLIC_URL% in the tags above.
Expand Down
34 changes: 1 addition & 33 deletions potluck/src/GroceryItem/GroceryItem.js
Expand Up @@ -6,47 +6,15 @@ export default class GroceryItem extends Component {
constructor() {
super()
this.selectorToggle = this.selectorToggle.bind(this);
this.selectorToServer = this.selectorToServer.bind(this);
this.state = {
selector: 0
}
}

selectorToServer(id) {
fetch('/items/' + id, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
selector: this.state.selector
})
}).then((res) => {
console.log(res);
return res.json();
}).then((data) => {
this.setState({
items: data
});
});
}

selectorToggle(id) {
if (this.state.selector === 0) {
this.setState({
selector: this.state.selector + 1
})
this.selectorToServer(id);
}
else {
this.setState({
selector: this.state.selector - 1
})
this.selectorToServer(id);
}
this.props.selectorToServer(id);
}


render() {
console.log(this.props);
return (
<tr>
<td><ListGroup>
Expand Down
28 changes: 25 additions & 3 deletions potluck/src/GroceryList/GroceryList.js
Expand Up @@ -5,13 +5,35 @@ import './GroceryList.css';

export default class GroceryList extends Component {
constructor(){
super()

super();
this.selectorToServer = this.selectorToServer.bind(this);
this.state = {
selector: 0
}
}

selectorToServer(id) {
fetch('/items/' + id, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
selector: this.state.selector
})
}).then((res) => {
console.log(res);
return res.json();
}).then((data) => {
this.setState({
selector: data.selector
});
});
}

render(){
console.log("HERE")
console.log(this.state.selector);
let newList = this.props.items.map((item, i)=>{
return <GroceryItem class='grocery-item' deleteItem={this.props.deleteItem} items={this.props.items[i]}/>
return <GroceryItem class='grocery-item' deleteItem={this.props.deleteItem} items={this.props.items[i]} selectorToServer={this.selectorToServer}/>
})
console.log(newList)
return(
Expand Down
11 changes: 9 additions & 2 deletions server.js
Expand Up @@ -67,13 +67,20 @@ app.put('/items/:id', (req, res, next)=>{
console.log(err);
next(err);
} else {
item.selector = req.body.selector;
if(item.selector === 0){
item.selector = 1;
}else{
item.selector = 0;
}
console.log("HERE");
console.log(item.selector);
// item.selector = req.body.selector;
item.save((err, itemReturned)=>{
if(err){
console.log(err);
next(err);
} else {
res.json('item updated in db' + itemReturned);
res.json( itemReturned);
}
});
};
Expand Down

0 comments on commit 6a78a80

Please sign in to comment.