Merge pull request #301 from lbryio/nsfw
Move client settings into redux
This commit is contained in:
commit
c011783003
11 changed files with 51 additions and 24 deletions
|
@ -29,3 +29,15 @@ export function doSetDaemonSetting(key, value) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function doSetClientSetting(key, value) {
|
||||||
|
lbry.setClientSetting(key, value);
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: types.CLIENT_SETTING_CHANGED,
|
||||||
|
data: {
|
||||||
|
key,
|
||||||
|
value,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import React from "react";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { doNavigate } from "actions/app";
|
import { doNavigate } from "actions/app";
|
||||||
import { doResolveUri } from "actions/content";
|
import { doResolveUri } from "actions/content";
|
||||||
import { selectObscureNsfw } from "selectors/app";
|
import { selectShowNsfw } from "selectors/settings";
|
||||||
import {
|
import {
|
||||||
makeSelectClaimForUri,
|
makeSelectClaimForUri,
|
||||||
makeSelectMetadataForUri,
|
makeSelectMetadataForUri,
|
||||||
|
@ -20,7 +20,7 @@ const makeSelect = () => {
|
||||||
const select = (state, props) => ({
|
const select = (state, props) => ({
|
||||||
claim: selectClaimForUri(state, props),
|
claim: selectClaimForUri(state, props),
|
||||||
fileInfo: selectFileInfoForUri(state, props),
|
fileInfo: selectFileInfoForUri(state, props),
|
||||||
obscureNsfw: selectObscureNsfw(state),
|
obscureNsfw: !selectShowNsfw(state),
|
||||||
metadata: selectMetadataForUri(state, props),
|
metadata: selectMetadataForUri(state, props),
|
||||||
isResolvingUri: selectResolvingUri(state, props),
|
isResolvingUri: selectResolvingUri(state, props),
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,7 +7,7 @@ import {
|
||||||
makeSelectMetadataForUri,
|
makeSelectMetadataForUri,
|
||||||
} from "selectors/claims";
|
} from "selectors/claims";
|
||||||
import { makeSelectFileInfoForUri } from "selectors/file_info";
|
import { makeSelectFileInfoForUri } from "selectors/file_info";
|
||||||
import { selectObscureNsfw } from "selectors/app";
|
import { selectShowNsfw } from "selectors/settings";
|
||||||
import { makeSelectIsResolvingForUri } from "selectors/content";
|
import { makeSelectIsResolvingForUri } from "selectors/content";
|
||||||
import FileTile from "./view";
|
import FileTile from "./view";
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ const makeSelect = () => {
|
||||||
const select = (state, props) => ({
|
const select = (state, props) => ({
|
||||||
claim: selectClaimForUri(state, props),
|
claim: selectClaimForUri(state, props),
|
||||||
fileInfo: selectFileInfoForUri(state, props),
|
fileInfo: selectFileInfoForUri(state, props),
|
||||||
obscureNsfw: selectObscureNsfw(state),
|
obscureNsfw: !selectShowNsfw(state),
|
||||||
metadata: selectMetadataForUri(state, props),
|
metadata: selectMetadataForUri(state, props),
|
||||||
isResolvingUri: selectResolvingUri(state, props),
|
isResolvingUri: selectResolvingUri(state, props),
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,7 +14,7 @@ import {
|
||||||
makeSelectDownloadingForUri,
|
makeSelectDownloadingForUri,
|
||||||
} from "selectors/file_info";
|
} from "selectors/file_info";
|
||||||
import { makeSelectCostInfoForUri } from "selectors/cost_info";
|
import { makeSelectCostInfoForUri } from "selectors/cost_info";
|
||||||
import { selectObscureNsfw } from "selectors/app";
|
import { selectShowNsfw } from "selectors/settings";
|
||||||
import Video from "./view";
|
import Video from "./view";
|
||||||
|
|
||||||
const makeSelect = () => {
|
const makeSelect = () => {
|
||||||
|
@ -29,7 +29,7 @@ const makeSelect = () => {
|
||||||
costInfo: selectCostInfo(state, props),
|
costInfo: selectCostInfo(state, props),
|
||||||
fileInfo: selectFileInfo(state, props),
|
fileInfo: selectFileInfo(state, props),
|
||||||
metadata: selectMetadata(state, props),
|
metadata: selectMetadata(state, props),
|
||||||
obscureNsfw: selectObscureNsfw(state),
|
obscureNsfw: !selectShowNsfw(state),
|
||||||
modal: selectCurrentModal(state),
|
modal: selectCurrentModal(state),
|
||||||
isLoading: selectIsLoading(state, props),
|
isLoading: selectIsLoading(state, props),
|
||||||
isDownloading: selectIsDownloading(state, props),
|
isDownloading: selectIsDownloading(state, props),
|
||||||
|
|
|
@ -69,6 +69,7 @@ export const SEARCH_CANCELLED = "SEARCH_CANCELLED";
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
export const DAEMON_SETTINGS_RECEIVED = "DAEMON_SETTINGS_RECEIVED";
|
export const DAEMON_SETTINGS_RECEIVED = "DAEMON_SETTINGS_RECEIVED";
|
||||||
|
export const CLIENT_SETTING_CHANGED = "CLIENT_SETTING_CHANGED";
|
||||||
|
|
||||||
// User
|
// User
|
||||||
export const AUTHENTICATION_STARTED = "AUTHENTICATION_STARTED";
|
export const AUTHENTICATION_STARTED = "AUTHENTICATION_STARTED";
|
||||||
|
|
|
@ -10,7 +10,7 @@ import {
|
||||||
makeSelectMetadataForUri,
|
makeSelectMetadataForUri,
|
||||||
} from "selectors/claims";
|
} from "selectors/claims";
|
||||||
import { makeSelectCostInfoForUri } from "selectors/cost_info";
|
import { makeSelectCostInfoForUri } from "selectors/cost_info";
|
||||||
import { selectObscureNsfw } from "selectors/app";
|
import { selectShowNsfw } from "selectors/settings";
|
||||||
import FilePage from "./view";
|
import FilePage from "./view";
|
||||||
|
|
||||||
const makeSelect = () => {
|
const makeSelect = () => {
|
||||||
|
@ -25,7 +25,7 @@ const makeSelect = () => {
|
||||||
contentType: selectContentType(state, props),
|
contentType: selectContentType(state, props),
|
||||||
costInfo: selectCostInfo(state, props),
|
costInfo: selectCostInfo(state, props),
|
||||||
metadata: selectMetadata(state, props),
|
metadata: selectMetadata(state, props),
|
||||||
obscureNsfw: selectObscureNsfw(state),
|
showNsfw: !selectShowNsfw(state),
|
||||||
fileInfo: selectFileInfo(state, props),
|
fileInfo: selectFileInfo(state, props),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { doClearCache } from "actions/app";
|
import { doClearCache } from "actions/app";
|
||||||
import { doSetDaemonSetting } from "actions/settings";
|
import { doSetDaemonSetting, doSetClientSetting } from "actions/settings";
|
||||||
import { selectDaemonSettings } from "selectors/settings";
|
import { selectDaemonSettings, selectShowNsfw } from "selectors/settings";
|
||||||
import SettingsPage from "./view";
|
import SettingsPage from "./view";
|
||||||
|
|
||||||
const select = state => ({
|
const select = state => ({
|
||||||
daemonSettings: selectDaemonSettings(state),
|
daemonSettings: selectDaemonSettings(state),
|
||||||
|
showNsfw: selectShowNsfw(state),
|
||||||
});
|
});
|
||||||
|
|
||||||
const perform = dispatch => ({
|
const perform = dispatch => ({
|
||||||
setDaemonSetting: (key, value) => dispatch(doSetDaemonSetting(key, value)),
|
setDaemonSetting: (key, value) => dispatch(doSetDaemonSetting(key, value)),
|
||||||
clearCache: () => dispatch(doClearCache()),
|
clearCache: () => dispatch(doClearCache()),
|
||||||
|
setClientSetting: (key, value) => dispatch(doSetClientSetting(key, value)),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(select, perform)(SettingsPage);
|
export default connect(select, perform)(SettingsPage);
|
||||||
|
|
|
@ -10,12 +10,11 @@ class SettingsPage extends React.PureComponent {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
const daemonSettings = this.props.daemonSettings;
|
const { daemonSettings } = this.props;
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
isMaxUpload: daemonSettings && daemonSettings.max_upload != 0,
|
isMaxUpload: daemonSettings && daemonSettings.max_upload != 0,
|
||||||
isMaxDownload: daemonSettings && daemonSettings.max_download != 0,
|
isMaxDownload: daemonSettings && daemonSettings.max_download != 0,
|
||||||
showNsfw: lbry.getClientSetting("showNsfw"),
|
|
||||||
showUnavailable: lbry.getClientSetting("showUnavailable"),
|
showUnavailable: lbry.getClientSetting("showUnavailable"),
|
||||||
language: lbry.getClientSetting("language"),
|
language: lbry.getClientSetting("language"),
|
||||||
clearingCache: false,
|
clearingCache: false,
|
||||||
|
@ -83,7 +82,7 @@ class SettingsPage extends React.PureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
onShowNsfwChange(event) {
|
onShowNsfwChange(event) {
|
||||||
lbry.setClientSetting("showNsfw", event.target.checked);
|
this.props.setClientSetting("showNsfw", event.target.checked);
|
||||||
}
|
}
|
||||||
|
|
||||||
// onLanguageChange(language) {
|
// onLanguageChange(language) {
|
||||||
|
@ -238,7 +237,7 @@ class SettingsPage extends React.PureComponent {
|
||||||
label={__("Show NSFW content")}
|
label={__("Show NSFW content")}
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
onChange={this.onShowNsfwChange.bind(this)}
|
onChange={this.onShowNsfwChange.bind(this)}
|
||||||
defaultChecked={this.state.showNsfw}
|
defaultChecked={this.props.showNsfw}
|
||||||
helper={__(
|
helper={__(
|
||||||
"NSFW content may include nudity, intense sexuality, profanity, or other adult content. By displaying NSFW content, you are affirming you are of legal age to view mature content in your country or jurisdiction. "
|
"NSFW content may include nudity, intense sexuality, profanity, or other adult content. By displaying NSFW content, you are affirming you are of legal age to view mature content in your country or jurisdiction. "
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
import * as types from "constants/action_types";
|
import * as types from "constants/action_types";
|
||||||
|
import lbry from "lbry";
|
||||||
|
|
||||||
const reducers = {};
|
const reducers = {};
|
||||||
const defaultState = {};
|
const defaultState = {
|
||||||
|
clientSettings: {
|
||||||
|
showNsfw: lbry.getClientSetting("showNsfw"),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
reducers[types.DAEMON_SETTINGS_RECEIVED] = function(state, action) {
|
reducers[types.DAEMON_SETTINGS_RECEIVED] = function(state, action) {
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
|
@ -9,6 +14,17 @@ reducers[types.DAEMON_SETTINGS_RECEIVED] = function(state, action) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
reducers[types.CLIENT_SETTING_CHANGED] = function(state, action) {
|
||||||
|
const { key, value } = action.data;
|
||||||
|
const clientSettings = Object.assign({}, state.clientSettings);
|
||||||
|
|
||||||
|
clientSettings[key] = value;
|
||||||
|
|
||||||
|
return Object.assign({}, state, {
|
||||||
|
clientSettings,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export default function reducer(state = defaultState, action) {
|
export default function reducer(state = defaultState, action) {
|
||||||
const handler = reducers[action.type];
|
const handler = reducers[action.type];
|
||||||
if (handler) return handler(state, action);
|
if (handler) return handler(state, action);
|
||||||
|
|
|
@ -177,14 +177,6 @@ export const selectDaemonReady = createSelector(
|
||||||
state => state.daemonReady
|
state => state.daemonReady
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls to lbry.getClientSetting shouldn't be happening in selector logic, but settings have not
|
|
||||||
* properly been reworked into redux framework. This added as a bug fix to NSFW settings not refreshing.
|
|
||||||
*/
|
|
||||||
export const selectObscureNsfw = () => {
|
|
||||||
return !lbry.getClientSetting("showNsfw");
|
|
||||||
};
|
|
||||||
|
|
||||||
export const selectSnackBar = createSelector(
|
export const selectSnackBar = createSelector(
|
||||||
_selectState,
|
_selectState,
|
||||||
state => state.snackBar || {}
|
state => state.snackBar || {}
|
||||||
|
|
|
@ -9,10 +9,15 @@ export const selectDaemonSettings = createSelector(
|
||||||
|
|
||||||
export const selectClientSettings = createSelector(
|
export const selectClientSettings = createSelector(
|
||||||
_selectState,
|
_selectState,
|
||||||
state => state.clientSettings
|
state => state.clientSettings || {}
|
||||||
);
|
);
|
||||||
|
|
||||||
export const selectSettingsIsGenerous = createSelector(
|
export const selectSettingsIsGenerous = createSelector(
|
||||||
selectDaemonSettings,
|
selectDaemonSettings,
|
||||||
settings => settings && settings.is_generous_host
|
settings => settings && settings.is_generous_host
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const selectShowNsfw = createSelector(
|
||||||
|
selectClientSettings,
|
||||||
|
clientSettings => !!clientSettings.showNsfw
|
||||||
|
);
|
||||||
|
|
Loading…
Reference in a new issue