PLT-6214 Move channel store and actions over to redux (#6235)

* Move channel store and actions over to redux

* Fix style errors

* Fix unit test

* Various fixes

* More fixes

* Revert config changes
Этот коммит содержится в:
Joram Wilander
2017-04-28 13:16:03 -04:00
коммит произвёл Christopher Speller
родитель 302ec17bee
Коммит 96906482ce
30 изменённых файлов: 499 добавлений и 691 удалений

Просмотреть файл

@@ -6,14 +6,12 @@ import * as RouteUtils from 'routes/route_utils.jsx';
import {browserHistory} from 'react-router/es6';
import TeamStore from 'stores/team_store.jsx';
import UserStore from 'stores/user_store.jsx';
import * as GlobalActions from 'actions/global_actions.jsx';
import {loadStatusesForChannelAndSidebar} from 'actions/status_actions.jsx';
import {reconnect} from 'actions/websocket_actions.jsx';
import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
import Constants from 'utils/constants.jsx';
const ActionTypes = Constants.ActionTypes;
import * as AsyncClient from 'utils/async_client.jsx';
import Client from 'client/web_client.jsx';
import ChannelStore from 'stores/channel_store.jsx';
import BrowserStore from 'stores/browser_store.jsx';
@@ -22,6 +20,13 @@ import integrationsRoute from 'routes/route_integrations.jsx';
import {loadNewDMIfNeeded, loadNewGMIfNeeded, loadProfilesForSidebar} from 'actions/user_actions.jsx';
// Redux actions
import store from 'stores/redux_store.jsx';
const dispatch = store.dispatch;
const getState = store.getState;
import {fetchMyChannelsAndMembers, joinChannel} from 'mattermost-redux/actions/channels';
function onChannelEnter(nextState, replace, callback) {
doChannelChange(nextState, replace, callback);
}
@@ -40,22 +45,16 @@ function doChannelChange(state, replace, callback) {
}
if (!channel) {
Client.joinChannelByName(
state.params.channel,
joinChannel(UserStore.getCurrentId(), TeamStore.getCurrentId(), null, state.params.channel)(dispatch, getState).then(
(data) => {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_CHANNEL,
channel: data
});
GlobalActions.emitChannelClickEvent(data);
callback();
},
() => {
if (state.params.team) {
replace('/' + state.params.team + '/channels/town-square');
} else {
replace('/');
if (data) {
GlobalActions.emitChannelClickEvent(data.channel);
} else if (data == null) {
if (state.params.team) {
replace('/' + state.params.team + '/channels/town-square');
} else {
replace('/');
}
}
callback();
}
@@ -107,25 +106,16 @@ function preNeedsTeam(nextState, replace, callback) {
if (nextState.location.pathname.indexOf('/channels/') > -1 ||
nextState.location.pathname.indexOf('/pl/') > -1) {
AsyncClient.getMyTeamsUnread();
AsyncClient.getMyChannelMembersForTeam(team.id);
fetchMyChannelsAndMembers(team.id)(dispatch, getState);
}
const d1 = $.Deferred(); //eslint-disable-line new-cap
Client.getChannels(
(data) => {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_CHANNELS,
channels: data
});
fetchMyChannelsAndMembers(team.id)(dispatch, getState).then(
() => {
loadStatusesForChannelAndSidebar();
loadProfilesForSidebar();
d1.resolve();
},
(err) => {
AsyncClient.dispatchError(err, 'getChannels');
d1.resolve();
}
);
@@ -166,7 +156,7 @@ export default {
emojiRoute,
{
getComponents: (location, callback) => {
System.import('components/needs_team.jsx').then(RouteUtils.importComponentSuccess(callback));
System.import('components/needs_team').then(RouteUtils.importComponentSuccess(callback));
},
childRoutes: [
{