Remove inactive

This commit is contained in:
Diego Mello 2020-04-15 14:39:54 -03:00
parent bba76a7879
commit 2b4ef42816
5 changed files with 12 additions and 35 deletions

View File

@ -64,3 +64,4 @@ export const INVITE_LINKS = createRequestTypes('INVITE_LINKS', [
...defaultTypes
]);
export const SETTINGS = createRequestTypes('SETTINGS', ['CLEAR', 'ADD']);
export const APP_STATE = createRequestTypes('APP_STATE', ['FOREGROUND', 'BACKGROUND']);

View File

@ -1,9 +1,7 @@
// https://github.com/bamlab/redux-enhancer-react-native-appstate
import { AppState } from 'react-native';
export const FOREGROUND = 'APP_STATE.FOREGROUND';
export const BACKGROUND = 'APP_STATE.BACKGROUND';
export const INACTIVE = 'APP_STATE.INACTIVE';
import { APP_STATE } from '../actions/actionsTypes';
export default () => createStore => (...args) => {
const store = createStore(...args);
@ -15,9 +13,9 @@ export default () => createStore => (...args) => {
if (currentState !== nextAppState) {
let type;
if (nextAppState === 'active') {
type = FOREGROUND;
type = APP_STATE.FOREGROUND;
} else if (nextAppState === 'background') {
type = BACKGROUND;
type = APP_STATE.BACKGROUND;
}
if (type) {
store.dispatch({

View File

@ -1,36 +1,26 @@
import { FOREGROUND, BACKGROUND, INACTIVE } from '../lib/appStateMiddleware';
import { APP } from '../actions/actionsTypes';
import { APP, APP_STATE } from '../actions/actionsTypes';
const initialState = {
root: null,
ready: false,
inactive: false,
foreground: true,
background: false
};
export default function app(state = initialState, action) {
switch (action.type) {
case FOREGROUND:
case APP_STATE.FOREGROUND:
return {
...state,
inactive: false,
foreground: true,
background: false
};
case BACKGROUND:
case APP_STATE.BACKGROUND:
return {
...state,
inactive: false,
foreground: false,
background: true
};
case INACTIVE:
return {
...state,
inactive: true,
foreground: false,
background: false
};
case APP.START:
return {
...state,

View File

@ -12,7 +12,6 @@ import mergeSubscriptionsRooms from '../lib/methods/helpers/mergeSubscriptionsRo
import RocketChat from '../lib/rocketchat';
import buildMessage from '../lib/methods/helpers/buildMessage';
import protectedFunction from '../lib/methods/helpers/protectedFunction';
import { BACKGROUND, INACTIVE } from '../lib/appStateMiddleware';
const updateRooms = function* updateRooms({ server, newRoomsUpdatedAt }) {
const serversDB = database.servers;
@ -109,8 +108,7 @@ const root = function* root() {
roomsSuccess: take(types.ROOMS.SUCCESS),
roomsFailure: take(types.ROOMS.FAILURE),
serverReq: take(types.SERVER.SELECT_REQUEST),
background: take(BACKGROUND),
inactive: take(INACTIVE),
background: take(types.APP_STATE.BACKGROUND),
logout: take(types.LOGOUT),
timeout: delay(30000)
});

View File

@ -1,11 +1,11 @@
import { takeLatest, select, put } from 'redux-saga/effects';
import { FOREGROUND, BACKGROUND } from '../lib/appStateMiddleware';
import RocketChat from '../lib/rocketchat';
import { setBadgeCount } from '../notifications/push';
import log from '../utils/log';
import { localAuthenticate, saveLastLocalAuthenticationSession } from '../utils/localAuthentication';
import * as actions from '../actions';
import { APP_STATE } from '../actions/actionsTypes';
const appHasComeBackToForeground = function* appHasComeBackToForeground() {
const appRoot = yield select(state => state.app.root);
@ -49,18 +49,8 @@ const appHasComeBackToBackground = function* appHasComeBackToBackground() {
};
const root = function* root() {
yield takeLatest(
FOREGROUND,
appHasComeBackToForeground
);
yield takeLatest(
BACKGROUND,
appHasComeBackToBackground
);
// yield takeLatest(
// INACTIVE,
// appHasComeBackToBackground
// );
yield takeLatest(APP_STATE.FOREGROUND, appHasComeBackToForeground);
yield takeLatest(APP_STATE.BACKGROUND, appHasComeBackToBackground);
};
export default root;