isNight() to arrow function and update isNight every 10 minutes, default to false

This commit is contained in:
Arrowana 2018-01-20 08:37:22 +11:00
parent 6f77106ffa
commit a5dce3e77a
2 changed files with 10 additions and 10 deletions

View file

@ -6,7 +6,7 @@ import Http from 'http';
import Lbry from 'lbry'; import Lbry from 'lbry';
import moment from 'moment'; import moment from 'moment';
const UPDATE_IS_NIGHT_INTERVAL = 60 * 1000; const UPDATE_IS_NIGHT_INTERVAL = 10 * 60 * 1000;
export function doFetchDaemonSettings() { export function doFetchDaemonSettings() {
return dispatch => { return dispatch => {
@ -56,6 +56,7 @@ export function doGetThemes() {
export function doUpdateIsNightAsync() { export function doUpdateIsNightAsync() {
return dispatch => { return dispatch => {
dispatch(doUpdateIsNight());
const updateIsNightInterval = setInterval( const updateIsNightInterval = setInterval(
() => dispatch(doUpdateIsNight()), () => dispatch(doUpdateIsNight()),
UPDATE_IS_NIGHT_INTERVAL UPDATE_IS_NIGHT_INTERVAL
@ -63,17 +64,16 @@ export function doUpdateIsNightAsync() {
}; };
} }
function isNight() {
const startNightMoment = moment('19:00', 'HH:mm');
const endNightTime = moment('8:00', 'HH:mm');
const momentNow = moment();
return !(momentNow.isAfter(endNightTime) && momentNow.isBefore(startNightMoment));
}
export function doUpdateIsNight() { export function doUpdateIsNight() {
const momentNow = moment();
return { return {
type: ACTIONS.UPDATE_IS_NIGHT, type: ACTIONS.UPDATE_IS_NIGHT,
data: { isNight: isNight() }, data: { isNight: () => {
const startNightMoment = moment('19:00', 'HH:mm');
const endNightMoment = moment('8:00', 'HH:mm');
return !(momentNow.isAfter(endNightMoment) && momentNow.isBefore(startNightMoment));
}
},
}; };
} }

View file

@ -25,7 +25,7 @@ const defaultState = {
themes: getLocalStorageSetting(SETTINGS.THEMES, []), themes: getLocalStorageSetting(SETTINGS.THEMES, []),
automaticDarkModeEnabled: getLocalStorageSetting(SETTINGS.AUTOMATIC_DARK_MODE_ENABLED, false), automaticDarkModeEnabled: getLocalStorageSetting(SETTINGS.AUTOMATIC_DARK_MODE_ENABLED, false),
}, },
isNight: true, isNight: false,
languages: {}, languages: {},
}; };