finish issue-1922
This commit is contained in:
parent
1d0ac2fec8
commit
a52d7df06f
6 changed files with 142 additions and 37 deletions
|
@ -1,7 +1,13 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import * as settings from 'constants/settings';
|
import * as settings from 'constants/settings';
|
||||||
import { doClearCache, doNotifyEncryptWallet, doNotifyDecryptWallet } from 'redux/actions/app';
|
import { doClearCache, doNotifyEncryptWallet, doNotifyDecryptWallet } from 'redux/actions/app';
|
||||||
import { doSetDaemonSetting, doSetClientSetting, doGetThemes, doChangeLanguage } from 'redux/actions/settings';
|
import {
|
||||||
|
doSetDaemonSetting,
|
||||||
|
doSetClientSetting,
|
||||||
|
doGetThemes,
|
||||||
|
doChangeLanguage,
|
||||||
|
doSetDarkTime,
|
||||||
|
} from 'redux/actions/settings';
|
||||||
import { doSetPlayingUri } from 'redux/actions/content';
|
import { doSetPlayingUri } from 'redux/actions/content';
|
||||||
import {
|
import {
|
||||||
makeSelectClientSetting,
|
makeSelectClientSetting,
|
||||||
|
@ -30,6 +36,7 @@ const select = state => ({
|
||||||
userBlockedChannelsCount: selectBlockedChannelsCount(state),
|
userBlockedChannelsCount: selectBlockedChannelsCount(state),
|
||||||
hideBalance: makeSelectClientSetting(settings.HIDE_BALANCE)(state),
|
hideBalance: makeSelectClientSetting(settings.HIDE_BALANCE)(state),
|
||||||
floatingPlayer: makeSelectClientSetting(settings.FLOATING_PLAYER)(state),
|
floatingPlayer: makeSelectClientSetting(settings.FLOATING_PLAYER)(state),
|
||||||
|
darkModeTimes: makeSelectClientSetting(settings.DARK_MODE_TIMES)(state),
|
||||||
});
|
});
|
||||||
|
|
||||||
const perform = dispatch => ({
|
const perform = dispatch => ({
|
||||||
|
@ -42,6 +49,7 @@ const perform = dispatch => ({
|
||||||
decryptWallet: () => dispatch(doNotifyDecryptWallet()),
|
decryptWallet: () => dispatch(doNotifyDecryptWallet()),
|
||||||
updateWalletStatus: () => dispatch(doWalletStatus()),
|
updateWalletStatus: () => dispatch(doWalletStatus()),
|
||||||
clearPlayingUri: () => dispatch(doSetPlayingUri(null)),
|
clearPlayingUri: () => dispatch(doSetPlayingUri(null)),
|
||||||
|
setDarkTime: (time, options) => dispatch(doSetDarkTime(time, options)),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(
|
export default connect(
|
||||||
|
|
|
@ -52,6 +52,11 @@ type Props = {
|
||||||
hideBalance: boolean,
|
hideBalance: boolean,
|
||||||
floatingPlayer: boolean,
|
floatingPlayer: boolean,
|
||||||
clearPlayingUri: () => void,
|
clearPlayingUri: () => void,
|
||||||
|
darkModeTimes: {
|
||||||
|
from: { hour: string, min: string, formattedTime: string },
|
||||||
|
to: { hour: string, min: string, formattedTime: string },
|
||||||
|
},
|
||||||
|
setDarkTime: (string, {}) => void,
|
||||||
};
|
};
|
||||||
|
|
||||||
type State = {
|
type State = {
|
||||||
|
@ -74,6 +79,7 @@ class SettingsPage extends React.PureComponent<Props, State> {
|
||||||
(this: any).onAutomaticDarkModeChange = this.onAutomaticDarkModeChange.bind(this);
|
(this: any).onAutomaticDarkModeChange = this.onAutomaticDarkModeChange.bind(this);
|
||||||
(this: any).onLanguageChange = this.onLanguageChange.bind(this);
|
(this: any).onLanguageChange = this.onLanguageChange.bind(this);
|
||||||
(this: any).clearCache = this.clearCache.bind(this);
|
(this: any).clearCache = this.clearCache.bind(this);
|
||||||
|
(this: any).onChangeTime = this.onChangeTime.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
@ -130,6 +136,20 @@ class SettingsPage extends React.PureComponent<Props, State> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onChangeTime(event: SyntheticInputEvent<*>, options: Object) {
|
||||||
|
const { value } = event.target;
|
||||||
|
|
||||||
|
this.props.setDarkTime(value, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
to12Hour(time: string) {
|
||||||
|
const now = new Date(0, 0, 0, Number(time));
|
||||||
|
|
||||||
|
const hour = now.toLocaleTimeString('en-US', { hour12: true, hour: '2-digit' });
|
||||||
|
|
||||||
|
return hour;
|
||||||
|
}
|
||||||
|
|
||||||
setDaemonSetting(name: string, value: ?SetDaemonSettingArg): void {
|
setDaemonSetting(name: string, value: ?SetDaemonSettingArg): void {
|
||||||
this.props.setDaemonSetting(name, value);
|
this.props.setDaemonSetting(name, value);
|
||||||
}
|
}
|
||||||
|
@ -169,6 +189,7 @@ class SettingsPage extends React.PureComponent<Props, State> {
|
||||||
userBlockedChannelsCount,
|
userBlockedChannelsCount,
|
||||||
floatingPlayer,
|
floatingPlayer,
|
||||||
clearPlayingUri,
|
clearPlayingUri,
|
||||||
|
darkModeTimes,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
const noDaemonSettings = !daemonSettings || Object.keys(daemonSettings).length === 0;
|
const noDaemonSettings = !daemonSettings || Object.keys(daemonSettings).length === 0;
|
||||||
|
@ -177,6 +198,9 @@ class SettingsPage extends React.PureComponent<Props, State> {
|
||||||
|
|
||||||
const disableMaxKeyFee = !(daemonSettings && daemonSettings.max_key_fee);
|
const disableMaxKeyFee = !(daemonSettings && daemonSettings.max_key_fee);
|
||||||
const connectionOptions = [1, 2, 4, 6, 10, 20];
|
const connectionOptions = [1, 2, 4, 6, 10, 20];
|
||||||
|
const startHours = ['18', '19', '20', '21'];
|
||||||
|
const endHours = ['5', '6', '7', '8'];
|
||||||
|
const enabledMinutes = ['00', '15', '30', '45'];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Page>
|
<Page>
|
||||||
|
@ -420,36 +444,76 @@ class SettingsPage extends React.PureComponent<Props, State> {
|
||||||
name="automatic_dark_mode"
|
name="automatic_dark_mode"
|
||||||
onChange={() => this.onAutomaticDarkModeChange(!automaticDarkModeEnabled)}
|
onChange={() => this.onAutomaticDarkModeChange(!automaticDarkModeEnabled)}
|
||||||
checked={automaticDarkModeEnabled}
|
checked={automaticDarkModeEnabled}
|
||||||
label={__('Automatic dark mode (9pm to 8am)')}
|
label={__('Automatic dark mode')}
|
||||||
/>
|
/>
|
||||||
<FormField
|
|
||||||
type="select"
|
<h3>{__('From: ')}</h3>
|
||||||
name="automatic_dark_mode_range"
|
<div className="time-section">
|
||||||
// onChange={() => this.onAutomaticDarkModeChange(!automaticDarkModeEnabled)}
|
<FormField
|
||||||
// checked={automaticDarkModeEnabled}
|
className="select-hours"
|
||||||
disabled={!automaticDarkModeEnabled}
|
type="select"
|
||||||
label={__('from:')}
|
name="automatic_dark_mode_range"
|
||||||
>
|
disabled={!automaticDarkModeEnabled}
|
||||||
{['18:00', '19:00', '20:00', '21:00'].map(time => (
|
onChange={value => this.onChangeTime(value, { fromTo: 'from', time: 'hour' })}
|
||||||
<option key={time} value={time}>
|
value={darkModeTimes.from.hour}
|
||||||
{time}
|
label={__('Hours:')}
|
||||||
</option>
|
>
|
||||||
))}
|
{startHours.map(time => (
|
||||||
</FormField>
|
<option key={time} value={time}>
|
||||||
<FormField
|
{this.to12Hour(time)}
|
||||||
type="select"
|
</option>
|
||||||
name="automatic_dark_mode_range"
|
))}
|
||||||
// onChange={() => this.onAutomaticDarkModeChange(!automaticDarkModeEnabled)}
|
</FormField>
|
||||||
// checked={automaticDarkModeEnabled}
|
<FormField
|
||||||
disabled={!automaticDarkModeEnabled}
|
className="select-hours"
|
||||||
label={__('To:')}
|
label={__('minutes')}
|
||||||
>
|
type="select"
|
||||||
{['5:00', '6:00', '7:00', '8:00'].map(time => (
|
name="automatic_dark_mode_range"
|
||||||
<option key={time} value={time}>
|
disabled={!automaticDarkModeEnabled}
|
||||||
{time}
|
onChange={value => this.onChangeTime(value, { fromTo: 'from', time: 'min' })}
|
||||||
</option>
|
value={darkModeTimes.from.min}
|
||||||
))}
|
>
|
||||||
</FormField>
|
{enabledMinutes.map(time => (
|
||||||
|
<option key={time} value={time}>
|
||||||
|
{time}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</FormField>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>{__('To: ')}</h3>
|
||||||
|
<div className="time-section">
|
||||||
|
<FormField
|
||||||
|
className="select-hours"
|
||||||
|
type="select"
|
||||||
|
name="automatic_dark_mode_range"
|
||||||
|
disabled={!automaticDarkModeEnabled}
|
||||||
|
label={__('Hours:')}
|
||||||
|
onChange={value => this.onChangeTime(value, { fromTo: 'to', time: 'hour' })}
|
||||||
|
value={darkModeTimes.to.hour}
|
||||||
|
>
|
||||||
|
{endHours.map(time => (
|
||||||
|
<option key={time} value={time}>
|
||||||
|
{this.to12Hour(time)}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</FormField>
|
||||||
|
<FormField
|
||||||
|
className="select-hours"
|
||||||
|
label={__('minutes')}
|
||||||
|
type="select"
|
||||||
|
name="automatic_dark_mode_range"
|
||||||
|
disabled={!automaticDarkModeEnabled}
|
||||||
|
onChange={value => this.onChangeTime(value, { fromTo: 'to', time: 'min' })}
|
||||||
|
value={darkModeTimes.to.min}
|
||||||
|
>
|
||||||
|
{enabledMinutes.map(time => (
|
||||||
|
<option key={time} value={time}>
|
||||||
|
{time}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</FormField>
|
||||||
|
</div>
|
||||||
</fieldset-section>
|
</fieldset-section>
|
||||||
</Form>
|
</Form>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { Lbry, ACTIONS, SETTINGS } from 'lbry-redux';
|
||||||
import { makeSelectClientSetting } from 'redux/selectors/settings';
|
import { makeSelectClientSetting } from 'redux/selectors/settings';
|
||||||
import analytics from 'analytics';
|
import analytics from 'analytics';
|
||||||
|
|
||||||
const UPDATE_IS_NIGHT_INTERVAL = 10 * 60 * 1000;
|
const UPDATE_IS_NIGHT_INTERVAL = 5 * 60 * 1000;
|
||||||
|
|
||||||
export function doFetchDaemonSettings() {
|
export function doFetchDaemonSettings() {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
|
@ -138,3 +138,25 @@ export function doChangeLanguage(language) {
|
||||||
i18n.setLocale(language);
|
i18n.setLocale(language);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function doSetDarkTime(value, options) {
|
||||||
|
const { fromTo, time } = options;
|
||||||
|
return (dispatch, getState) => {
|
||||||
|
const state = getState();
|
||||||
|
const { darkModeTimes } = state.settings.clientSettings;
|
||||||
|
const { hour, min } = darkModeTimes[fromTo];
|
||||||
|
const newHour = time === 'hour' ? value : hour;
|
||||||
|
const newMin = time === 'min' ? value : min;
|
||||||
|
const modifiedTimes = {
|
||||||
|
[fromTo]: {
|
||||||
|
hour: newHour,
|
||||||
|
min: newMin,
|
||||||
|
formattedTime: newHour + ':' + newMin,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const mergedTimes = { ...darkModeTimes, ...modifiedTimes };
|
||||||
|
|
||||||
|
dispatch(doSetClientSetting(SETTINGS.DARK_MODE_TIMES, mergedTimes));
|
||||||
|
dispatch(doUpdateIsNight());
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -33,7 +33,10 @@ const defaultState = {
|
||||||
[SETTINGS.HIDE_BALANCE]: Boolean(getLocalStorageSetting(SETTINGS.HIDE_BALANCE, false)),
|
[SETTINGS.HIDE_BALANCE]: Boolean(getLocalStorageSetting(SETTINGS.HIDE_BALANCE, false)),
|
||||||
[SETTINGS.HIDE_SPLASH_ANIMATION]: Boolean(getLocalStorageSetting(SETTINGS.HIDE_SPLASH_ANIMATION, false)),
|
[SETTINGS.HIDE_SPLASH_ANIMATION]: Boolean(getLocalStorageSetting(SETTINGS.HIDE_SPLASH_ANIMATION, false)),
|
||||||
[SETTINGS.FLOATING_PLAYER]: Boolean(getLocalStorageSetting(SETTINGS.FLOATING_PLAYER, true)),
|
[SETTINGS.FLOATING_PLAYER]: Boolean(getLocalStorageSetting(SETTINGS.FLOATING_PLAYER, true)),
|
||||||
[SETTINGS.DARK_MODE_TIMES]: getLocalStorageSetting(SETTINGS.DARK_MODE_TIMES, { from: '21:00', to: '8:00' }),
|
[SETTINGS.DARK_MODE_TIMES]: getLocalStorageSetting(SETTINGS.DARK_MODE_TIMES, {
|
||||||
|
from: { hour: '21', min: '00', formattedTime: '21:00' },
|
||||||
|
to: { hour: '8', min: '00', formattedTime: '8:00' },
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
isNight: false,
|
isNight: false,
|
||||||
languages: { en: 'English', pl: 'Polish', id: 'Bahasa Indonesia' }, // temporarily hard code these so we can advance i18n testing
|
languages: { en: 'English', pl: 'Polish', id: 'Bahasa Indonesia' }, // temporarily hard code these so we can advance i18n testing
|
||||||
|
@ -62,12 +65,10 @@ reducers[ACTIONS.CLIENT_SETTING_CHANGED] = (state, action) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
reducers[ACTIONS.UPDATE_IS_NIGHT] = state => {
|
reducers[ACTIONS.UPDATE_IS_NIGHT] = state => {
|
||||||
|
const { from, to } = state.clientSettings.darkModeTimes;
|
||||||
const momentNow = moment();
|
const momentNow = moment();
|
||||||
const { from, to } = state.settings.clientSettings.darkModeTimes;
|
const startNightMoment = moment(from.formattedTime, 'HH:mm');
|
||||||
|
const endNightMoment = moment(to.formattedTime, 'HH:mm');
|
||||||
const startNightMoment = moment(from, 'HH:mm');
|
|
||||||
const endNightMoment = moment(to, 'HH:mm');
|
|
||||||
|
|
||||||
const isNight = !(momentNow.isAfter(endNightMoment) && momentNow.isBefore(startNightMoment));
|
const isNight = !(momentNow.isAfter(endNightMoment) && momentNow.isBefore(startNightMoment));
|
||||||
|
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
@import 'component/pagination';
|
@import 'component/pagination';
|
||||||
@import 'component/placeholder';
|
@import 'component/placeholder';
|
||||||
@import 'component/search';
|
@import 'component/search';
|
||||||
|
@import 'component/settings';
|
||||||
@import 'component/snack-bar';
|
@import 'component/snack-bar';
|
||||||
@import 'component/spinner';
|
@import 'component/spinner';
|
||||||
@import 'component/splash';
|
@import 'component/splash';
|
||||||
|
|
9
src/ui/scss/component/_settings.scss
Normal file
9
src/ui/scss/component/_settings.scss
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
.select-hours {
|
||||||
|
display: block;
|
||||||
|
float: left;
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.time-section {
|
||||||
|
display: flex;
|
||||||
|
}
|
Loading…
Reference in a new issue