client/src/components/Navbar.js
author ymh <ymh.work@gmail.com>
Fri, 28 Jul 2017 19:40:35 +0200
changeset 129 d48946d164c6
parent 107 e6f85e26b08c
child 130 78246db1cbac
permissions -rw-r--r--
Add a first version of synchronisation Remove redux-offline dependency make the redux state fully immutable TODO: better error management TODO: make syncronization work automatically
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
     1
import PropTypes from 'prop-types';
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
     2
import React, { Component } from 'react';
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
     3
import { connect } from 'react-redux';
105
0a1d6560acac Introduce authenticated routes.
Alexandre Segura <mex.zktk@gmail.com>
parents: 104
diff changeset
     4
import { withRouter } from 'react-router';
52
96f8a4a59bd9 Implement logout.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
     5
import { bindActionCreators } from 'redux';
12
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
     6
// import logo from './logo.svg';
107
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
     7
import { Navbar, Nav, NavItem, NavDropdown, MenuItem, Modal, Button } from 'react-bootstrap';
52
96f8a4a59bd9 Implement logout.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
     8
import * as authActions from '../actions/authActions';
129
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
     9
import { forceSync } from '../actions/networkActions';
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
    10
import { ActionEnum } from '../constants';
12
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    11
107
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    12
const LoginNav = ({isAuthenticated, currentUser, history, authActions, onLogout}) => {
65
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    13
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    14
  const onClickSettings = (e) => {
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    15
    e.preventDefault();
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    16
    history.push('/settings');
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    17
  }
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    18
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    19
  const onClickLogin = (e) => {
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    20
    e.preventDefault();
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    21
    history.push('/login');
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    22
  }
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    23
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    24
  if (isAuthenticated) {
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    25
    return (
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    26
      <NavDropdown title={ currentUser.get('username') } id="user-dropdown">
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    27
        <MenuItem onClick={onClickSettings}>Settings</MenuItem>
107
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    28
        <MenuItem onClick={onLogout}>Logout</MenuItem>
65
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    29
      </NavDropdown>
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    30
    );
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    31
  }
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    32
  return (
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    33
    <NavItem onClick={onClickLogin} href="/login">Login</NavItem>
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    34
  );
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    35
}
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    36
129
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
    37
const Online = ({ online }) => {
81
a6bd1aaddc34 Add online/offline indicator.
Alexandre Segura <mex.zktk@gmail.com>
parents: 65
diff changeset
    38
  return (
a6bd1aaddc34 Add online/offline indicator.
Alexandre Segura <mex.zktk@gmail.com>
parents: 65
diff changeset
    39
    <NavItem>
129
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
    40
      <span className="material-icons" style={{ color: online ? '#2ECC71' : '#E74C3C' }}>signal_wifi_4_bar</span>
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
    41
    </NavItem>
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
    42
  )
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
    43
}
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
    44
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
    45
