Make list use data/render model

This commit is contained in:
John Lyon-Smith
2018-03-19 08:05:48 -07:00
parent bfd86b5b46
commit 59c11d791d
2 changed files with 10 additions and 14 deletions

View File

@@ -27,26 +27,23 @@ export class UserList extends React.Component {
render() { render() {
const { selectedUser, selectionModified } = this.props const { selectedUser, selectionModified } = this.props
const { users } = this.state
return ( return (
<Column fillParent> <Column fillParent>
<Column.Item grow> <Column.Item grow>
<List> <List data={users} render={(user, index) => {
{ return (
this.state.users <List.Item key={user._id || '0'} onClick={(e) => (this.props.onUserListClick(e, index))}
? this.state.users.map((user, index) =>
(<List.Item key={user._id || '0'} onClick={(e) => (this.props.onUserListClick(e, index))}
active={user === this.props.selectedUser}> active={user === this.props.selectedUser}>
<List.Icon name={user.administrator ? 'admin' : 'profile'} size={sizeInfo.listIcon} /> <List.Icon name={user.administrator ? 'admin' : 'profile'} size={sizeInfo.listIcon} />
<List.Text> <List.Text>
{ user._id ? user.firstName + ' ' + user.lastName : '[New User]' } { user._id ? user.firstName + ' ' + user.lastName : '[New User]' }
</List.Text> </List.Text>
{ user === selectedUser && selectionModified ? <List.Icon name='edit' size={sizeInfo.listIcon} /> : null } { user === selectedUser && selectionModified ? <List.Icon name='edit' size={sizeInfo.listIcon} /> : null }
</List.Item>) </List.Item>
) )
: null }} />
}
</List>
</Column.Item> </Column.Item>
<Column.Item height={sizeInfo.formColumnSpacing} /> <Column.Item height={sizeInfo.formColumnSpacing} />
<Column.Item height={sizeInfo.buttonHeight}> <Column.Item height={sizeInfo.buttonHeight}>

View File

@@ -6,13 +6,12 @@ import { sizeInfo, colorInfo, fontInfo } from './style'
class List extends Component { class List extends Component {
static propTypes = { static propTypes = {
children: PropTypes.node, data: PropTypes.array,
// data: PropTypes.array, render: PropTypes.func.isRequired,
// render: PropTypes.func,
} }
render() { render() {
const { children } = this.props const { data, render } = this.props
return ( return (
<Box <Box
@@ -24,7 +23,7 @@ class List extends Component {
fontFamily: fontInfo.family, fontFamily: fontInfo.family,
overflow: 'scroll', overflow: 'scroll',
}}> }}>
{children} {data ? data.map(render) : null}
</Box> </Box>
) )
} }