mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-20 20:01:56 +03:00
removed getSettings method from applicationContainer in favour of MigrationHelpers
This commit is contained in:
parent
f19320f90d
commit
f00bbff0d3
83
src/screens/application/children/migrationHelpers.ts
Normal file
83
src/screens/application/children/migrationHelpers.ts
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
import { Appearance } from 'react-native';
|
||||||
|
|
||||||
|
// Constants
|
||||||
|
import THEME_OPTIONS from '../../../constants/options/theme';
|
||||||
|
|
||||||
|
// Services
|
||||||
|
import {
|
||||||
|
getSettings,
|
||||||
|
} from '../../../realm/realm';
|
||||||
|
|
||||||
|
import {
|
||||||
|
isDarkTheme,
|
||||||
|
changeNotificationSettings,
|
||||||
|
changeAllNotificationSettings,
|
||||||
|
setApi,
|
||||||
|
setCurrency,
|
||||||
|
setLanguage,
|
||||||
|
setUpvotePercent,
|
||||||
|
setNsfw,
|
||||||
|
isDefaultFooter,
|
||||||
|
isPinCodeOpen,
|
||||||
|
setColorTheme,
|
||||||
|
setSettingsMigrated,
|
||||||
|
} from '../../../redux/actions/applicationActions';
|
||||||
|
import {
|
||||||
|
hideActionModal,
|
||||||
|
hideProfileModal,
|
||||||
|
setRcOffer,
|
||||||
|
toastNotification,
|
||||||
|
} from '../../../redux/actions/uiAction';
|
||||||
|
|
||||||
|
|
||||||
|
//migrates settings from realm to redux once and do no user realm for settings again;
|
||||||
|
export const migrateSettings = async (dispatch: any, settingsMigrated: boolean) => {
|
||||||
|
|
||||||
|
if (settingsMigrated) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//reset certain properties
|
||||||
|
dispatch(hideActionModal());
|
||||||
|
dispatch(hideProfileModal());
|
||||||
|
dispatch(toastNotification(''));
|
||||||
|
dispatch(setRcOffer(false));
|
||||||
|
|
||||||
|
|
||||||
|
const settings = await getSettings();
|
||||||
|
|
||||||
|
if (settings) {
|
||||||
|
const isDarkMode = Appearance.getColorScheme() === 'dark';
|
||||||
|
dispatch(isDarkTheme(settings.isDarkTheme !== null ? settings.isDarkTheme : isDarkMode));
|
||||||
|
dispatch(setColorTheme(THEME_OPTIONS.findIndex(item => item.value === settings.isDarkTheme)));
|
||||||
|
if (settings.isPinCodeOpen !== '') await dispatch(isPinCodeOpen(settings.isPinCodeOpen));
|
||||||
|
if (settings.language !== '') dispatch(setLanguage(settings.language));
|
||||||
|
if (settings.server !== '') dispatch(setApi(settings.server));
|
||||||
|
if (settings.upvotePercent !== '') {
|
||||||
|
dispatch(setUpvotePercent(Number(settings.upvotePercent)));
|
||||||
|
}
|
||||||
|
if (settings.isDefaultFooter !== '') dispatch(isDefaultFooter(settings.isDefaultFooter)); //TODO: remove as not being used
|
||||||
|
|
||||||
|
|
||||||
|
if (settings.nsfw !== '') dispatch(setNsfw(settings.nsfw));
|
||||||
|
|
||||||
|
dispatch(setCurrency(settings.currency !== '' ? settings.currency : 'usd'));
|
||||||
|
|
||||||
|
if (settings.notification !== '') {
|
||||||
|
dispatch(
|
||||||
|
changeNotificationSettings({
|
||||||
|
type: 'notification',
|
||||||
|
action: settings.notification,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
dispatch(changeAllNotificationSettings(settings));
|
||||||
|
}
|
||||||
|
|
||||||
|
await dispatch(setSettingsMigrated(true))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
migrateSettings
|
||||||
|
}
|
@ -104,6 +104,7 @@ import { setMomentLocale } from '../../../utils/time';
|
|||||||
import parseAuthUrl from '../../../utils/parseAuthUrl';
|
import parseAuthUrl from '../../../utils/parseAuthUrl';
|
||||||
import { purgeExpiredCache } from '../../../redux/actions/cacheActions';
|
import { purgeExpiredCache } from '../../../redux/actions/cacheActions';
|
||||||
import { fetchSubscribedCommunities } from '../../../redux/actions/communitiesAction';
|
import { fetchSubscribedCommunities } from '../../../redux/actions/communitiesAction';
|
||||||
|
import MigrationHelpers from '../children/migrationHelpers';
|
||||||
|
|
||||||
// Workaround
|
// Workaround
|
||||||
let previousAppState = 'background';
|
let previousAppState = 'background';
|
||||||
@ -432,12 +433,14 @@ class ApplicationContainer extends Component {
|
|||||||
|
|
||||||
|
|
||||||
_fetchApp = async () => {
|
_fetchApp = async () => {
|
||||||
await this._getSettings();
|
const {dispatch, settingsMigrated} = this.props;
|
||||||
|
|
||||||
|
await MigrationHelpers.migrateSettings(dispatch, settingsMigrated)
|
||||||
this._refreshGlobalProps();
|
this._refreshGlobalProps();
|
||||||
await this._getUserDataFromRealm();
|
await this._getUserDataFromRealm();
|
||||||
this._compareAndPromptForUpdate();
|
this._compareAndPromptForUpdate();
|
||||||
this._registerDeviceForNotifications();
|
this._registerDeviceForNotifications();
|
||||||
this.props.dispatch(purgeExpiredCache());
|
dispatch(purgeExpiredCache());
|
||||||
};
|
};
|
||||||
|
|
||||||
_pushNavigate = (notification) => {
|
_pushNavigate = (notification) => {
|
||||||
@ -753,57 +756,6 @@ class ApplicationContainer extends Component {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
//TODO rename to migrateSettings and move out of application container
|
|
||||||
_getSettings = async () => {
|
|
||||||
const { dispatch, settingsMigrated } = this.props;
|
|
||||||
|
|
||||||
if(settingsMigrated){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//reset certain properties
|
|
||||||
dispatch(hideActionModal());
|
|
||||||
dispatch(hideProfileModal());
|
|
||||||
dispatch(toastNotification(''));
|
|
||||||
dispatch(setRcOffer(false));
|
|
||||||
|
|
||||||
|
|
||||||
const settings = await getSettings();
|
|
||||||
|
|
||||||
if (settings) {
|
|
||||||
const isDarkMode = Appearance.getColorScheme() === 'dark';
|
|
||||||
dispatch(isDarkTheme(settings.isDarkTheme !== null ? settings.isDarkTheme : isDarkMode));
|
|
||||||
dispatch(setColorTheme(THEME_OPTIONS.findIndex(item=>item.value===settings.isDarkTheme)));
|
|
||||||
if (settings.isPinCodeOpen !== '') await dispatch(isPinCodeOpen(settings.isPinCodeOpen));
|
|
||||||
if (settings.language !== '') dispatch(setLanguage(settings.language));
|
|
||||||
if (settings.server !== '') dispatch(setApi(settings.server));
|
|
||||||
if (settings.upvotePercent !== '') {
|
|
||||||
dispatch(setUpvotePercent(Number(settings.upvotePercent)));
|
|
||||||
}
|
|
||||||
if (settings.isDefaultFooter !== '') dispatch(isDefaultFooter(settings.isDefaultFooter)); //TODO: remove as not being used
|
|
||||||
|
|
||||||
|
|
||||||
if (settings.nsfw !== '') dispatch(setNsfw(settings.nsfw));
|
|
||||||
|
|
||||||
dispatch(setCurrency(settings.currency !== '' ? settings.currency : 'usd'));
|
|
||||||
|
|
||||||
if (settings.notification !== '') {
|
|
||||||
dispatch(
|
|
||||||
changeNotificationSettings({
|
|
||||||
type: 'notification',
|
|
||||||
action: settings.notification,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
dispatch(changeAllNotificationSettings(settings));
|
|
||||||
}
|
|
||||||
|
|
||||||
await dispatch(setSettingsMigrated(true))
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//update notification settings and update push token for each signed accoutn useing access tokens
|
//update notification settings and update push token for each signed accoutn useing access tokens
|
||||||
_registerDeviceForNotifications = (settings?:any) => {
|
_registerDeviceForNotifications = (settings?:any) => {
|
||||||
const { otherAccounts, notificationDetails, isNotificationsEnabled } = this.props;
|
const { otherAccounts, notificationDetails, isNotificationsEnabled } = this.props;
|
||||||
|
Loading…
Reference in New Issue
Block a user