From 96906482cecb0df21c8e1a40a2ba00c13c0182a7 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Fri, 28 Apr 2017 13:16:03 -0400 Subject: 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 --- webapp/routes/route_team.jsx | 52 ++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 31 deletions(-) (limited to 'webapp/routes/route_team.jsx') diff --git a/webapp/routes/route_team.jsx b/webapp/routes/route_team.jsx index 0a3c0a59f..45494dca5 100644 --- a/webapp/routes/route_team.jsx +++ b/webapp/routes/route_team.jsx @@ -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: [ { -- cgit v1.2.3-1-g7c22