Skip to content

Commit

Permalink
Start moving webapp to Redux (mattermost#6140)
Browse files Browse the repository at this point in the history
* Start moving webapp to Redux

* Fix localforage import

* Updates per feedback

* Feedback udpates and a few fixes

* Minor updates

* Fix statuses, config not loading properly, getMe sanitizing too much

* Fix preferences

* Fix user autocomplete

* Fix sessions and audits

* Fix error handling for all redux actions

* Use new directory structure for components and containers

* Refresh immediately on logout instead of after timeout

* Add fetch polyfill
  • Loading branch information
jwilander authored and crspeller committed Apr 25, 2017
1 parent ede07e7 commit 12e752f
Show file tree
Hide file tree
Showing 55 changed files with 1,129 additions and 1,447 deletions.
23 changes: 7 additions & 16 deletions actions/admin_actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,12 @@ import Client from 'client/web_client.jsx';
import * as AsyncClient from 'utils/async_client.jsx';
import {browserHistory} from 'react-router/es6';

export function revokeSession(altId, success, error) {
Client.revokeSession(altId,
() => {
AsyncClient.getSessions();
if (success) {
success();
}
},
(err) => {
if (error) {
error(err);
}
}
);
}
// Redux actions
import store from 'stores/redux_store.jsx';
const dispatch = store.dispatch;
const getState = store.getState;

import {getUser} from 'mattermost-redux/actions/users';

export function saveConfig(config, success, error) {
Client.saveConfig(
Expand Down Expand Up @@ -57,7 +48,7 @@ export function adminResetMfa(userId, success, error) {
Client.adminResetMfa(
userId,
() => {
AsyncClient.getUser(userId);
getUser(userId)(dispatch, getState);

if (success) {
success();
Expand Down
8 changes: 7 additions & 1 deletion actions/emoji_actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import Client from 'client/web_client.jsx';

import {ActionTypes} from 'utils/constants.jsx';

// Redux actions
import store from 'stores/redux_store.jsx';
const dispatch = store.dispatch;
const getState = store.getState;
import {getProfilesByIds} from 'mattermost-redux/actions/users';

export function loadEmoji(getProfiles = true) {
Client.listEmoji(
(data) => {
Expand Down Expand Up @@ -42,5 +48,5 @@ function loadProfilesForEmoji(emojiList) {
return;
}

AsyncClient.getProfilesByIds(list);
getProfilesByIds(list)(dispatch, getState);
}
94 changes: 12 additions & 82 deletions actions/global_actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import UserStore from 'stores/user_store.jsx';
import BrowserStore from 'stores/browser_store.jsx';
import ErrorStore from 'stores/error_store.jsx';
import TeamStore from 'stores/team_store.jsx';
import PreferenceStore from 'stores/preference_store.jsx';
import SearchStore from 'stores/search_store.jsx';

import {handleNewPost, loadPosts, loadPostsBefore, loadPostsAfter} from 'actions/post_actions.jsx';
Expand All @@ -32,6 +31,12 @@ import en from 'i18n/en.json';
import * as I18n from 'i18n/i18n.jsx';
import {browserHistory} from 'react-router/es6';

// Redux actions
import store from 'stores/redux_store.jsx';
const dispatch = store.dispatch;
const getState = store.getState;
import {ChannelTypes} from 'mattermost-redux/action_types';

export function emitChannelClickEvent(channel) {
function userVisitedFakeChannel(chan, success, fail) {
const otherUserId = Utils.getUserIdFromChannelName(chan);
Expand Down Expand Up @@ -77,6 +82,11 @@ export function emitChannelClickEvent(channel) {
channelMember,
prev: oldChannelId
});

dispatch({
type: ChannelTypes.SELECT_CHANNEL,
data: chan.id
}, getState);
}

if (channel.fake) {
Expand All @@ -94,85 +104,6 @@ export function emitChannelClickEvent(channel) {
}
}

export function emitInitialLoad(callback) {
Client.getInitialLoad(
(data) => {
global.window.mm_config = data.client_cfg;
global.window.mm_license = data.license_cfg;

if (global.window && global.window.analytics) {
global.window.analytics.identify(global.window.mm_config.DiagnosticId, {}, {
context: {
ip: '0.0.0.0'
},
page: {
path: '',
referrer: '',
search: '',
title: '',
url: ''
},
anonymousId: '00000000000000000000000000'
});
}

UserStore.setNoAccounts(data.no_accounts);

if (data.user && data.user.id) {
global.window.mm_user = data.user;
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_ME,
me: data.user
});
}

if (data.preferences) {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_PREFERENCES,
preferences: data.preferences
});
}

if (data.teams) {
var teams = {};
data.teams.forEach((team) => {
teams[team.id] = team;
});

AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_ALL_TEAMS,
teams
});
}

if (data.team_members) {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_MY_TEAM_MEMBERS,
team_members: data.team_members
});
}

if (data.direct_profiles) {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_DIRECT_PROFILES,
profiles: data.direct_profiles
});
}

if (callback) {
callback();
}
},
(err) => {
AsyncClient.dispatchError(err, 'getInitialLoad');

if (callback) {
callback();
}
}
);
}

