summaryrefslogtreecommitdiff
path: root/frontend/common/header.component.js
blob: 5cb15b563c75d87b5c210d5b9f0564a8535106f2 (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
import React from 'react'
// import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { Link } from 'react-router-dom'
import { session } from '../session'

function Header(props) {
  return (
    <header>
      <div>
        <Link to="/" className="logo"><b>swimmer</b></Link>
      </div>
      <div>
        <span className='username' onClick={() => changeUsername()}>
          {' → '}{props.username}
        </span>
      </div>
    </header>
  )
}

const changeUsername = () => {
  const username = prompt("Please enter your username:", session('username'))
  if (username && username.length) {
    session.set('username', username)
    document.querySelector('Header div span').innerText = ' → ' + username // very naughty
  }
}


const mapStateToProps = (state) => ({
  auth: state.auth,
  username: session.get('username'),
  isAuthenticated: state.auth.isAuthenticated,
})

const mapDispatchToProps = (dispatch) => ({
})

export default connect(mapStateToProps, mapDispatchToProps)(Header)