Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

save night mode in option cookie #676 #692

Merged
merged 5 commits into from
Mar 18, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/components/GlobalNav/Surah/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ const GlobalNavSurah = ({ chapter, chapters, setOption, options, ...props }) =>
isToggled={options.isReadingMode}
onToggle={setOption}
/>
<NightModeToggle />
<NightModeToggle
isNightMode={options.isNightMode}
onToggle={setOption}
/>
</NavDropdown>,
<div className="navbar-form navbar-left hidden-xs hidden-sm">
<SearchInput className="search-input" />
Expand All @@ -64,7 +67,10 @@ const GlobalNavSurah = ({ chapter, chapters, setOption, options, ...props }) =>
isToggled={options.isReadingMode}
onToggle={setOption}
/>,
<NightModeToggle />
<NightModeToggle
isNightMode={options.isNightMode}
onToggle={setOption}
/>
]}
/>
);
Expand Down
27 changes: 20 additions & 7 deletions src/components/NightModeToggle/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
/* global document */
import React, { Component } from 'react';
import React, { Component, PropTypes } from 'react';
import LocaleFormattedMessage from 'components/LocaleFormattedMessage';

class NightModeToggle extends Component {
state = {
isNightMode: false,
};
static propTypes = {
isNightMode: PropTypes.bool.isRequired,
onToggle: PropTypes.func.isRequired
}

toggleNightMode = () => {
document.body.classList.toggle('night-mode');
const { isNightMode, onToggle } = this.props;

if (isNightMode) {
document.body.classList.remove('night-mode');
} else {
document.body.classList.add('night-mode');
}

this.setState({ isNightMode: !this.state.isNightMode });
onToggle({ isNightMode: !isNightMode });
}

render() {
const { isNightMode } = this.props;

if (__CLIENT__ && isNightMode) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want to just add document.body.classList.add('night-mode'); inside of componentDidMount(){} if isNightMode. Putting it in the render will cause document.body.classList.add('night-mode'); to continue to be called on every render

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

document.body.classList.add('night-mode');
}

return (
<li className={this.state.isNightMode && 'active'}>
<li className={isNightMode && 'active'}>
<a
tabIndex="-1"
className="pointer"
Expand Down
1 change: 0 additions & 1 deletion src/components/SurahInfo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React, { PropTypes } from 'react';
import { surahType } from 'types';
import Loader from 'quran-components/lib/Loader';


const style = require('./style.scss');

const SurahInfo = ({ chapter, isShowingSurahInfo, onClose }) => {
Expand Down
4 changes: 4 additions & 0 deletions src/redux/actions/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export function isReadingMode(globalState) {
return globalState.options.isReadingMode;
}

export function isNightMode(globalState) {
return globalState.options.isNightMode;
}

export function setOption(payload) {
const options = cookie.load('options') || {}; // protect against first timers.

Expand Down
1 change: 1 addition & 0 deletions src/redux/modules/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {

const initialState = {
isReadingMode: false,
isNightMode: false,
isShowingSurahInfo: false,
loadingRecitations: false,
loadingTranslations: false,
Expand Down