client/src/components/Navbar.js
author ymh <ymh.work@gmail.com>
Thu, 03 Aug 2017 23:04:33 +0200
changeset 137 279e1dffa213
parent 134 be36eed5e6e0
child 143 cfcbf4bc66f1
permissions -rw-r--r--
session is now created with current group and protocol
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';
134
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
    10
import { groupSetCurrent } from '../actions/groupActions';
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
    11
import { isAuthenticated, getCurrentUser, getOnline, getCurrentGroup, getGroups } from '../selectors/authSelectors';
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
    12
import { isSynchronizing, isSynchronized } from '../selectors/syncSelectors';
130
78246db1cbac make synchronization recurent, improve synchronization status display
ymh <ymh.work@gmail.com>
parents: 129
diff changeset
    13
import './Navbar.css';
12
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    14
107
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    15
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
    16
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    17
  const onClickSettings = (e) => {
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    18
    e.preventDefault();
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    19
    history.push('/settings');
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    20
  }
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    21
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    22
  const onClickLogin = (e) => {
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    23
    e.preventDefault();
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    24
    history.push('/login');
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    25
  }
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    26
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    27
  if (isAuthenticated) {
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    28
    return (
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    29
      <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
    30
        <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
    31
        <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
    32
      </NavDropdown>
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    33
    );
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
  return (
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    36
    <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
    37
  );
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    38
}
14989b339e5d Use a fonctionnal component for the login part of the navbar
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    39
129
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
    40
const Online = ({ online }) => {
81
a6bd1aaddc34 Add online/offline indicator.
Alexandre Segura <mex.zktk@gmail.com>
parents: 65
diff changeset
    41
  return (
a6bd1aaddc34 Add online/offline indicator.
Alexandre Segura <mex.zktk@gmail.com>
parents: 65
diff changeset
    42
    <NavItem>
129
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
    43
      <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
    44
    </NavItem>
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
    45
  )
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
    46
}
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
    47
130
78246db1cbac make synchronization recurent, improve synchronization status display
ymh <ymh.work@gmail.com>
parents: 129
diff changeset
    48
const SyncButton = ({ onSyncClick, isSynchronizing, isSynchronized, id }) => {
78246db1cbac make synchronization recurent, improve synchronization status display
ymh <ymh.work@gmail.com>
parents: 129
diff changeset
    49
  const classnames = "material-icons"
78246db1cbac make synchronization recurent, improve synchronization status display
ymh <ymh.work@gmail.com>
parents: 129
diff changeset
    50
    + ((!isSynchronized)?" sync-button-not-synchronized":"")
78246db1cbac make synchronization recurent, improve synchronization status display
ymh <ymh.work@gmail.com>
parents: 129
diff changeset
    51
    + ((isSynchronizing)?" sync-button-synchronizing":"");
78246db1cbac make synchronization recurent, improve synchronization status display
ymh <ymh.work@gmail.com>
parents: 129
diff changeset
    52
  let title = "Synchronize";
78246db1cbac make synchronization recurent, improve synchronization status display
ymh <ymh.work@gmail.com>
parents: 129
diff changeset
    53
  let clickCb = onSyncClick;
78246db1cbac make synchronization recurent, improve synchronization status display
ymh <ymh.work@gmail.com>
parents: 129
diff changeset
    54
  if(isSynchronizing) {
78246db1cbac make synchronization recurent, improve synchronization status display
ymh <ymh.work@gmail.com>
parents: 129
diff changeset
    55
    title = "Synchronizing...";
78246db1cbac make synchronization recurent, improve synchronization status display
ymh <ymh.work@gmail.com>
parents: 129
diff changeset
    56
    clickCb = () => {};
78246db1cbac make synchronization recurent, improve synchronization status display
ymh <ymh.work@gmail.com>
parents: 129
diff changeset
    57
  } else if (!isSynchronized) {
78246db1cbac make synchronization recurent, improve synchronization status display
ymh <ymh.work@gmail.com>
parents: 129
diff changeset
    58
    title += ": not synchronized";
78246db1cbac make synchronization recurent, improve synchronization status display
ymh <ymh.work@gmail.com>
parents: 129
diff changeset
    59
  }
78246db1cbac make synchronization recurent, improve synchronization status display
ymh <ymh.work@gmail.com>
parents: 129
diff changeset
    60
129
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
    61
  return (
130
78246db1cbac make synchronization recurent, improve synchronization status display
ymh <ymh.work@gmail.com>
parents: 129
diff changeset
    62
    <NavItem title={title} onClick={clickCb} id={id || null}>
78246db1cbac make synchronization recurent, improve synchronization status display
ymh <ymh.work@gmail.com>
parents: 129
diff changeset
    63
      <span className={classnames}>&#xE627;</span>
81
a6bd1aaddc34 Add online/offline indicator.
Alexandre Segura <mex.zktk@gmail.com>
parents: 65
diff changeset
    64
    </NavItem>
a6bd1aaddc34 Add online/offline indicator.
Alexandre Segura <mex.zktk@gmail.com>
parents: 65
diff changeset
    65
  )
a6bd1aaddc34 Add online/offline indicator.
Alexandre Segura <mex.zktk@gmail.com>
parents: 65
diff changeset
    66
}
a6bd1aaddc34 Add online/offline indicator.
Alexandre Segura <mex.zktk@gmail.com>
parents: 65
diff changeset
    67
