Skip to content

Commit

Permalink
PLT-6173: Offline redux store (mattermost#471)
Browse files Browse the repository at this point in the history
* PLT-6173: Offline redux store

* Review feedback
  • Loading branch information
csduarte authored and enahum committed Apr 10, 2017
1 parent 2251960 commit d206ea6
Show file tree
Hide file tree
Showing 29 changed files with 407 additions and 229 deletions.
103 changes: 103 additions & 0 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -899,3 +899,106 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

---

## redux-action-buffer

A middleware for redux that buffers all actions into a queue until a breaker condition is met, at which point the queue is released (i.e. actions are triggered).

* HOMEPAGE
* https://github.com/rt2zz/redux-action-buffer

* LICENSE

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

---

## redux-persist

Persist and rehydrate a redux store.

* HOMEPAGE
* https://github.com/rt2zz/redux-persis

* LICENSE

The MIT License (MIT)

Copyright (c) 2015-present Zack Story

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

---

## redux-persist-transform-filter

Filter transformator for redux-persist

* HOMEPAGE
* https://github.com/edy/redux-persist-transform-filter

* LICENSE

MIT License

Copyright (c) 2016 Eduard Baun

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Contact GitHub API Training Shop Blog About

---

## jsdom-global

jsdom-global will inject document, window and other DOM API into your Node.js environment. Useful for running, in Node.js, tests that are made for browsers.

* HOMEPAGE
* https://github.com/rstacruz/jsdom-global

* LICENSE

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.google.android.c2dm.permission.SEND" />

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="22" />
Expand Down
150 changes: 0 additions & 150 deletions app/actions/storage/index.js

This file was deleted.

7 changes: 5 additions & 2 deletions app/actions/views/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import {batchActions} from 'redux-batched-actions';

import {ViewTypes} from 'app/constants';
import {updateStorage} from 'app/actions/storage';

import {
fetchMyChannelsAndMembers,
Expand Down Expand Up @@ -219,7 +218,11 @@ export function handleSelectChannel(channelId) {
return async (dispatch, getState) => {
const {currentTeamId} = getState().entities.teams;

updateStorage(currentTeamId, {currentChannelId: channelId});
dispatch({
type: ViewTypes.SET_LAST_CHANNEL_FOR_TEAM,
teamId: currentTeamId,
channelId
});
getChannelStats(currentTeamId, channelId)(dispatch, getState);
selectChannel(channelId)(dispatch, getState);
};
Expand Down
13 changes: 8 additions & 5 deletions app/actions/views/login.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import {GeneralTypes} from 'mattermost-redux/constants';

import {ViewTypes} from 'app/constants';
import {updateStorage} from 'app/actions/storage';
import Client from 'mattermost-redux/client';

export function handleLoginIdChanged(loginId) {
Expand All @@ -24,10 +24,13 @@ export function handlePasswordChanged(password) {
}

export function handleSuccessfulLogin() {
return async () => {
await updateStorage(null, {
url: Client.getUrl(),
token: Client.getToken()
return async (dispatch) => {
dispatch({
type: GeneralTypes.RECEIVED_APP_CREDENTIALS,
data: {
url: Client.getUrl(),
token: Client.getToken()
}
});
};
}
Expand Down
2 changes: 0 additions & 2 deletions app/actions/views/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
} from 'app/actions/views/channel';
import {goToChannelView} from 'app/actions/views/load_team';
import {handleTeamChange, selectFirstAvailableTeam} from 'app/actions/views/select_team';
import {updateStorage} from 'app/actions/storage';

import {getClientConfig, getLicenseConfig, setServerVersion} from 'mattermost-redux/actions/general';
import {markChannelAsRead, viewChannel} from 'mattermost-redux/actions/channels';
Expand All @@ -29,7 +28,6 @@ export function loadConfigAndLicense(serverVersion) {
getClientConfig()(dispatch, getState);
getLicenseConfig()(dispatch, getState);
setServerVersion(serverVersion)(dispatch, getState);
await updateStorage(null, {serverVersion});
};
}

Expand Down
7 changes: 3 additions & 4 deletions app/actions/views/select_team.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import {batchActions} from 'redux-batched-actions';

import {ChannelTypes, TeamsTypes} from 'mattermost-redux/constants';
import {updateStorage} from 'app/actions/storage';

export function handleTeamChange(team) {
return async (dispatch, getState) => {
Expand All @@ -13,12 +12,12 @@ export function handleTeamChange(team) {
return;
}

const storage = await updateStorage('currentTeamId', team.id);
const lastChannelForTeam = storage[team.id] ? storage[team.id].currentChannelId : '';
const state = getState();
const lastChannelId = state.views.team.lastChannelForTeam[team.id] || '';

dispatch(batchActions([
{type: TeamsTypes.SELECT_TEAM, data: team.id},
{type: ChannelTypes.SELECT_CHANNEL, data: lastChannelForTeam}
{type: ChannelTypes.SELECT_CHANNEL, data: lastChannelId}
]), getState);
};
}
Expand Down
6 changes: 2 additions & 4 deletions app/components/root/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export default class Root extends Component {
loadConfigAndLicense: PropTypes.func.isRequired,
logout: PropTypes.func.isRequired,
setAppState: PropTypes.func.isRequired,
flushToStorage: PropTypes.func.isRequired,
unrenderDrawer: PropTypes.func.isRequired
}).isRequired
};
Expand All @@ -48,11 +47,10 @@ export default class Root extends Component {
super(props);

this.handleAppStateChange = this.handleAppStateChange.bind(this);

this.props.actions.setAppState(AppState.currentState === 'active');
}

componentDidMount() {
this.props.actions.setAppState(AppState.currentState === 'active');
AppState.addEventListener('change', this.handleAppStateChange);
EventEmitter.on(Constants.CONFIG_CHANGED, this.handleConfigChanged);
Client.setUserAgent(DeviceInfo.getUserAgent());
Expand All @@ -75,7 +73,7 @@ export default class Root extends Component {
this.props.actions.setAppState(appState === 'active');

if (appState === 'inactive') {
this.props.actions.flushToStorage();
// TODO: See if we still need this
}
}

Expand Down
Loading

0 comments on commit d206ea6

Please sign in to comment.