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

function Header(props) {
  return (
    <header>
      <div>
        <Link to="/" className="logo"><b>{props.site.siteTitle}</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,
  site: state.site,
  username: session.get('username'),
  // isAuthenticated: state.auth.isAuthenticated,
})

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

export default connect(mapStateToProps, mapDispatchToProps)(Header)