summaryrefslogtreecommitdiff
path: root/frontend/common/header.component.js
blob: a4777dcdecc9ddcbfd4c82096c95edd51845bda6 (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
42
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>
        <Link to="/collection/">Collections</Link>
        <Link to="/dashboard/">Dashboard</Link>
        <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);