Skip to content
This repository has been archived by the owner on Oct 1, 2019. It is now read-only.

Commit

Permalink
Fix sidebar switching off/on on wide screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
agat committed May 5, 2016
1 parent 95f1a6f commit f371e5b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
14 changes: 14 additions & 0 deletions src/actions/index.js
Expand Up @@ -99,6 +99,8 @@ export const UPDATE_EDIT_POST_FORM = 'UPDATE_EDIT_POST_FORM';

export const UI__SET_PROGRESS = 'UI__SET_PROGRESS';
export const UI__TOGGLE_SIDEBAR = 'UI__TOGGLE_SIDEBAR';
export const UI__SWITCH_OFF_SIDEBAR = 'UI__SWITCH_OFF_SIDEBAR';
export const UI__SWITCH_ON_SIDEBAR = 'UI__SWITCH_ON_SIDEBAR';

export function addUser(user) {
return {
Expand Down Expand Up @@ -550,6 +552,18 @@ export function toggleUISidebar(isVisible) {
}
}

export function switchOffUISidebar() {
return {
type: UI__SWITCH_OFF_SIDEBAR
}
}

export function switchONUISidebar() {
return {
type: UI__SWITCH_ON_SIDEBAR
}
}

export function setPostComments(postId, comments) {
return {
type: SET_POST_COMMENTS,
Expand Down
17 changes: 14 additions & 3 deletions src/components/header-logo.js
Expand Up @@ -21,16 +21,27 @@ import React, {
import { Link } from 'react-router';
import { connect } from 'react-redux';

import { toggleUISidebar } from '../actions';
import {
toggleUISidebar,
switchOffUISidebar,
switchONUISidebar
} from '../actions';
import currentUserSelector from '../selectors/currentUser';
import createSelector from '../selectors/createSelector';

class HeaderLogo extends Component {
toggleSidebar = () => {
const {
dispatch
dispatch,
ui
} = this.props;

if (ui.get('sidebarIsVisible')) {
dispatch(switchOffUISidebar());
} else {
dispatch(switchONUISidebar());
}

dispatch(toggleUISidebar());
};

Expand All @@ -55,7 +66,7 @@ class HeaderLogo extends Component {
if (current_user.get('id')) {
return (
<div
onClick={this.toggleSidebar}
onClick={this.toggleSidebar}
className="header__logo action"
>
{logoBody}
Expand Down
2 changes: 1 addition & 1 deletion src/components/sidebar.js
Expand Up @@ -70,7 +70,7 @@ class Sidebar extends React.Component {
dispatch(toggleUISidebar(false));
}

if (!ui.get('sidebarIsVisible') && (clientWidth >= breakpointWidth) && (clientWidth > this.state.clientWidth)) {
if (!ui.get('sidebarIsVisible') && !ui.get('sidebarSwitchedOff') && (clientWidth >= breakpointWidth) && (clientWidth > this.state.clientWidth)) {
dispatch(toggleUISidebar(true));
}

Expand Down
13 changes: 13 additions & 0 deletions src/store/ui.js
Expand Up @@ -21,6 +21,7 @@ import * as a from '../actions';

const initialState = i.Map({
sidebarIsVisible: true,
sidebarSwitchedOff: false,
progress: i.Map({}),
comments: i.Map({})
});
Expand All @@ -38,6 +39,18 @@ function reducer (state=initialState, action) {

state = state.set('sidebarIsVisible', isVisible);

break;
}
case a.UI__SWITCH_OFF_SIDEBAR:
{
state = state.set('sidebarSwitchedOff', true);

break;
}
case a.UI__SWITCH_ON_SIDEBAR:
{
state = state.set('sidebarSwitchedOff', false);

break;
}
case a.UI__SET_PROGRESS:
Expand Down

0 comments on commit f371e5b

Please sign in to comment.