From 6ae0c07daeea0e03c832b3aa0f838778627431d8 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 20 Mar 2017 04:48:32 +0100 Subject: view app as a different user --- client/components/UserList.jsx | 57 +++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 20 deletions(-) (limited to 'client/components/UserList.jsx') diff --git a/client/components/UserList.jsx b/client/components/UserList.jsx index fb93b9f..3e87ec5 100644 --- a/client/components/UserList.jsx +++ b/client/components/UserList.jsx @@ -5,30 +5,37 @@ import client from '../client' export default class UserList extends React.Component { constructor(props){ super() - console.log("WHAT") + console.log("USER") this.state = { - users: [], + data: [], } -// client.service('users').find({ -// query: { -// '$sort': { 'date': '-1' }, -// token: client.get('token'), -// }, -// }).then((data) => { -// this.setState(data) -// }).catch((error) => { -// console.error(error) -// }) + client.service('users').find({ + query: { + '$sort': { 'email': '1' }, + token: client.get('token'), + }, + }).then((data) => { + this.setState(data) + }).catch((error) => { + console.error(error) + }) this.pick.bind(this) + console.log(props) } - pick(){ + pick(user){ + // bubble this up.. + console.log(user) + console.log(this) + this.props.updateUser(user) } render() { - const items = this.state.users.map((item,i) => { + console.log(this.state.data) + const items = this.state.data.map((user,i) => { return ( this.pick(user)} onDelete={this.handleDelete} /> ) }) @@ -59,13 +66,15 @@ class UserItem extends React.Component { render() { const user = this.props.user // const canEdit = this.props.user.userid === this.props.currentUser.id ? 'canEdit' : '' + const userClass = this.props.user.id == this.props.activeUser.id ? 'active' : '' const canEdit = 'canEdit' - const date = parseDate(meal.date) - const time = parseTime(meal.date) + const date = parseDate(user.updatedAt) + const time = parseTime(user.updatedAt) return ( -
this.props.onClick(meal)}> -
{meal.name}
-
{meal.calories} cal
+
this.props.onClick(this.props.user)}> +
{user.email}
+
{user.goal} cal
+
{user.role}
{date}
{time}
x
@@ -73,3 +82,11 @@ class UserItem extends React.Component { ) } } + +function parseDate(d){ + return new Date(d).toISOString().substr(0, 10) +} + +function parseTime(d){ + return new Date(d).toISOString().substr(11, 5) +} -- cgit v1.2.3-70-g09d2