summaryrefslogtreecommitdiff
path: root/client/components/UserList.jsx
blob: fb93b9fad95bf7223cedc1a881e44411e434343b (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
65
66
67
68
69
70
71
72
73
74
75
import React from 'react'

import client from '../client'

export default class UserList extends React.Component {
  constructor(props){
    super()
    console.log("WHAT")
    this.state = {
      users: [],
    }
//     client.service('users').find({
//       query: {
//         '$sort': { 'date': '-1' },
//         token: client.get('token'),
//       },
//     }).then((data) => {
//       this.setState(data)
//     }).catch((error) => {
//       console.error(error)
//     })
    this.pick.bind(this)
  }
  pick(){
  }
  render() {
    const items = this.state.users.map((item,i) => {
      return (
        <UserItem key={user.id}
          user={user}
          onClick={this.pick}
          onDelete={this.handleDelete} />
      )
    })
    return (
      <div>
        {items}
      </div>
    )
  }
}

class UserItem extends React.Component {
  constructor() {
    super()
    this.remove = this.remove.bind(this)
  }
  remove(e) {
    e.stopPropagation()
    const userid = this.props.user.id
    const usersService = client.service('users')
    const params = { query: { token: client.get('token') } }
    usersService.remove(userid, params).then(result => {
      this.props.onDelete(userid)
    }).catch(error => {
      console.error(error)
    })
  }
  render() {
    const user = this.props.user
    // const canEdit = this.props.user.userid === this.props.currentUser.id ? 'canEdit' : ''
    const canEdit = 'canEdit'
    const date = parseDate(meal.date)
    const time = parseTime(meal.date)
    return (
      <div className={'user row ' + canEdit} onClick={() => this.props.onClick(meal)}>
        <div className='name'>{meal.name}</div>
        <div className='calories'>{meal.calories} cal</div>
        <div className='date'>{date}</div>
        <div className='time'>{time}</div>
        <div className='remove' onClick={this.remove}>x</div>
      </div>
    )
  }
}