From 98d27493ac1f0d555c5eb24c34f1382c0a0ad9c2 Mon Sep 17 00:00:00 2001 From: Tsang Wai Lam Date: Tue, 6 Dec 2016 09:56:54 +0800 Subject: [PATCH] #23 Add sidebar docking --- package.json | 1 + src/App/App.css | 4 ++-- src/App/App.js | 49 ++++++++++++++++++++++++++++++++-------- src/Settings/Settings.js | 6 +++++ src/actions.js | 5 ++++ src/reducers.js | 7 ++++++ 6 files changed, 61 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 00d815f..2cca2a8 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "react-helmet": "^3.2.2", "react-redux": "^4.4.6", "react-router": "^3.0.0", + "react-sidebar": "^2.2.1", "redux": "^3.6.0", "semantic-ui-react": "^0.61.4", "string.prototype.repeat": "^0.2.0", diff --git a/src/App/App.css b/src/App/App.css index d63233c..4afa04c 100644 --- a/src/App/App.css +++ b/src/App/App.css @@ -93,10 +93,10 @@ header > a { background: #333; height: 100%; left: 0; - max-width: 320px; + max-width: 150px; -webkit-overflow-scrolling: touch; overflow-x: hidden; - padding: 1em 0; + padding: 3em 0 1em 0; position: fixed; top: 0; width: 40%; diff --git a/src/App/App.js b/src/App/App.js index 3243ba2..40e8079 100644 --- a/src/App/App.js +++ b/src/App/App.js @@ -5,6 +5,7 @@ import { bindActionCreators } from 'redux' import * as types from '../actions' import Helmet from 'react-helmet' import moment from 'moment' +import Sidebar from 'react-sidebar' import { Icon, Modal, Image } from 'semantic-ui-react' import { VelocityComponent } from 'velocity-react' @@ -34,6 +35,7 @@ class App extends Component { state = { drawerOpen: false, modalOpen: false, + sidebarDocked: false } async componentDidMount() { @@ -62,6 +64,10 @@ class App extends Component { if (isStory && !this.props.app.storyMode) { this.props.actions.onToggleStoryMode() } + const isDockMenu = JSON.parse(localStorage.getItem('dm')) + if (isDockMenu && !this.props.app.dockMenu) { + this.props.actions.onToggleDockMenu() + } let list try { @@ -90,6 +96,29 @@ class App extends Component { window.requestAnimationFrame(step) } + + async componentWillMount() { + let mql = window.matchMedia(`(min-width: 800px)`); + mql.addListener(this.mediaQueryChanged); + this.setState({mql: mql, drawerOpen: mql.matches}); + + } + + async componentWillUnmount() { + this.state.mql.removeListener(this.mediaQueryChanged); + } + + async mediaQueryChanged() { + console.log("change open"); + + // this.setState({drawerOpen: !this.state.drawerOpen}); + this.setState({ drawerOpen: !this.state.drawerOpen }, () => { + document.body.style.overflow = this.state.drawerOpen ? 'hidden' : 'visible' + }) + + this.state.mql.removeListener(this.mediaQueryChanged); + } + render() { let { user } = this.props.app.user const linkRef = e => this.settings = e @@ -109,7 +138,7 @@ class App extends Component { this.setState({ modalOpen: !this.state.modalOpen }) } const drawer = ( -
+
{ this.props.app.categories.map(c => { const click = e => { setTimeout(browserHistory.push.bind(null, `/category/${ c.cat_id }`), 250) @@ -169,18 +198,20 @@ class App extends Component { -
- - - - - { drawer } - -
+ {/*
*/} + {/**/} + {/**/} + {/**/} + {/**/} + {/*{ drawer }*/} + {/**/} + {/*
*/} +
{ children }
+
) } diff --git a/src/Settings/Settings.js b/src/Settings/Settings.js index 2c67b63..09bbbab 100644 --- a/src/Settings/Settings.js +++ b/src/Settings/Settings.js @@ -44,6 +44,12 @@ class Settings extends Component { { this.props.app.storyMode ? 'ON' : 'OFF' }
+
+ 癡住條命 + +
洗底 ({ type: TOGGLE_STORY_MODE, }) +export const TOGGLE_DOCK_MENU = 'TOGGLE_DOCK_MENU' +export const onToggleDockMenu = () => ({ + type: TOGGLE_DOCK_MENU, +}) + export const SET_CATEGORIES = 'SET_CATEGORIES' export const onSetCategories = categories => ({ type: SET_CATEGORIES, diff --git a/src/reducers.js b/src/reducers.js index 991c559..ac1c370 100644 --- a/src/reducers.js +++ b/src/reducers.js @@ -6,6 +6,7 @@ const initialStates = { darkMode: true, officeMode: false, storyMode: false, + dockMenu: false, categories: [], visitedThreads: JSON.parse(localStorage.getItem('vts')) || [], } @@ -41,6 +42,12 @@ const app = (state = initialStates, action = {}) => { ...state, storyMode: !state.storyMode, } + case types.TOGGLE_DOCK_MENU: + localStorage.setItem('dm', !state.dockMenu) + return { + ...state, + dockMenu: !state.dockMenu, + } case types.SET_CATEGORIES: return { ...state,