Skip to content
This repository was 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 all commits
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
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