diff --git a/app/lib/createStore.js b/app/lib/createStore.js index 7a2f79a5..f894b543 100644 --- a/app/lib/createStore.js +++ b/app/lib/createStore.js @@ -2,6 +2,7 @@ import { createStore, applyMiddleware } from 'redux'; import createSagaMiddleware from 'redux-saga'; import logger from 'redux-logger'; import { composeWithDevTools } from 'remote-redux-devtools'; +import applyAppStateListener from 'redux-enhancer-react-native-appstate'; import reducers from '../reducers'; import sagas from '../sagas'; @@ -13,12 +14,16 @@ if (__DEV__) { const reduxImmutableStateInvariant = require('redux-immutable-state-invariant').default(); enhacers = composeWithDevTools( + applyAppStateListener(), applyMiddleware(reduxImmutableStateInvariant), applyMiddleware(sagaMiddleware), applyMiddleware(logger) ); } else { - enhacers = composeWithDevTools(applyMiddleware(sagaMiddleware)); + enhacers = composeWithDevTools( + applyAppStateListener(), + applyMiddleware(sagaMiddleware) + ); } const store = enhacers(createStore)(reducers); diff --git a/app/sagas/index.js b/app/sagas/index.js index fcc8fd72..df6f7d7a 100644 --- a/app/sagas/index.js +++ b/app/sagas/index.js @@ -7,6 +7,7 @@ import messages from './messages'; import selectServer from './selectServer'; import createChannel from './createChannel'; import init from './init'; +import state from './state'; const root = function* root() { yield all([ @@ -17,7 +18,8 @@ const root = function* root() { login(), connect(), messages(), - selectServer() + selectServer(), + state() ]); }; // Consider using takeEvery diff --git a/app/sagas/init.js b/app/sagas/init.js index 024c26b4..5117c86c 100644 --- a/app/sagas/init.js +++ b/app/sagas/init.js @@ -1,5 +1,5 @@ import { AsyncStorage } from 'react-native'; -import { call, put, take } from 'redux-saga/effects'; +import { call, put, takeLatest } from 'redux-saga/effects'; import * as actions from '../actions'; import { setServer } from '../actions/server'; import { restoreToken } from '../actions/login'; @@ -9,7 +9,6 @@ import RocketChat from '../lib/rocketchat'; const restore = function* restore() { try { - yield take(APP.INIT); const token = yield call([AsyncStorage, 'getItem'], 'reactnativemeteor_usertoken'); if (token) { yield put(restoreToken(token)); @@ -28,4 +27,8 @@ const restore = function* restore() { console.log(e); } }; -export default restore; + +const root = function* root() { + yield takeLatest(APP.INIT, restore); +}; +export default root; diff --git a/app/sagas/state.js b/app/sagas/state.js new file mode 100644 index 00000000..0f58ae7f --- /dev/null +++ b/app/sagas/state.js @@ -0,0 +1,23 @@ +import { takeLatest } from 'redux-saga/effects'; +import { FOREGROUND, BACKGROUND, INACTIVE } from 'redux-enhancer-react-native-appstate'; + +const appHasComeBackToForeground = function* appHasComeBackToForeground() { + yield console.log('appHasComeBackToForeground'); +}; + +const root = function* root() { + yield takeLatest( + FOREGROUND, + appHasComeBackToForeground + ); + yield takeLatest( + BACKGROUND, + appHasComeBackToForeground + ); + yield takeLatest( + INACTIVE, + appHasComeBackToForeground + ); +}; + +export default root; diff --git a/app/views/RoomsListView.js b/app/views/RoomsListView.js index b6ffcfe1..ebf13071 100644 --- a/app/views/RoomsListView.js +++ b/app/views/RoomsListView.js @@ -259,7 +259,7 @@ export default class RoomsListView extends React.Component { userMentions={item.userMentions} favorite={item.f} name={item.name} - _updatedAt={item._updatedAt} + _updatedAt={item.roomUpdatedAt} key={item._id} type={item.t} baseUrl={this.props.Site_Url} diff --git a/package-lock.json b/package-lock.json index ffe97482..79fa47d6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12564,6 +12564,11 @@ "symbol-observable": "1.0.4" } }, + "redux-enhancer-react-native-appstate": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/redux-enhancer-react-native-appstate/-/redux-enhancer-react-native-appstate-0.3.0.tgz", + "integrity": "sha1-+5Fwk3WM4J9DLNCytWPRNh6PV28=" + }, "redux-immutable-state-invariant": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/redux-immutable-state-invariant/-/redux-immutable-state-invariant-2.1.0.tgz", diff --git a/package.json b/package.json index a18c15b5..efa0055e 100644 --- a/package.json +++ b/package.json @@ -46,14 +46,15 @@ "react-redux": "^5.0.6", "realm": "^2.0.7", "redux": "^3.7.2", + "redux-enhancer-react-native-appstate": "^0.3.0", "redux-immutable-state-invariant": "^2.1.0", "redux-logger": "^3.0.6", "redux-saga": "^0.16.0", "regenerator-runtime": "^0.11.0", "remote-redux-devtools": "^0.5.12", - "strip-ansi": "^4.0.0", "@storybook/react-native": "^3.2.15", - "snyk": "^1.41.1" + "snyk": "^1.41.1", + "strip-ansi": "^4.0.0" }, "devDependencies": { "@storybook/addon-storyshots": "^3.2.15",