-
Notifications
You must be signed in to change notification settings - Fork 38
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
weekend za delivereat #22
Open
zuberman
wants to merge
1
commit into
constructorlabs:master
Choose a base branch
from
zuberman:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React from 'react'; | ||
|
||
import '../styles/AddOrderModal.scss'; | ||
|
||
class AddOrderModal extends React.Component { | ||
constructor(){ | ||
super(); | ||
|
||
this.state= { | ||
quantity: 1, | ||
} | ||
|
||
this.handleClick = this.handleClick.bind(this); | ||
this.handleSubmit = this.handleSubmit.bind(this); | ||
this.handleChange = this.handleChange.bind(this); | ||
} | ||
|
||
|
||
handleClick(event) { | ||
this.props.receiveModalCloseBtn(); | ||
this.setState({ | ||
quantity: 1, | ||
}) | ||
} | ||
|
||
handleSubmit(event) { | ||
event.preventDefault() | ||
this.props.updateOrder(this.props.modalDetails.id, this.state.quantity); | ||
this.props.receiveModalCloseBtn(); | ||
this.setState({ | ||
quantity: 1, | ||
}) | ||
} | ||
|
||
handleChange(event) { | ||
this.setState({ | ||
quantity: parseInt(event.target.value, 10), | ||
}) | ||
} | ||
|
||
render(){ | ||
return( | ||
<div className={this.props.className} id="addOrderModal"> | ||
<div className="modal-content"> | ||
<div className="modal-header"> | ||
<span className="closeBtn" onClick={this.handleClick}>×</span> | ||
<h2>Add to Order</h2> | ||
</div> | ||
<div className="modal-body"> | ||
<img src={"/static/"+this.props.modalDetails.photoUrl} /> | ||
<h3>{this.props.modalDetails.description}</h3> | ||
<form className="itemOrder" onSubmit={this.handleSubmit}> | ||
<input onChange={this.handleChange} value={this.state.quantity} type="number" step="1" max="10" min="1"/> | ||
<button>Add to Order</button> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
} | ||
|
||
export default AddOrderModal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import React from 'react'; | ||
import AddOrderModal from './AddOrderModal.js' | ||
import Order from './Order.js' | ||
|
||
// import '../styles/Menu.scss'; | ||
|
||
class Menu extends React.Component { | ||
constructor(){ | ||
super(); | ||
|
||
this.state ={ | ||
menu: [], | ||
modalDetails: "", | ||
modalOpen: false, | ||
order: {}, | ||
total: "" | ||
} | ||
|
||
this.menuCall = this.menuCall.bind(this); | ||
this.itemCall = this.itemCall.bind(this); | ||
this.handleClick = this.handleClick.bind(this); | ||
this.updateOrder = this.updateOrder.bind(this); | ||
this.receiveModalCloseBtn = this.receiveModalCloseBtn.bind(this); | ||
this.receiveOrderSubmit = this.receiveOrderSubmit.bind(this); | ||
this.receiveRemoveItem = this.receiveRemoveItem.bind(this); | ||
} | ||
|
||
componentDidMount(){ | ||
this.menuCall() | ||
} | ||
|
||
menuCall(){ | ||
fetch(`/menu`) | ||
.then(function(response) { | ||
return response.json(); | ||
}) | ||
.then(body => { | ||
this.setState({ | ||
menu: body | ||
}) | ||
}) | ||
} | ||
|
||
itemCall(menuId){ | ||
fetch(`/menu/${menuId}`) | ||
.then(function(response) { | ||
return response.json(); | ||
}) | ||
.then(body => { | ||
this.setState({ | ||
modalDetails: body | ||
}) | ||
}) | ||
} | ||
|
||
handleClick(menuId) { | ||
this.itemCall(menuId); | ||
this.setState({ | ||
modalOpen: true | ||
}) | ||
} | ||
|
||
receiveModalCloseBtn(){ | ||
this.setState({ | ||
modalOpen: false, | ||
}) | ||
} | ||
|
||
updateOrder(itemId, itemQuantity){ | ||
const newOrder = Object.assign({}, this.state.order); | ||
|
||
if (newOrder[itemId]) { | ||
newOrder[itemId] = newOrder[itemId] + itemQuantity | ||
} else { | ||
newOrder[itemId] = itemQuantity | ||
} | ||
|
||
Object.entries(this.order).reduce() | ||
|
||
this.setState({ | ||
order: newOrder, | ||
total: "" | ||
}) | ||
} | ||
|
||
receiveOrderSubmit(){ | ||
fetch(`/order`, {method:"POST", headers: { | ||
"Content-Type": "application/json; charset=utf-8", | ||
}, body: JSON.stringify(this.state.order)}) | ||
this.setState({ | ||
order: {} | ||
}) | ||
} | ||
|
||
receiveRemoveItem(menuItem){ | ||
const orderEntries = Object.entries(this.state.order); | ||
console.log(menuItem) | ||
// this.setState{( | ||
// order: | ||
// )} | ||
} | ||
|
||
render(){ | ||
return( | ||
<div> | ||
{this.state.menu.map (item => { | ||
return( | ||
<div onClick={() => this.handleClick(item.id)}> | ||
{item.name}{item.price} | ||
{item.vegetarian ? <img className="vegan" src="static/vegan.png" /> : null} | ||
</div> | ||
) | ||
})} | ||
<div><AddOrderModal receiveModalCloseBtn={this.receiveModalCloseBtn} updateOrder={this.updateOrder} className= {this.state.modalOpen ? "modal2" : "modal"} modalDetails={this.state.modalDetails}/></div> | ||
<div><Order receiveRemoveItem={this.receiveRemoveItem} receiveOrderSubmit={this.receiveOrderSubmit} order={this.state.order} menu={this.state.menu} /></div> | ||
</div> | ||
) | ||
|
||
} | ||
} | ||
|
||
export default Menu; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React from 'react'; | ||
|
||
class Order extends React.Component { | ||
constructor(){ | ||
super(); | ||
|
||
this.state= { | ||
} | ||
|
||
this.handleClick=this.handleClick.bind(this); | ||
this.handleClick2=this.handleClick2.bind(this); | ||
} | ||
|
||
handleClick(){ | ||
this.props.receiveOrderSubmit(); | ||
} | ||
|
||
handleClick2(id){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this could have a more descriptive name |
||
this.props.receiveRemoveItem(id); | ||
} | ||
|
||
render(){ | ||
return( | ||
<div> | ||
<h3>Your Order Basket</h3> | ||
<div> | ||
{Object.entries(this.props.order).map (([id, quantity]) => { | ||
const menuItem = this.props.menu.find(item => item.id.toString() === id) | ||
return( | ||
<div data-id={id}> | ||
{quantity}x {id} x {menuItem.name} x £{menuItem.price} | ||
<button | ||
data-id={id} | ||
key={menuItem.id} | ||
receiveRemoveItem={this.props.receiveRemoveItem} | ||
onClick={event => this.handleClick2(id)}>Remove Item</button> | ||
</div> | ||
) | ||
})} | ||
</div> | ||
<div> | ||
<button onClick={this.handleClick} >Submit</button> | ||
</div> | ||
<div> | ||
<button onClick={this.handleClick} >Submit</button> | ||
</div> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
export default Order |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to put setState inside a then so you can ensure that the POSTt has completed successfully