blob: 452c395e40948c87813837ad3af27d24c888071e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
import React from 'react'
import client from '../client'
export default class Menu extends React.Component {
constructor() {
super()
this.setGoal = this.setGoal.bind(this)
this.logout = this.logout.bind(this)
}
setGoal() {
const goal = Math.abs(parseInt(prompt('Please enter your calorie goal', this.props.user.goal)))
if (goal) {
client.service('users').patch(this.props.user.id, {
goal: goal,
token: client.get('token'),
}).then((user) => {
this.props.updateUser(user)
})
}
}
logout() {
client.logout().then(() => {
window.location.reload()
})
}
render() {
const user = this.props.user
const currentUser = this.props.currentUser
const observing = user.id !== currentUser.id
const items = []
if (observing) {
items.push( <li key='observing'><i>Viewing</i> {user.email}</li> )
}
else {
items.push( <li key='hello'>Hello {currentUser.email}</li> )
}
items.push( <li key='goal' onMouseDown={this.setGoal}><a href='#'>Goal</a>: {user.goal} cal</li> )
switch (currentUser.role) {
case 'admin':
// if (this.props.user.id !== this.props.currentUser.id) {
// items.push( <li key='resetUser'><a href='#' onClick={this.resetUser}>Stop viewing</a></li> )
// }
items.push( <li key='userlist'><a href='#' onClick={this.props.toggleMode}>Users</a></li> )
items.push( <li key='meallist'><a href='#' onClick={this.props.toggleMode}>Meals</a></li> )
break
case 'manager':
items.push( <li key='userlist'><a href='#' onClick={this.props.toggleMode}>Users</a></li> )
items.push( <li key='meallist'><a href='#' onClick={this.props.toggleMode}>Meals</a></li> )
case 'user':
break
}
items.push( <li key='logout'><a href='#' onClick={this.logout}>Logout</a></li> )
return (
<div>
<ul className='menu'>
{items}
</ul>
</div>
)
}
}
|