const SyncButton = ({ onSyncClick, isSynchronizing }) => {
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
    46
  return (
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
    47
    <NavItem onClick={onSyncClick}>
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
    48
      Sync
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
    49
      {isSynchronizing && <span className="material-icons">&#xE627;</span>}
81
a6bd1aaddc34 Add online/offline indicator.
Alexandre Segura <mex.zktk@gmail.com>
parents: 65
diff changeset
    50
    </NavItem>
a6bd1aaddc34 Add online/offline indicator.
Alexandre Segura <mex.zktk@gmail.com>
parents: 65
diff changeset
    51
  )
a6bd1aaddc34 Add online/offline indicator.
Alexandre Segura <mex.zktk@gmail.com>
parents: 65
diff changeset
    52
}
a6bd1aaddc34 Add online/offline indicator.
Alexandre Segura <mex.zktk@gmail.com>
parents: 65
diff changeset
    53
12
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    54
class AppNavbar extends Component {
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    55
107
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    56
  state = {
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    57
    showModal: false
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    58
  }
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    59
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    60
  closeModal = () => {
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    61
    this.setState({ showModal: false });
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    62
  }
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    63
12
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    64
  onClickHome = (e) => {
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    65
    e.preventDefault();
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    66
    this.props.history.push('/');
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    67
  }
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    68
129
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
    69
  isSynchronized = () => {
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
    70
    return this.props.isSynchronized;
107
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    71
  }
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    72
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    73
  onClickLogout = (e) => {
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    74
    e.preventDefault();
129
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
    75
    const isSynchronized = this.isSynchronized();
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
    76
    if (isSynchronized) {
107
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    77
      this.logout();
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    78
    } else {
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    79
      this.setState({ showModal: true })
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    80
    }
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    81
  }
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    82
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    83
  confirmLogout = () => {
129
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
    84
    const isSynchronized = this.isSynchronized();
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
    85
    if (!isSynchronized) {
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
    86
      this.props.authActions.resetAll();
107
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    87
    }
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    88
    this.logout();
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    89
    this.closeModal();
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    90
  }
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    91
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    92
  logout = () => {
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    93
    this.props.authActions.logout();
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    94
    this.props.history.push('/');
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    95
  }
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    96
12
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    97
  onClickSessions = (e) => {
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    98
    e.preventDefault();
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    99
    this.props.history.push('/sessions');
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   100
  }
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   101
129
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
   102
  onSyncClick = (e) => {
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
   103
    e.preventDefault();
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
   104
    this.props.networkActions.forceSync();
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
   105
  }
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
   106
12
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   107
  render() {
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   108
    return (
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   109
      <Navbar fluid inverse fixedTop>
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   110
        <Navbar.Header>
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   111
          <Navbar.Brand>
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   112
            <a onClick={this.onClickHome} href="/">IRI Notes</a>
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   113
          </Navbar.Brand>
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   114
          <Navbar.Toggle />
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   115
        </Navbar.Header>
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   116
        <Navbar.Collapse>
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   117
          <Nav>
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   118
            <NavItem onClick={this.onClickSessions} href="/sessions">Sessions</NavItem>
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   119
          </Nav>
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   120
          <Nav pullRight>
129
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
   121
            <SyncButton onSyncClick={this.onSyncClick} isSynchronizing={this.props.isSynchronizing}/>
81
a6bd1aaddc34 Add online/offline indicator.
Alexandre Segura <mex.zktk@gmail.com>
parents: 65
diff changeset
   122
            <Online {...this.props} />
107
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   123
            <LoginNav {...this.props} onLogout={this.onClickLogout} />
12
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   124
          </Nav>
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   125
        </Navbar.Collapse>
107
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   126
        <Modal show={this.state.showModal} onHide={this.closeModal}>
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   127
          <Modal.Body>
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   128
            <p className="text-center">
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   129
              Some data is not synchronized with server.
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   130
              <br />
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   131
              If you continue, it will be lost.
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   132
            </p>
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   133
          </Modal.Body>
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   134
          <Modal.Footer>
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   135
            <Button bsStyle="primary" onClick={this.confirmLogout}>Confirm</Button>
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   136
            <Button onClick={this.closeModal}>Close</Button>
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   137
          </Modal.Footer>
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   138
        </Modal>
12
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   139
      </Navbar>
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   140
    );
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   141
  }
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   142
}
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   143
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   144
AppNavbar.propTypes = {
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   145
  isAuthenticated: PropTypes.bool.isRequired
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   146
};
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   147
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   148
function mapStateToProps(state, props) {
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   149
  return {
129
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
   150
    isAuthenticated: state.getIn(['authStatus', 'isAuthenticated']),
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
   151
    currentUser: state.getIn(['authStatus', 'currentUser']),
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
   152
    online: state.getIn(['status', 'online']),
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
   153
    isSynchronizing: state.getIn(['status', 'isSynchronizing']),
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
   154
    isSynchronized: state.get('notes').every((n) => n.get('action')===ActionEnum.NONE) &&
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
   155
      state.get('sessions').every((n) => n.get('action')===ActionEnum.NONE)
12
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   156
  };
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   157
}
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   158
52
96f8a4a59bd9 Implement logout.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   159
function mapDispatchToProps(dispatch) {
96f8a4a59bd9 Implement logout.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   160
  return {
96f8a4a59bd9 Implement logout.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   161
    authActions: bindActionCreators(authActions, dispatch),
129
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
   162
    networkActions: bindActionCreators({ forceSync }, dispatch)
52
96f8a4a59bd9 Implement logout.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   163
  }
96f8a4a59bd9 Implement logout.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   164
}
96f8a4a59bd9 Implement logout.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   165
105
0a1d6560acac Introduce authenticated routes.
Alexandre Segura <mex.zktk@gmail.com>
parents: 104
diff changeset
   166
export default connect(mapStateToProps, mapDispatchToProps)(withRouter(AppNavbar));