export function doFocusPost(channelId, postId, data) {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_FOCUSED_POST,
Expand Down Expand Up @@ -536,12 +467,11 @@ export function emitUserLoggedOutEvent(redirectTo = '/', shouldSignalLogout = tr
export function clientLogout(redirectTo = '/') {
BrowserStore.clear();
ErrorStore.clearLastError();
PreferenceStore.clear();
UserStore.clear();
TeamStore.clear();
ChannelStore.clear();
stopPeriodicStatusUpdates();
WebsocketActions.close();
localStorage.removeItem('currentUserId');
window.location.href = redirectTo;
}

Expand Down
12 changes: 9 additions & 3 deletions actions/integration_actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import Client from 'client/web_client.jsx';

import {ActionTypes} from 'utils/constants.jsx';

// Redux actions
import store from 'stores/redux_store.jsx';
const dispatch = store.dispatch;
const getState = store.getState;
import {getProfilesByIds} from 'mattermost-redux/actions/users';

export function loadIncomingHooks() {
Client.listIncomingHooks(
(data) => {
Expand Down Expand Up @@ -42,7 +48,7 @@ function loadProfilesForIncomingHooks(hooks) {
return;
}

AsyncClient.getProfilesByIds(list);
getProfilesByIds(list)(dispatch, getState);
}

export function loadOutgoingHooks() {
Expand Down Expand Up @@ -76,7 +82,7 @@ function loadProfilesForOutgoingHooks(hooks) {
return;
}

AsyncClient.getProfilesByIds(list);
getProfilesByIds(list)(dispatch, getState);
}

export function loadTeamCommands() {
Expand Down Expand Up @@ -110,5 +116,5 @@ function loadProfilesForCommands(commands) {
return;
}

AsyncClient.getProfilesByIds(list);
getProfilesByIds(list)(dispatch, getState);
}
8 changes: 7 additions & 1 deletion actions/post_actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ import Constants from 'utils/constants.jsx';
const ActionTypes = Constants.ActionTypes;
const Preferences = Constants.Preferences;

// Redux actions
import store from 'stores/redux_store.jsx';
const dispatch = store.dispatch;
const getState = store.getState;
import {getProfilesByIds} from 'mattermost-redux/actions/users';

export function handleNewPost(post, msg) {
let websocketMessageProps = {};
if (msg) {
Expand Down Expand Up @@ -310,7 +316,7 @@ export function loadProfilesForPosts(posts) {
return;
}

AsyncClient.getProfilesByIds(list);
getProfilesByIds(list)(dispatch, getState);
}

export function addReaction(channelId, postId, emojiName) {
Expand Down
21 changes: 8 additions & 13 deletions actions/status_actions.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import AppDispatcher from 'dispatcher/app_dispatcher.jsx';

import ChannelStore from 'stores/channel_store.jsx';
import PostStore from 'stores/post_store.jsx';
import PreferenceStore from 'stores/preference_store.jsx';
import UserStore from 'stores/user_store.jsx';

import Client from 'client/web_client.jsx';
import {Preferences, Constants} from 'utils/constants.jsx';

// Redux actions
import store from 'stores/redux_store.jsx';
const dispatch = store.dispatch;
const getState = store.getState;

import {ActionTypes, Preferences, Constants} from 'utils/constants.jsx';
import {getStatusesByIds} from 'mattermost-redux/actions/users';

export function loadStatusesForChannel(channelId = ChannelStore.getCurrentId()) {
const postList = PostStore.getVisiblePosts(channelId);
Expand Down Expand Up @@ -108,15 +111,7 @@ export function loadStatusesByIds(userIds) {
return;
}

Client.getStatusesByIds(
userIds,
(data) => {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_STATUSES,
statuses: data
});
}
);
getStatusesByIds(userIds)(dispatch, getState);
}

let intervalId = '';
Expand Down
9 changes: 8 additions & 1 deletion actions/team_actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ import AppDispatcher from 'dispatcher/app_dispatcher.jsx';

import {browserHistory} from 'react-router/es6';

// Redux actions
import store from 'stores/redux_store.jsx';
const dispatch = store.dispatch;
const getState = store.getState;

import {getUser} from 'mattermost-redux/actions/users';

export function checkIfTeamExists(teamName, onSuccess, onError) {
Client.findTeamByName(teamName, onSuccess, onError);
}
Expand Down Expand Up @@ -62,7 +69,7 @@ export function removeUserFromTeam(teamId, userId, success, error) {
TeamStore.removeMemberInTeam(teamId, userId);
UserStore.removeProfileFromTeam(teamId, userId);
UserStore.emitInTeamChange();
AsyncClient.getUser(userId);
getUser(userId)(dispatch, getState);
AsyncClient.getTeamStats(teamId);

if (success) {
Expand Down
Loading

0 comments on commit 12e752f

Please sign in to comment.