mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-02 11:15:35 +03:00
Added nsfw settings
This commit is contained in:
parent
fd0bbe15b6
commit
fec326fdcb
@ -63,7 +63,13 @@
|
||||
"dark_theme": "Dark Theme",
|
||||
"push_notification": "Push Notification",
|
||||
"pincode": "PIN code",
|
||||
"reset": "Reset"
|
||||
"reset": "Reset",
|
||||
"nsfw_content": "NSFW Content",
|
||||
"nsfw": {
|
||||
"always_show": "Always show",
|
||||
"always_hide": "Always hide",
|
||||
"always_warn": "Always warn"
|
||||
}
|
||||
},
|
||||
"voters": {
|
||||
"voters_info": "Voters Info",
|
||||
|
5
src/constants/options/nsfw.js
Normal file
5
src/constants/options/nsfw.js
Normal file
@ -0,0 +1,5 @@
|
||||
export default [
|
||||
'settings.nsfw.always_show',
|
||||
'settings.nsfw.always_warn',
|
||||
'settings.nsfw.always_hide',
|
||||
];
|
@ -51,6 +51,7 @@ const settingsSchema = {
|
||||
notification: { type: 'bool', default: true },
|
||||
server: { type: 'string', default: null },
|
||||
upvotePercent: { type: 'string', default: null },
|
||||
nsfw: { type: 'string', default: null },
|
||||
},
|
||||
};
|
||||
|
||||
@ -74,7 +75,7 @@ const authSchema = {
|
||||
const realm = new Realm({
|
||||
path: 'esteem.realm',
|
||||
schema: [userSchema, authSchema, draftSchema, settingsSchema, applicationSchema, scAccounts],
|
||||
schemaVersion: 0,
|
||||
schemaVersion: 1,
|
||||
migration,
|
||||
});
|
||||
|
||||
@ -102,6 +103,7 @@ if (Array.from(settings).length <= 0) {
|
||||
notification: true,
|
||||
server: '',
|
||||
upvotePercent: '1',
|
||||
nsfw: '0',
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -365,6 +367,29 @@ export const getUpvotePercent = () => new Promise((resolve, reject) => {
|
||||
}
|
||||
});
|
||||
|
||||
export const getNsfw = () => new Promise((resolve, reject) => {
|
||||
try {
|
||||
if (settings[0]) {
|
||||
resolve(settings[0].nsfw);
|
||||
} else {
|
||||
resolve(false);
|
||||
}
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
|
||||
export const setNsfw = nsfw => new Promise((resolve, reject) => {
|
||||
try {
|
||||
realm.write(() => {
|
||||
settings[0].nsfw = nsfw;
|
||||
resolve(true);
|
||||
});
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
|
||||
export const getTheme = () => new Promise((resolve, reject) => {
|
||||
try {
|
||||
if (settings[0]) {
|
||||
|
@ -15,6 +15,7 @@ import {
|
||||
SET_CURRENCY,
|
||||
SET_LANGUAGE,
|
||||
SET_UPVOTE_PERCENT,
|
||||
SET_NSFW,
|
||||
} from '../constants/constants';
|
||||
|
||||
export const login = payload => ({
|
||||
@ -77,6 +78,11 @@ export const setConnectivityStatus = payload => ({
|
||||
type: IS_CONNECTED,
|
||||
});
|
||||
|
||||
export const setNsfw = payload => ({
|
||||
payload,
|
||||
type: SET_NSFW,
|
||||
});
|
||||
|
||||
/**
|
||||
* MW
|
||||
*/
|
||||
|
@ -21,6 +21,7 @@ export const SET_API = 'SET_API';
|
||||
export const SET_CURRENCY = 'SET_CURRENCY';
|
||||
export const SET_LANGUAGE = 'SET_LANGUAGE';
|
||||
export const SET_UPVOTE_PERCENT = 'SET_UPVOTE_PERCENT';
|
||||
export const SET_NSFW = 'SET_NSFW';
|
||||
|
||||
// Accounts
|
||||
export const ADD_OTHER_ACCOUNT = 'ADD_OTHER_ACCOUNT';
|
||||
|
@ -13,6 +13,7 @@ import {
|
||||
SET_CURRENCY,
|
||||
SET_LANGUAGE,
|
||||
SET_UPVOTE_PERCENT,
|
||||
SET_NSFW,
|
||||
} from '../constants/constants';
|
||||
|
||||
const initialState = {
|
||||
@ -33,6 +34,7 @@ const initialState = {
|
||||
language: 'en-US',
|
||||
loading: false, // It is lock to all screen and shows loading animation.
|
||||
upvotePercent: 1,
|
||||
nsfw: 'Always show',
|
||||
};
|
||||
|
||||
export default function (state = initialState, action) {
|
||||
@ -101,6 +103,10 @@ export default function (state = initialState, action) {
|
||||
return Object.assign({}, state, {
|
||||
upvotePercent: action.payload,
|
||||
});
|
||||
case SET_NSFW:
|
||||
return Object.assign({}, state, {
|
||||
nsfw: action.payload,
|
||||
});
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
@ -65,6 +65,7 @@ import {
|
||||
setCurrency,
|
||||
setLanguage,
|
||||
setUpvotePercent,
|
||||
setNsfw,
|
||||
} from '../../../redux/actions/applicationActions';
|
||||
|
||||
// Container
|
||||
@ -250,6 +251,7 @@ class ApplicationContainer extends Component {
|
||||
dispatch(isNotificationOpen(response.notification));
|
||||
Push.setEnabled(response.notification);
|
||||
}
|
||||
if (response.nsfw !== '') dispatch(setNsfw(response.nsfw));
|
||||
|
||||
dispatch(setCurrency(response.currency !== '' ? response.currency : 'usd'));
|
||||
|
||||
|
@ -13,6 +13,7 @@ import {
|
||||
setServer,
|
||||
setNotificationIsOpen,
|
||||
getExistUser,
|
||||
setNsfw as setNsfw2DB,
|
||||
} from '../../../realm/realm';
|
||||
|
||||
// Services and Actions
|
||||
@ -23,6 +24,7 @@ import {
|
||||
setApi,
|
||||
isDarkTheme,
|
||||
openPinCodeModal,
|
||||
setNsfw,
|
||||
} from '../../../redux/actions/applicationActions';
|
||||
import { toastNotification } from '../../../redux/actions/uiAction';
|
||||
import { setPushToken, getNodes } from '../../../providers/esteem/esteem';
|
||||
@ -79,6 +81,11 @@ class SettingsContainer extends Component {
|
||||
this._changeApi(action);
|
||||
break;
|
||||
|
||||
case 'nsfw':
|
||||
dispatch(setNsfw(action));
|
||||
setNsfw2DB(action);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -112,7 +119,6 @@ class SettingsContainer extends Component {
|
||||
dispatch(toastNotification('Server not available'));
|
||||
isError = true;
|
||||
|
||||
this.setState({ apiCheck: false });
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -232,6 +238,7 @@ const mapStateToProps = state => ({
|
||||
isNotificationSettingsOpen: state.application.isNotificationOpen,
|
||||
isLoggedIn: state.application.isLoggedIn,
|
||||
username: state.account.currentAccount && state.account.currentAccount.name,
|
||||
nsfw: state.application.nsfw,
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps)(SettingsContainer);
|
||||
|
@ -8,6 +8,7 @@ import { groomingServerName } from '../../../utils/settings';
|
||||
// Constants
|
||||
import LANGUAGE, { VALUE as LANGUAGE_VALUE } from '../../../constants/options/language';
|
||||
import CURRENCY, { VALUE as CURRENCY_VALUE } from '../../../constants/options/currency';
|
||||
import NSFW from '../../../constants/options/nsfw';
|
||||
|
||||
// Components
|
||||
import { BasicHeader } from '../../../components/basicHeader';
|
||||
@ -41,6 +42,7 @@ class SettingsScreen extends PureComponent {
|
||||
selectedCurrency,
|
||||
selectedLanguage,
|
||||
serverList,
|
||||
nsfw,
|
||||
} = this.props;
|
||||
|
||||
return (
|
||||
@ -83,6 +85,18 @@ class SettingsScreen extends PureComponent {
|
||||
defaultText={groomingServerName(selectedApi)}
|
||||
handleOnChange={handleOnChange}
|
||||
/>
|
||||
<SettingsItem
|
||||
title={intl.formatMessage({
|
||||
id: 'settings.nsfw_content',
|
||||
})}
|
||||
type="dropdown"
|
||||
actionType="nsfw"
|
||||
options={NSFW.map(item => intl.formatMessage({
|
||||
id: item,
|
||||
}))}
|
||||
selectedOptionIndex={parseInt(nsfw, 10)}
|
||||
handleOnChange={handleOnChange}
|
||||
/>
|
||||
<SettingsItem
|
||||
title={intl.formatMessage({
|
||||
id: 'settings.dark_theme',
|
||||
|
Loading…
Reference in New Issue
Block a user