Skip to content

Commit

Permalink
Remove flux stores (mattermost#2110)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwilander authored and hmhealey committed Nov 30, 2018
1 parent 1713b62 commit 329cd98
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 2,186 deletions.
112 changes: 13 additions & 99 deletions actions/global_actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See LICENSE.txt for license information.

import debounce from 'lodash/debounce';
import {batchActions} from 'redux-batched-actions';

import {
getChannel,
Expand All @@ -19,7 +20,8 @@ import {Client4} from 'mattermost-redux/client';
import {getConfig} from 'mattermost-redux/selectors/entities/general';
import {getCurrentTeamId, getTeam, getMyTeams, getMyTeamMember} from 'mattermost-redux/selectors/entities/teams';
import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users';
import {getCurrentChannelStats, getCurrentChannelId, getChannelByName} from 'mattermost-redux/selectors/entities/channels';
import {getCurrentChannelStats, getCurrentChannelId, getChannelByName, getMyChannelMember as selectMyChannelMember} from 'mattermost-redux/selectors/entities/channels';
import {ChannelTypes} from 'mattermost-redux/action_types';

import {browserHistory} from 'utils/browser_history';
import {loadChannelsForCurrentUser} from 'actions/channel_actions.jsx';
Expand Down Expand Up @@ -66,6 +68,7 @@ export function emitChannelClickEvent(channel) {
const teamId = chan.team_id || getCurrentTeamId(state);
const isRHSOpened = getIsRhsOpen(state);
const isPinnedPostsShowing = getRhsState(state) === RHSStates.PIN;
const member = selectMyChannelMember(state, chan.id);

getMyChannelMemberPromise.then(() => {
dispatch(getChannelStats(chan.id));
Expand All @@ -89,11 +92,15 @@ export function emitChannelClickEvent(channel) {

loadProfilesForSidebar();

AppDispatcher.handleViewAction({
type: ActionTypes.CLICK_CHANNEL,
id: chan.id,
team_id: teamId,
});
dispatch(batchActions([{
type: ChannelTypes.SELECT_CHANNEL,
data: chan.id,
}, {
type: ActionTypes.SELECT_CHANNEL_WITH_MEMBER,
data: chan.id,
channel: chan,
member,
}]));
}

if (channel.fake) {
Expand Down Expand Up @@ -167,20 +174,6 @@ export async function emitPostFocusEvent(postId, returnTo = '') {
await doFocusPost(channelId, postId, data);
}

export function emitUserPostedEvent(post) {
AppDispatcher.handleServerAction({
type: ActionTypes.CREATE_POST,
post,
});
}

export function emitUserCommentedEvent(post) {
AppDispatcher.handleServerAction({
type: ActionTypes.CREATE_COMMENT,
post,
});
}

export function toggleShortcutsModal() {
AppDispatcher.handleViewAction({
type: ActionTypes.TOGGLE_SHORTCUTS_MODAL,
Expand Down Expand Up @@ -234,76 +227,6 @@ export function showLeavePrivateChannelModal(channel) {
});
}

export function emitSuggestionPretextChanged(suggestionId, pretext) {
AppDispatcher.handleViewAction({
type: ActionTypes.SUGGESTION_PRETEXT_CHANGED,
id: suggestionId,
pretext,
});
}

export function emitSelectNextSuggestion(suggestionId) {
AppDispatcher.handleViewAction({
type: ActionTypes.SUGGESTION_SELECT_NEXT,
id: suggestionId,
});
}

export function emitSelectPreviousSuggestion(suggestionId) {
AppDispatcher.handleViewAction({
type: ActionTypes.SUGGESTION_SELECT_PREVIOUS,
id: suggestionId,
});
}

export function emitCompleteWordSuggestion(suggestionId, term = '') {
AppDispatcher.handleViewAction({
type: Constants.ActionTypes.SUGGESTION_COMPLETE_WORD,
id: suggestionId,
term,
});
}

export function emitClearSuggestions(suggestionId) {
AppDispatcher.handleViewAction({
type: Constants.ActionTypes.SUGGESTION_CLEAR_SUGGESTIONS,
id: suggestionId,
});
}

export function emitPreferenceChangedEvent(preference) {
AppDispatcher.handleServerAction({
type: Constants.ActionTypes.RECEIVED_PREFERENCE,
preference,
});

if (addedNewDmUser(preference)) {
loadProfilesForSidebar();
}
}

export function emitPreferencesChangedEvent(preferences) {
AppDispatcher.handleServerAction({
type: Constants.ActionTypes.RECEIVED_PREFERENCES,
preferences,
});

if (preferences.findIndex(addedNewDmUser) !== -1) {
loadProfilesForSidebar();
}
}

function addedNewDmUser(preference) {
return preference.category === Constants.Preferences.CATEGORY_DIRECT_CHANNEL_SHOW && preference.value === 'true';
}

export function emitPreferencesDeletedEvent(preferences) {
AppDispatcher.handleServerAction({
type: Constants.ActionTypes.DELETED_PREFERENCES,
preferences,
});
}

export function sendEphemeralPost(message, channelId, parentId) {
const timestamp = Utils.getTimestamp();
const post = {
Expand Down Expand Up @@ -364,15 +287,6 @@ export function emitLocalUserTypingEvent(channelId, parentPostId) {
return dispatch(userTyping);
}

export function emitRemoteUserTypingEvent(channelId, userId, postParentId) {
AppDispatcher.handleViewAction({
type: Constants.ActionTypes.USER_TYPING,
channelId,
userId,
postParentId,
});
}

export function emitUserLoggedOutEvent(redirectTo = '/', shouldSignalLogout = true, userAction = true) {
// If the logout was intentional, discard knowledge about having previously been logged in.
// This bit is otherwise used to detect session expirations on the login page.
Expand Down
17 changes: 0 additions & 17 deletions actions/post_actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {addRecentEmoji} from 'actions/emoji_actions';
import * as StorageActions from 'actions/storage';
import {loadNewDMIfNeeded, loadNewGMIfNeeded} from 'actions/user_actions.jsx';
import * as RhsActions from 'actions/views/rhs';
import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
import {isEmbedVisible} from 'selectors/posts';
import {getSelectedPostId, getRhsState} from 'selectors/rhs';
import {
Expand Down Expand Up @@ -223,22 +222,12 @@ export function searchForTerm(term) {
export function pinPost(postId) {
return async (dispatch) => {
await dispatch(PostActions.pinPost(postId));

AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_POST_PINNED,
postId,
});
};
}

export function unpinPost(postId) {
return async (dispatch) => {
await dispatch(PostActions.unpinPost(postId));

AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_POST_UNPINNED,
postId,
});
};
}

Expand Down Expand Up @@ -305,12 +294,6 @@ export function deleteAndRemovePost(post) {
data: post,
});

// Needed for search store
AppDispatcher.handleViewAction({
type: Constants.ActionTypes.REMOVE_POST,
post,
});

return {data: true};
};
}
Expand Down
3 changes: 0 additions & 3 deletions actions/views/create_comment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {Posts} from 'mattermost-redux/constants';
import {isPostPendingOrFailed} from 'mattermost-redux/utils/post_utils';

import * as PostActions from 'actions/post_actions.jsx';
import * as GlobalActions from 'actions/global_actions.jsx';
import {executeCommand} from 'actions/command';
import {setGlobalItem, actionOnGlobalItemsWithPrefix} from 'actions/storage';
import EmojiMap from 'utils/emoji_map';
Expand Down Expand Up @@ -78,8 +77,6 @@ export function submitPost(channelId, rootId, draft) {
create_at: time,
};

GlobalActions.emitUserCommentedEvent(post);

dispatch(PostActions.createPost(post, draft.fileInfos));
};
}
Expand Down
11 changes: 0 additions & 11 deletions actions/views/create_comment.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
} from 'actions/views/create_comment';
import {setGlobalItem, actionOnGlobalItemsWithPrefix} from 'actions/storage';
import * as PostActions from 'actions/post_actions.jsx';
import * as GlobalActions from 'actions/global_actions.jsx';
import {executeCommand} from 'actions/command';
import {StoragePrefixes} from 'utils/constants';

Expand Down Expand Up @@ -207,16 +206,6 @@ describe('rhs view actions', () => {
user_id: currentUserId,
};

test('it calls GlobalActions.emitUserCommentedEvent with post', () => {
store.dispatch(submitPost(channelId, rootId, draft));

expect(GlobalActions.emitUserCommentedEvent).toHaveBeenCalled();

expect(lastCall(GlobalActions.emitUserCommentedEvent.mock.calls)[0]).toEqual(
expect.objectContaining(post)
);
});

test('it call PostActions.createPost with post', () => {
store.dispatch(submitPost(channelId, rootId, draft));

Expand Down
33 changes: 17 additions & 16 deletions actions/websocket_actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
GeneralTypes,
AdminTypes,
IntegrationTypes,
PreferenceTypes,
} from 'mattermost-redux/action_types';
import {WebsocketEvents, General} from 'mattermost-redux/constants';
import {
Expand Down Expand Up @@ -40,7 +41,7 @@ import {loadChannelsForCurrentUser} from 'actions/channel_actions.jsx';
import * as GlobalActions from 'actions/global_actions.jsx';
import {handleNewPost} from 'actions/post_actions.jsx';
import * as StatusActions from 'actions/status_actions.jsx';
import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
import {loadProfilesForSidebar} from 'actions/user_actions.jsx';
import store from 'stores/redux_store.jsx';
import WebSocketClient from 'client/web_websocket_client.jsx';
import {loadPlugin, loadPluginsIfNecessary, removePlugin} from 'plugins';
Expand Down Expand Up @@ -480,23 +481,11 @@ function handlePostEditEvent(msg) {
dispatch(viewChannel(currentChannelId));
}
}

// Needed for search store
AppDispatcher.handleViewAction({
type: Constants.ActionTypes.POST_UPDATED,
post,
});
}

function handlePostDeleteEvent(msg) {
const post = JSON.parse(msg.data.post);
dispatch({type: PostTypes.POST_DELETED, data: post});

// Needed for search store
AppDispatcher.handleViewAction({
type: Constants.ActionTypes.POST_DELETED,
post,
});
}

async function handleTeamAddedEvent(msg) {
Expand Down Expand Up @@ -726,17 +715,29 @@ function handleChannelDeletedEvent(msg) {

function handlePreferenceChangedEvent(msg) {
const preference = JSON.parse(msg.data.preference);
GlobalActions.emitPreferenceChangedEvent(preference);
dispatch({type: PreferenceTypes.RECEIVED_PREFERENCES, data: [preference]});

if (addedNewDmUser(preference)) {
loadProfilesForSidebar();
}
}

function handlePreferencesChangedEvent(msg) {
const preferences = JSON.parse(msg.data.preferences);
GlobalActions.emitPreferencesChangedEvent(preferences);
dispatch({type: PreferenceTypes.RECEIVED_PREFERENCES, data: preferences});

if (preferences.findIndex(addedNewDmUser) !== -1) {
loadProfilesForSidebar();
}
}

function handlePreferencesDeletedEvent(msg) {
const preferences = JSON.parse(msg.data.preferences);
GlobalActions.emitPreferencesDeletedEvent(preferences);
dispatch({type: PreferenceTypes.DELETED_PREFERENCES, data: preferences});
}

function addedNewDmUser(preference) {
return preference.category === Constants.Preferences.CATEGORY_DIRECT_CHANNEL_SHOW && preference.value === 'true';
}

function handleUserTypingEvent(msg) {
Expand Down
4 changes: 0 additions & 4 deletions components/create_comment/create_comment.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import CreateComment from 'components/create_comment/create_comment.jsx';
import FileUpload from 'components/file_upload';
import FilePreview from 'components/file_preview/file_preview.jsx';

jest.mock('stores/post_store.jsx', () => ({
clearCommentDraftUploads: jest.fn(),
}));

describe('components/CreateComment', () => {
const channelId = 'g6139tbospd18cmxroesdk3kkc';
const rootId = '';
Expand Down
3 changes: 1 addition & 2 deletions components/create_post/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {Posts, Preferences as PreferencesRedux} from 'mattermost-redux/constants

import {connectionErrorCount} from 'selectors/views/system';

import {emitUserPostedEvent, postListScrollChangeToBottom} from 'actions/global_actions.jsx';
import {postListScrollChangeToBottom} from 'actions/global_actions.jsx';
import {addReaction, createPost, setEditingPost} from 'actions/post_actions.jsx';
import {selectPostFromRightHandSideSearchByPostId} from 'actions/views/rhs';
import {executeCommand} from 'actions/command';
Expand Down Expand Up @@ -95,7 +95,6 @@ function mapStateToProps() {

function onSubmitPost(post, fileInfos) {
return (dispatch) => {
emitUserPostedEvent(post);
dispatch(createPost(post, fileInfos));
postListScrollChangeToBottom();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import {getCurrentUserLocale} from 'mattermost-redux/selectors/entities/i18n';
import {haveICurrentTeamPermission} from 'mattermost-redux/selectors/entities/roles';
import {Permissions} from 'mattermost-redux/constants';
import {sortChannelsByTypeAndDisplayName} from 'mattermost-redux/utils/channel_utils';
import {logError} from 'mattermost-redux/actions/errors';

import GlobeIcon from 'components/svg/globe_icon';
import LockIcon from 'components/svg/lock_icon';
import ArchiveIcon from 'components/svg/archive_icon';
import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
import store from 'stores/redux_store.jsx';
import {ActionTypes, Constants} from 'utils/constants.jsx';
import {Constants} from 'utils/constants.jsx';

import Provider from './provider.jsx';
import Suggestion from './suggestion.jsx';
Expand Down Expand Up @@ -153,10 +153,7 @@ export default class SearchChannelWithPermissionsProvider extends Provider {
const {data} = await channelsAsync;
channelsFromServer = data;
} catch (err) {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_ERROR,
err,
});
store.dispatch(logError(err));
}

if (this.shouldCancelDispatch(channelPrefix)) {
Expand Down
Loading

0 comments on commit 329cd98

Please sign in to comment.