Merge pull request #670 from esteemapp/feature/defaultFooter

Default Feature [PART 1] [FOR NEXT RELEASE]
This commit is contained in:
Mustafa Buyukcelebi 2019-03-17 00:30:51 +03:00 committed by GitHub
commit 09b6086796
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 83 additions and 34 deletions

View File

@ -66,6 +66,7 @@
"pincode": "PIN code", "pincode": "PIN code",
"reset": "Reset", "reset": "Reset",
"nsfw_content": "NSFW Content", "nsfw_content": "NSFW Content",
"default_footer": "Default Footer",
"nsfw": { "nsfw": {
"always_show": "Always show", "always_show": "Always show",
"always_hide": "Always hide", "always_hide": "Always hide",

View File

@ -45,13 +45,14 @@ const draftSchema = {
const settingsSchema = { const settingsSchema = {
name: SETTINGS_SCHEMA, name: SETTINGS_SCHEMA,
properties: { properties: {
language: { type: 'string', default: null },
isDarkTheme: { type: 'bool', default: false },
currency: { type: 'string', default: null }, currency: { type: 'string', default: null },
isDarkTheme: { type: 'bool', default: false },
isDefaultFooter: { type: 'bool', default: true },
language: { type: 'string', default: null },
notification: { type: 'bool', default: true }, notification: { type: 'bool', default: true },
nsfw: { type: 'string', default: null },
server: { type: 'string', default: null }, server: { type: 'string', default: null },
upvotePercent: { type: 'string', default: null }, upvotePercent: { type: 'string', default: null },
nsfw: { type: 'string', default: null },
}, },
}; };
@ -358,6 +359,17 @@ export const setTheme = isDarkTheme => new Promise((resolve, reject) => {
} }
}); });
export const setDefaultFooter = isDefaultFooter => new Promise((resolve, reject) => {
try {
realm.write(() => {
settings[0].isDefaultFooter = isDefaultFooter;
resolve(true);
});
} catch (error) {
reject(error);
}
});
export const setUpvotePercent = percent => new Promise((resolve, reject) => { export const setUpvotePercent = percent => new Promise((resolve, reject) => {
try { try {
realm.write(() => { realm.write(() => {

View File

@ -5,6 +5,7 @@ import {
CLOSE_PIN_CODE_MODAL, CLOSE_PIN_CODE_MODAL,
IS_CONNECTED, IS_CONNECTED,
IS_DARK_THEME, IS_DARK_THEME,
IS_DEFAULT_FOOTER,
IS_LOGIN_DONE, IS_LOGIN_DONE,
IS_NOTIFICATION_OPEN, IS_NOTIFICATION_OPEN,
LOGIN, LOGIN,
@ -14,8 +15,8 @@ import {
SET_API, SET_API,
SET_CURRENCY, SET_CURRENCY,
SET_LANGUAGE, SET_LANGUAGE,
SET_UPVOTE_PERCENT,
SET_NSFW, SET_NSFW,
SET_UPVOTE_PERCENT,
} from '../constants/constants'; } from '../constants/constants';
export const login = payload => ({ export const login = payload => ({
@ -83,6 +84,11 @@ export const setNsfw = payload => ({
type: SET_NSFW, type: SET_NSFW,
}); });
export const isDefaultFooter = payload => ({
payload,
type: IS_DEFAULT_FOOTER,
});
/** /**
* MW * MW
*/ */

View File

@ -11,6 +11,7 @@ export const IS_DARK_THEME = 'IS_DARK_THEME';
export const IS_LOGGED_IN = 'IS_LOGGED_IN'; export const IS_LOGGED_IN = 'IS_LOGGED_IN';
export const IS_LOGIN_DONE = 'IS_LOGIN_DONE'; export const IS_LOGIN_DONE = 'IS_LOGIN_DONE';
export const IS_NOTIFICATION_OPEN = 'IS_NOTIFICATION_OPEN'; export const IS_NOTIFICATION_OPEN = 'IS_NOTIFICATION_OPEN';
export const IS_DEFAULT_FOOTER = 'IS_DEFAULT_FOOTER';
export const LOGIN = 'LOGIN'; export const LOGIN = 'LOGIN';
export const LOGOUT = 'LOGOUT'; export const LOGOUT = 'LOGOUT';
export const LOGOUT_DONE = 'LOGOUT_DONE'; export const LOGOUT_DONE = 'LOGOUT_DONE';

View File

@ -3,6 +3,7 @@ import {
CLOSE_PIN_CODE_MODAL, CLOSE_PIN_CODE_MODAL,
IS_CONNECTED, IS_CONNECTED,
IS_DARK_THEME, IS_DARK_THEME,
IS_DEFAULT_FOOTER,
IS_LOGIN_DONE, IS_LOGIN_DONE,
IS_NOTIFICATION_OPEN, IS_NOTIFICATION_OPEN,
LOGIN, LOGIN,
@ -12,8 +13,8 @@ import {
SET_API, SET_API,
SET_CURRENCY, SET_CURRENCY,
SET_LANGUAGE, SET_LANGUAGE,
SET_UPVOTE_PERCENT,
SET_NSFW, SET_NSFW,
SET_UPVOTE_PERCENT,
} from '../constants/constants'; } from '../constants/constants';
const initialState = { const initialState = {
@ -26,6 +27,7 @@ const initialState = {
isActive: false, isActive: false,
isConnected: true, // internet connectivity isConnected: true, // internet connectivity
isDarkTheme: false, isDarkTheme: false,
isDefaultFooter: true,
isLoggedIn: false, // Has any logged in user. isLoggedIn: false, // Has any logged in user.
isLoginDone: false, isLoginDone: false,
isLogingOut: false, isLogingOut: false,
@ -107,6 +109,10 @@ export default function (state = initialState, action) {
return Object.assign({}, state, { return Object.assign({}, state, {
nsfw: action.payload, nsfw: action.payload,
}); });
case IS_DEFAULT_FOOTER:
return Object.assign({}, state, {
isDefaultFooter: action.payload,
});
default: default:
return state; return state;
} }

View File

@ -39,6 +39,7 @@ import {
setAuthStatus, setAuthStatus,
removeSCAccount, removeSCAccount,
setExistUser, setExistUser,
setDefaultFooter,
} from '../../../realm/realm'; } from '../../../realm/realm';
import { getUser } from '../../../providers/steem/dsteem'; import { getUser } from '../../../providers/steem/dsteem';
import { setPushToken } from '../../../providers/esteem/esteem'; import { setPushToken } from '../../../providers/esteem/esteem';
@ -247,6 +248,7 @@ class ApplicationContainer extends Component {
if (response.language !== '') dispatch(setLanguage(response.language)); if (response.language !== '') dispatch(setLanguage(response.language));
if (response.server !== '') dispatch(setApi(response.server)); if (response.server !== '') dispatch(setApi(response.server));
if (response.upvotePercent !== '') dispatch(setUpvotePercent(Number(response.upvotePercent))); if (response.upvotePercent !== '') dispatch(setUpvotePercent(Number(response.upvotePercent)));
if (response.isDefaultFooter !== '') dispatch(setDefaultFooter(response.isDefaultFooter));
if (response.notification !== '') { if (response.notification !== '') {
dispatch(isNotificationOpen(response.notification)); dispatch(isNotificationOpen(response.notification));
Push.setEnabled(response.notification); Push.setEnabled(response.notification);

View File

@ -293,7 +293,7 @@ class EditorContainer extends Component {
_submitPost = async (fields) => { _submitPost = async (fields) => {
const { const {
navigation, currentAccount, pinCode, intl, navigation, currentAccount, pinCode, intl, isDefaultFooter,
} = this.props; } = this.props;
if (currentAccount) { if (currentAccount) {
@ -533,9 +533,10 @@ class EditorContainer extends Component {
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({
currentAccount: state.account.currentAccount,
isDefaultFooter: state.account.isDefaultFooter,
isLoggedIn: state.application.isLoggedIn, isLoggedIn: state.application.isLoggedIn,
pinCode: state.account.pin, pinCode: state.account.pin,
currentAccount: state.account.currentAccount,
}); });
export default connect(mapStateToProps)(injectIntl(EditorContainer)); export default connect(mapStateToProps)(injectIntl(EditorContainer));

View File

@ -7,23 +7,25 @@ import { Client } from 'dsteem';
// Realm // Realm
import { import {
setTheme,
setLanguage as setLanguage2DB,
setCurrency as setCurrency2DB,
setServer,
setNotificationIsOpen,
getExistUser, getExistUser,
setCurrency as setCurrency2DB,
setDefaultFooter,
setLanguage as setLanguage2DB,
setNotificationIsOpen,
setNsfw as setNsfw2DB, setNsfw as setNsfw2DB,
setServer,
setTheme,
} from '../../../realm/realm'; } from '../../../realm/realm';
// Services and Actions // Services and Actions
import { import {
setLanguage,
isNotificationOpen,
setCurrency,
setApi,
isDarkTheme, isDarkTheme,
isDefaultFooter,
isNotificationOpen,
openPinCodeModal, openPinCodeModal,
setApi,
setCurrency,
setLanguage,
setNsfw, setNsfw,
} from '../../../redux/actions/applicationActions'; } from '../../../redux/actions/applicationActions';
import { toastNotification } from '../../../redux/actions/uiAction'; import { toastNotification } from '../../../redux/actions/uiAction';
@ -150,6 +152,11 @@ class SettingsContainer extends Component {
dispatch(isDarkTheme(action)); dispatch(isDarkTheme(action));
setTheme(action); setTheme(action);
break; break;
case 'default_footer':
dispatch(isDefaultFooter(action));
// setDefaultFooter(action);
break;
default: default:
break; break;
} }
@ -231,14 +238,15 @@ class SettingsContainer extends Component {
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({
selectedLanguage: state.application.language, isDarkTheme: state.application.isDarkTheme,
isDefaultFooter: state.application.isDefaultFooter,
isLoggedIn: state.application.isLoggedIn,
isNotificationSettingsOpen: state.application.isNotificationOpen,
nsfw: state.application.nsfw,
selectedApi: state.application.api, selectedApi: state.application.api,
selectedCurrency: state.application.currency, selectedCurrency: state.application.currency,
isDarkTheme: state.application.isDarkTheme, selectedLanguage: state.application.language,
isNotificationSettingsOpen: state.application.isNotificationOpen,
isLoggedIn: state.application.isLoggedIn,
username: state.account.currentAccount && state.account.currentAccount.name, username: state.account.currentAccount && state.account.currentAccount.name,
nsfw: state.application.nsfw,
}); });
export default connect(mapStateToProps)(SettingsContainer); export default connect(mapStateToProps)(SettingsContainer);

View File

@ -1,4 +1,4 @@
import React, { PureComponent } from 'react'; import React, { PureComponent, Fragment } from 'react';
import { ScrollView, View } from 'react-native'; import { ScrollView, View } from 'react-native';
import { injectIntl } from 'react-intl'; import { injectIntl } from 'react-intl';
@ -36,13 +36,14 @@ class SettingsScreen extends PureComponent {
handleOnChange, handleOnChange,
intl, intl,
isDarkTheme, isDarkTheme,
isDefaultFooter,
isLoggedIn, isLoggedIn,
isNotificationSettingsOpen, isNotificationSettingsOpen,
nsfw,
selectedApi, selectedApi,
selectedCurrency, selectedCurrency,
selectedLanguage, selectedLanguage,
serverList, serverList,
nsfw,
} = this.props; } = this.props;
return ( return (
@ -116,6 +117,16 @@ class SettingsScreen extends PureComponent {
handleOnChange={handleOnChange} handleOnChange={handleOnChange}
/> />
{!!isLoggedIn && ( {!!isLoggedIn && (
<Fragment>
<SettingsItem
title={intl.formatMessage({
id: 'settings.default_footer',
})}
type="toggle"
actionType="default_footer"
isOn={isDefaultFooter}
handleOnChange={handleOnChange}
/>
<SettingsItem <SettingsItem
title={intl.formatMessage({ title={intl.formatMessage({
id: 'settings.pincode', id: 'settings.pincode',
@ -127,6 +138,7 @@ class SettingsScreen extends PureComponent {
actionType="pincode" actionType="pincode"
handleOnChange={handleOnChange} handleOnChange={handleOnChange}
/> />
</Fragment>
)} )}
</ScrollView> </ScrollView>
</View> </View>