# HG changeset patch # User Alexandre Segura # Date 1498748541 -7200 # Node ID e6f85e26b08c70801575a5098f2fbe7f9a0f1622 # Parent fffefefed507c643e9860f4c1a68826d5b9d6303 Confirm logout when pending requests, try to purge offline.outbox diff -r fffefefed507 -r e6f85e26b08c client/src/actions/authActions.js --- a/client/src/actions/authActions.js Thu Jun 29 12:06:48 2017 +0200 +++ b/client/src/actions/authActions.js Thu Jun 29 17:02:21 2017 +0200 @@ -34,3 +34,8 @@ group, }; } + + +export const purgeOutbox = () => { + return { type: types.OFFLINE_PURGE_OUTBOX } +} diff -r fffefefed507 -r e6f85e26b08c client/src/components/Navbar.js --- a/client/src/components/Navbar.js Thu Jun 29 12:06:48 2017 +0200 +++ b/client/src/components/Navbar.js Thu Jun 29 17:02:21 2017 +0200 @@ -4,33 +4,26 @@ import { withRouter } from 'react-router'; import { bindActionCreators } from 'redux'; // import logo from './logo.svg'; -import { Navbar, Nav, NavItem, NavDropdown, MenuItem } from 'react-bootstrap'; +import { Navbar, Nav, NavItem, NavDropdown, MenuItem, Modal, Button } from 'react-bootstrap'; import * as authActions from '../actions/authActions'; -const LoginNav = ({isAuthenticated, currentUser, history, authActions}) => { +const LoginNav = ({isAuthenticated, currentUser, history, authActions, onLogout}) => { const onClickSettings = (e) => { e.preventDefault(); history.push('/settings'); } - const onClickLogout = (e) => { - e.preventDefault(); - authActions.logout(); - history.push('/'); - } - const onClickLogin = (e) => { e.preventDefault(); history.push('/login'); } - if (isAuthenticated) { return ( Settings - Logout + Logout ); } @@ -49,11 +42,47 @@ class AppNavbar extends Component { + state = { + showModal: false + } + + closeModal = () => { + this.setState({ showModal: false }); + } + onClickHome = (e) => { e.preventDefault(); this.props.history.push('/'); } + isOutboxEmpty = () => { + return this.props.offline.outbox.length === 0; + } + + onClickLogout = (e) => { + e.preventDefault(); + const isOutboxEmpty = this.isOutboxEmpty(); + if (isOutboxEmpty) { + this.logout(); + } else { + this.setState({ showModal: true }) + } + } + + confirmLogout = () => { + const isOutboxEmpty = this.isOutboxEmpty(); + if (!isOutboxEmpty) { + this.props.authActions.purgeOutbox(); + } + this.logout(); + this.closeModal(); + } + + logout = () => { + this.props.authActions.logout(); + this.props.history.push('/'); + } + onClickSessions = (e) => { e.preventDefault(); this.props.history.push('/sessions'); @@ -74,9 +103,22 @@ + + +

+ Some data is not synchronized with server. +
+ If you continue, it will be lost. +

+
+ + + + +
); } diff -r fffefefed507 -r e6f85e26b08c client/src/constants/actionTypes.js --- a/client/src/constants/actionTypes.js Thu Jun 29 12:06:48 2017 +0200 +++ b/client/src/constants/actionTypes.js Thu Jun 29 17:02:21 2017 +0200 @@ -17,6 +17,8 @@ export const AUTH_REGISTER_REQUEST = 'AUTH_REGISTER_REQUEST'; export const AUTH_REGISTER_ERROR = 'AUTH_REGISTER_ERROR'; +export const OFFLINE_PURGE_OUTBOX = 'OFFLINE_PURGE_OUTBOX'; + // Used both by login & register export const AUTH_LOGIN_SUCCESS = 'AUTH_LOGIN_SUCCESS'; diff -r fffefefed507 -r e6f85e26b08c client/src/reducers/index.js --- a/client/src/reducers/index.js Thu Jun 29 12:06:48 2017 +0200 +++ b/client/src/reducers/index.js Thu Jun 29 17:02:21 2017 +0200 @@ -5,7 +5,7 @@ import notes from './notesReducer'; import { sessions } from './sessionsReducer'; import { isAuthenticated, currentUser, login, register, token, groups, createGroup } from './authReducer'; -import { autoSubmit } from './miscReducer'; +import { autoSubmit, outbox } from './miscReducer'; const rootReducer = combineReducers({ sessions, @@ -18,7 +18,10 @@ router: routerReducer, autoSubmit, groups, - createGroup + createGroup, + offline: combineReducers({ + outbox + }) }); export default rootReducer; diff -r fffefefed507 -r e6f85e26b08c client/src/reducers/miscReducer.js --- a/client/src/reducers/miscReducer.js Thu Jun 29 12:06:48 2017 +0200 +++ b/client/src/reducers/miscReducer.js Thu Jun 29 17:02:21 2017 +0200 @@ -9,4 +9,14 @@ } } - +export const outbox = (state = [], action) => { + switch (action.type) { + case types.OFFLINE_PURGE_OUTBOX: + // FIXME Does not work + // Need to find a way to purge outbox + // @see https://github.com/jevakallio/redux-offline/issues/68 + return state; + default: + return state; + } +}