134
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
    68
const GroupStatus = ({currentGroup, groups, onSelect}) => {
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
    69
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
    70
  if(currentGroup) {
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
    71
    const currentGroupName = currentGroup.get('name');
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
    72
    return (
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
    73
      <NavDropdown title={currentGroupName} id="group-dropdown" onSelect={onSelect}>
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
    74
        { groups && groups.map((group, key) => {
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
    75
            const groupName = group.get('name');
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
    76
            const className = (groupName === currentGroupName)?'active':null;
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
    77
            return <MenuItem className={className} key={key} eventKey={groupName}>{ groupName }</MenuItem>
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
    78
          }
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
    79
        )}
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
    80
        <MenuItem key="-1" eventKey="__create_group__">Créer un groupe...</MenuItem>
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
    81
      </NavDropdown>
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
    82
    )
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
    83
  } else {
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
    84
    return null;
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
    85
  }
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
    86
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
    87
}
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
    88
12
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    89
class AppNavbar extends Component {
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    90
107
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    91
  state = {
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    92
    showModal: false
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    93
  }
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    94
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    95
  closeModal = () => {
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    96
    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
    97
  }
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
    98
12
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    99
  onClickHome = (e) => {
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   100
    e.preventDefault();
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   101
    this.props.history.push('/');
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   102
  }
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   103
129
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
   104
  isSynchronized = () => {
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
   105
    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
   106
  }
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   107
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   108
  onClickLogout = (e) => {
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   109
    e.preventDefault();
129
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
   110
    const isSynchronized = this.isSynchronized();
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
   111
    if (isSynchronized) {
107
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   112
      this.logout();
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   113
    } else {
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   114
      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
   115
    }
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   116
  }
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   117
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   118
  confirmLogout = () => {
129
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
   119
    const isSynchronized = this.isSynchronized();
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
   120
    if (!isSynchronized) {
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
   121
      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
   122
    }
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   123
    this.logout();
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   124
    this.closeModal();
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   125
  }
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   126
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   127
  logout = () => {
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   128
    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
   129
    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
   130
  }
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   131
12
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   132
  onClickSessions = (e) => {
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   133
    e.preventDefault();
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   134
    this.props.history.push('/sessions');
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   135
  }
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   136
129
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
   137
  onSyncClick = (e) => {
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
   138
    e.preventDefault();
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
   139
    this.props.networkActions.forceSync();
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
   140
  }
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
   141
134
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   142
  onGroupSelect = (groupName) => {
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   143
    if(groupName === "__create_group__") {
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   144
      this.props.history.push('/create-group');
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   145
    } else {
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   146
      this.props.groupActions.groupSetCurrent(groupName);
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   147
    }
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   148
  }
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   149
12
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   150
  render() {
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   151
    return (
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   152
      <Navbar fluid inverse fixedTop>
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   153
        <Navbar.Header>
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   154
          <Navbar.Brand>
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   155
            <a onClick={this.onClickHome} href="/">IRI Notes</a>
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   156
          </Navbar.Brand>
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   157
          <Navbar.Toggle />
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   158
        </Navbar.Header>
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   159
        <Navbar.Collapse>
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   160
          <Nav>
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   161
            <NavItem onClick={this.onClickSessions} href="/sessions">Sessions</NavItem>
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   162
          </Nav>
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   163
          <Nav pullRight>
134
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   164
            <GroupStatus currentGroup={this.props.currentGroup} groups={this.props.groups} onSelect={this.onGroupSelect}/>
130
78246db1cbac make synchronization recurent, improve synchronization status display
ymh <ymh.work@gmail.com>
parents: 129
diff changeset
   165
            <SyncButton id='sync-button' onSyncClick={this.onSyncClick} isSynchronizing={this.props.isSynchronizing} isSynchronized={this.props.isSynchronized} />
81
a6bd1aaddc34 Add online/offline indicator.
Alexandre Segura <mex.zktk@gmail.com>
parents: 65
diff changeset
   166
            <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
   167
            <LoginNav {...this.props} onLogout={this.onClickLogout} />
12
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   168
          </Nav>
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   169
        </Navbar.Collapse>
107
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   170
        <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
   171
          <Modal.Body>
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   172
            <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
   173
              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
   174
              <br />
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   175
              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
   176
            </p>
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   177
          </Modal.Body>
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   178
          <Modal.Footer>
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   179
            <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
   180
            <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
   181
          </Modal.Footer>
e6f85e26b08c Confirm logout when pending requests, try to purge offline.outbox
Alexandre Segura <mex.zktk@gmail.com>
parents: 105
diff changeset
   182
        </Modal>
12
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   183
      </Navbar>
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   184
    );
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   185
  }
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   186
}
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   187
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   188
AppNavbar.propTypes = {
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   189
  isAuthenticated: PropTypes.bool.isRequired
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   190
};
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   191
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   192
function mapStateToProps(state, props) {
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   193
  return {
134
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   194
    isAuthenticated: isAuthenticated(state),
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   195
    currentUser: getCurrentUser(state),
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   196
    online: getOnline(state),
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   197
    isSynchronizing: isSynchronizing(state),
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   198
    isSynchronized: isSynchronized(state),
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   199
    currentGroup: getCurrentGroup(state),
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   200
    groups: getGroups(state)
12
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   201
  };
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   202
}
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   203
52
96f8a4a59bd9 Implement logout.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   204
function mapDispatchToProps(dispatch) {
96f8a4a59bd9 Implement logout.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   205
  return {
96f8a4a59bd9 Implement logout.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   206
    authActions: bindActionCreators(authActions, dispatch),
134
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   207
    networkActions: bindActionCreators({ forceSync }, dispatch),
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   208
    groupActions: bindActionCreators({ groupSetCurrent }, dispatch)
52
96f8a4a59bd9 Implement logout.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   209
  }
96f8a4a59bd9 Implement logout.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   210
}
96f8a4a59bd9 Implement logout.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   211
105
0a1d6560acac Introduce authenticated routes.
Alexandre Segura <mex.zktk@gmail.com>
parents: 104
diff changeset
   212
export default connect(mapStateToProps, mapDispatchToProps)(withRouter(AppNavbar));