-
Notifications
You must be signed in to change notification settings - Fork 13
/
Navbar.js
executable file
·145 lines (134 loc) · 3.86 KB
/
Navbar.js
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import React, { Component } from 'react'
import { PropTypes } from 'prop-types'
import classes from './Navbar.scss'
import { Link } from 'react-router'
import { connect } from 'react-redux'
import {
firebaseConnect,
pathToJS,
isLoaded,
isEmpty
} from 'react-redux-firebase'
import {
LIST_PATH,
ACCOUNT_PATH,
TRANSFER_PATH
} from 'constants/paths'
// Components
import AppBar from 'material-ui/AppBar'
import IconMenu from 'material-ui/IconMenu'
import IconButton from 'material-ui/IconButton'
import MenuItem from 'material-ui/MenuItem'
import FlatButton from 'material-ui/FlatButton'
import DownArrow from 'material-ui/svg-icons/hardware/keyboard-arrow-down'
import Avatar from 'material-ui/Avatar'
import defaultUserImage from 'static/User.png'
const buttonStyle = {
color: 'white',
textDecoration: 'none',
alignSelf: 'center'
}
const avatarStyles = {
wrapper: { marginTop: 0 },
button: { marginRight: '.5rem', width: '200px', height: '64px' },
buttonSm: { marginRight: '.5rem', width: '30px', height: '64px', padding: '0' }
}
@firebaseConnect()
@connect(
({ firebase, faucet }) => ({
authError: pathToJS(firebase, 'authError'),
auth: pathToJS(firebase, 'auth'),
account: pathToJS(firebase, 'profile'),
faucet: faucet
})
)
export default class Navbar extends Component {
static contextTypes = {
router: PropTypes.object.isRequired
}
static propTypes = {
auth: PropTypes.object,
account: PropTypes.object,
firebase: PropTypes.object.isRequired
}
handleLogout = () => {
this.props.firebase.logout()
this.context.router.push('/')
}
render() {
const { account, faucet } = this.props
const accountExists = isLoaded(account) && !isEmpty(account)
const iconButton = (
<IconButton style={avatarStyles.button} disableTouchRipple>
<div className={classes.avatar}>
<div className='hidden-mobile'>
<Avatar
src={accountExists && account.avatarUrl ? account.avatarUrl : defaultUserImage}
/>
</div>
<div className={classes['avatar-text']}>
<span className={`${classes['avatar-text-name']} hidden-mobile`}>
{accountExists && account.displayName ? account.displayName : 'User'}
</span>
<DownArrow color='white' />
</div>
</div>
</IconButton>
)
const mainMenu = (
<div className={classes.menu}>
{/*<Link to={SIGNUP_PATH}>
<FlatButton
label='Sign Up'
style={buttonStyle}
/>
</Link>
<Link to={LOGIN_PATH}>
<FlatButton
label='Login'
style={buttonStyle}
/>
</Link>*/}
<FlatButton
href='https://github.com/transmute-industries/eth-faucet'
label='Source'
style={buttonStyle}
/>
</div>
)
const rightMenu = accountExists ? (
<IconMenu
iconButtonElement={iconButton}
targetOrigin={{ horizontal: 'right', vertical: 'bottom' }}
anchorOrigin={{ horizontal: 'right', vertical: 'top' }}
animated={false}
>
<MenuItem
primaryText='Account'
onTouchTap={() => this.context.router.push(ACCOUNT_PATH)}
/>
<MenuItem
primaryText='Transfer'
onTouchTap={() => this.context.router.push(TRANSFER_PATH)}
/>
<MenuItem
primaryText='Sign out'
onTouchTap={this.handleLogout}
/>
</IconMenu>
) : mainMenu
return (
<AppBar
title={
<Link to={accountExists ? `${LIST_PATH}` : '/'} className={classes.brand}>
ETH Faucet
</Link>
}
showMenuIconButton={false}
iconElementRight={rightMenu}
iconStyleRight={accountExists ? avatarStyles.wrapper : {}}
className={classes.appBar}
/>
)
}
}