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

Commit

Permalink
save night mode in option cookie #676 (#692)
Browse files Browse the repository at this point in the history
* save night mode in option cookie #676

* moved add night-mode class to componentDidMount

* fixed color of bismaalah for night mode
  • Loading branch information
naveed-ahmad authored and mmahalwy committed Mar 18, 2017
1 parent c471984 commit 2bff754
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 11 deletions.
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
31 changes: 24 additions & 7 deletions src/components/NightModeToggle/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
/* 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
}

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

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

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;

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
2 changes: 1 addition & 1 deletion src/styles/nightmode.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
fill: #fff;
}

.bismillah, .text-arabic b{
#bismillah, .text-arabic b{
color: #fff;
}

Expand Down

0 comments on commit 2bff754

Please sign in to comment.