Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #9 from mattermost/plt-5932
Browse files Browse the repository at this point in the history
PLT-5932 Split out action_types from constants
  • Loading branch information
jwilander authored and hmhealey committed Aug 28, 2020
1 parent 6c18b57 commit 8af1e72
Show file tree
Hide file tree
Showing 50 changed files with 678 additions and 682 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import keyMirror from 'utils/key_mirror';

const ChannelTypes = keyMirror({
export default keyMirror({
CHANNEL_REQUEST: null,
CHANNEL_SUCCESS: null,
CHANNEL_FAILURE: null,
Expand Down Expand Up @@ -79,5 +79,3 @@ const ChannelTypes = keyMirror({
UPDATE_CHANNEL_HEADER: null,
UPDATE_CHANNEL_PURPOSE: null
});

export default ChannelTypes;
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@

import keyMirror from 'utils/key_mirror';

const ErrorTypes = keyMirror({
export default keyMirror({
DISMISS_ERROR: null,
LOG_ERROR: null,
CLEAR_ERRORS: null
});

export default ErrorTypes;
12 changes: 12 additions & 0 deletions packages/mattermost-redux/src/action_types/files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import keyMirror from 'utils/key_mirror';

export default keyMirror({
FETCH_FILES_FOR_POST_REQUEST: null,
FETCH_FILES_FOR_POST_SUCCESS: null,
FETCH_FILES_FOR_POST_FAILURE: null,

RECEIVED_FILES_FOR_POST: null
});
36 changes: 36 additions & 0 deletions packages/mattermost-redux/src/action_types/general.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import keyMirror from 'utils/key_mirror';

export default keyMirror({
RECEIVED_APP_STATE: null,
RECEIVED_APP_CREDENTIALS: null,
REMOVED_APP_CREDENTIALS: null,
RECEIVED_APP_DEVICE_TOKEN: null,

PING_REQUEST: null,
PING_SUCCESS: null,
PING_FAILURE: null,
PING_RESET: null,

RECEIVED_SERVER_VERSION: null,

CLIENT_CONFIG_REQUEST: null,
CLIENT_CONFIG_SUCCESS: null,
CLIENT_CONFIG_FAILURE: null,
CLIENT_CONFIG_RECEIVED: null,

CLIENT_LICENSE_REQUEST: null,
CLIENT_LICENSE_SUCCESS: null,
CLIENT_LICENSE_FAILURE: null,
CLIENT_LICENSE_RECEIVED: null,

LOG_CLIENT_ERROR_REQUEST: null,
LOG_CLIENT_ERROR_SUCCESS: null,
LOG_CLIENT_ERROR_FAILURE: null,

WEBSOCKET_REQUEST: null,
WEBSOCKET_SUCCESS: null,
WEBSOCKET_FAILURE: null
});
22 changes: 22 additions & 0 deletions packages/mattermost-redux/src/action_types/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import ChannelTypes from './channels';
import ErrorTypes from './errors';
import GeneralTypes from './general';
import UserTypes from './users';
import TeamTypes from './teams';
import PostTypes from './posts';
import FileTypes from './files';
import PreferenceTypes from './preferences';

export {
ErrorTypes,
GeneralTypes,
UserTypes,
TeamTypes,
ChannelTypes,
PostTypes,
FileTypes,
PreferenceTypes
};
46 changes: 46 additions & 0 deletions packages/mattermost-redux/src/action_types/posts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import keyMirror from 'utils/key_mirror';

export default keyMirror({
CREATE_POST_REQUEST: null,
CREATE_POST_SUCCESS: null,
CREATE_POST_FAILURE: null,

EDIT_POST_REQUEST: null,
EDIT_POST_SUCCESS: null,
EDIT_POST_FAILURE: null,

DELETE_POST_REQUEST: null,
DELETE_POST_SUCCESS: null,
DELETE_POST_FAILURE: null,

GET_POST_REQUEST: null,
GET_POST_SUCCESS: null,
GET_POST_FAILURE: null,

GET_POSTS_REQUEST: null,
GET_POSTS_SUCCESS: null,
GET_POSTS_FAILURE: null,

GET_POSTS_SINCE_REQUEST: null,
GET_POSTS_SINCE_SUCCESS: null,
GET_POSTS_SINCE_FAILURE: null,

GET_POSTS_BEFORE_REQUEST: null,
GET_POSTS_BEFORE_SUCCESS: null,
GET_POSTS_BEFORE_FAILURE: null,

GET_POSTS_AFTER_REQUEST: null,
GET_POSTS_AFTER_SUCCESS: null,
GET_POSTS_AFTER_FAILURE: null,

RECEIVED_POST: null,
RECEIVED_POSTS: null,
RECEIVED_FOCUSED_POST: null,
RECEIVED_POST_SELECTED: null,
RECEIVED_EDIT_POST: null,
POST_DELETED: null,
REMOVE_POST: null
});
21 changes: 21 additions & 0 deletions packages/mattermost-redux/src/action_types/preferences.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import keyMirror from 'utils/key_mirror';

export default keyMirror({
MY_PREFERENCES_REQUEST: null,
MY_PREFERENCES_SUCCESS: null,
MY_PREFERENCES_FAILURE: null,

SAVE_PREFERENCES_REQUEST: null,
SAVE_PREFERENCES_SUCCESS: null,
SAVE_PREFERENCES_FAILURE: null,

DELETE_PREFERENCES_REQUEST: null,
DELETE_PREFERENCES_SUCCESS: null,
DELETE_PREFERENCES_FAILURE: null,

RECEIVED_PREFERENCES: null,
DELETED_PREFERENCES: null
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import keyMirror from 'utils/key_mirror';

const TeamTypes = keyMirror({
export default keyMirror({
FETCH_TEAMS_REQUEST: null,
FETCH_TEAMS_SUCCESS: null,
FETCH_TEAMS_FAILURE: null,
Expand Down Expand Up @@ -52,5 +52,3 @@ const TeamTypes = keyMirror({
RECEIVED_TEAM_STATS: null,
LEAVE_TEAM: null
});

export default TeamTypes;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import keyMirror from 'utils/key_mirror';

const UserTypes = keyMirror({
export default keyMirror({
LOGIN_REQUEST: null,
LOGIN_SUCCESS: null,
LOGIN_FAILURE: null,
Expand Down Expand Up @@ -75,5 +75,3 @@ const UserTypes = keyMirror({
RECEIVED_AUTOCOMPLETE_IN_CHANNEL: null,
RESET_LOGOUT_STATE: null
});

export default UserTypes;
27 changes: 11 additions & 16 deletions packages/mattermost-redux/src/actions/channels.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import {
Constants,
ChannelTypes,
Preferences,
PreferencesTypes,
UsersTypes
} from 'constants';
import {General, Preferences} from 'constants';
import {ChannelTypes, PreferenceTypes, UserTypes} from 'action_types';
import {batchActions} from 'redux-batched-actions';

import Client from 'client';
Expand Down Expand Up @@ -61,7 +56,7 @@ export function createChannel(channel, userId) {
const member = {
channel_id: created.id,
user_id: userId,
roles: `${Constants.CHANNEL_USER_ROLE} ${Constants.CHANNEL_ADMIN_ROLE}`,
roles: `${General.CHANNEL_USER_ROLE} ${General.CHANNEL_ADMIN_ROLE}`,
last_viewed_at: 0,
msg_count: 0,
mention_count: 0,
Expand Down Expand Up @@ -114,7 +109,7 @@ export function createDirectChannel(teamId, userId, otherUserId) {
const member = {
channel_id: created.id,
user_id: userId,
roles: `${Constants.CHANNEL_USER_ROLE} ${Constants.CHANNEL_ADMIN_ROLE}`,
roles: `${General.CHANNEL_USER_ROLE} ${General.CHANNEL_ADMIN_ROLE}`,
last_viewed_at: 0,
msg_count: 0,
mention_count: 0,
Expand All @@ -132,7 +127,7 @@ export function createDirectChannel(teamId, userId, otherUserId) {
data: member
},
{
type: PreferencesTypes.RECEIVED_PREFERENCES,
type: PreferenceTypes.RECEIVED_PREFERENCES,
data: [{category: Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, name: otherUserId, value: 'true'}]
},
{
Expand Down Expand Up @@ -371,7 +366,7 @@ export function joinChannel(userId, teamId, channelId, channelName) {
const channelMember = {
channel_id: channel.id,
user_id: userId,
roles: `${Constants.CHANNEL_USER_ROLE}`,
roles: `${General.CHANNEL_USER_ROLE}`,
last_viewed_at: 0,
msg_count: 0,
mention_count: 0,
Expand Down Expand Up @@ -413,7 +408,7 @@ export function deleteChannel(teamId, channelId) {
const entities = getState().entities;
const {channels, currentChannelId} = entities.channels;
if (channelId === currentChannelId) {
const channel = Object.keys(channels).filter((key) => channels[key].name === Constants.DEFAULT_CHANNEL);
const channel = Object.keys(channels).filter((key) => channels[key].name === General.DEFAULT_CHANNEL);
let defaultChannelId = '';
if (channel.length) {
defaultChannelId = channel[0];
Expand Down Expand Up @@ -462,7 +457,7 @@ export function viewChannel(teamId, channelId) {
};
}

export function getMoreChannels(teamId, offset, limit = Constants.CHANNELS_CHUNK_SIZE) {
export function getMoreChannels(teamId, offset, limit = General.CHANNELS_CHUNK_SIZE) {
return async (dispatch, getState) => {
dispatch({type: ChannelTypes.MORE_CHANNELS_REQUEST}, getState);

Expand Down Expand Up @@ -565,7 +560,7 @@ export function addChannelMember(teamId, channelId, userId) {

dispatch(batchActions([
{
type: UsersTypes.RECEIVED_PROFILE_IN_CHANNEL,
type: UserTypes.RECEIVED_PROFILE_IN_CHANNEL,
data: {user_id: userId},
id: channelId
},
Expand Down Expand Up @@ -593,7 +588,7 @@ export function removeChannelMember(teamId, channelId, userId) {

dispatch(batchActions([
{
type: UsersTypes.RECEIVED_PROFILE_NOT_IN_CHANNEL,
type: UserTypes.RECEIVED_PROFILE_NOT_IN_CHANNEL,
data: {user_id: userId},
id: channelId
},
Expand Down Expand Up @@ -675,7 +670,7 @@ export function markChannelAsUnread(channelId, mentionsArray) {

if (channel && member) {
channel.total_msg_count++;
if (member.notify_props && member.notify_props.mark_unread === Constants.MENTION) {
if (member.notify_props && member.notify_props.mark_unread === General.MENTION) {
member.msg_count++;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/mattermost-redux/src/actions/errors.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import {ErrorTypes} from 'constants';
import {ErrorTypes} from 'action_types';

export function dismissErrorObject(index) {
return {
Expand Down
10 changes: 5 additions & 5 deletions packages/mattermost-redux/src/actions/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,34 @@
import {batchActions} from 'redux-batched-actions';

import Client from 'client';
import {FilesTypes} from 'constants';
import {FileTypes} from 'action_types';
import {getLogErrorAction} from './errors';
import {forceLogoutIfNecessary} from './helpers';

export function getFilesForPost(teamId, channelId, postId) {
return async (dispatch, getState) => {
dispatch({type: FilesTypes.FETCH_FILES_FOR_POST_REQUEST}, getState);
dispatch({type: FileTypes.FETCH_FILES_FOR_POST_REQUEST}, getState);
let files;

try {
files = await Client.getFileInfosForPost(teamId, channelId, postId);
} catch (error) {
forceLogoutIfNecessary(error, dispatch);
dispatch(batchActions([
{type: FilesTypes.FETCH_FILES_FOR_POST_FAILURE, error},
{type: FileTypes.FETCH_FILES_FOR_POST_FAILURE, error},
getLogErrorAction(error)
]), getState);
return;
}

dispatch(batchActions([
{
type: FilesTypes.RECEIVED_FILES_FOR_POST,
type: FileTypes.RECEIVED_FILES_FOR_POST,
data: files,
postId
},
{
type: FilesTypes.FETCH_FILES_FOR_POST_SUCCESS
type: FileTypes.FETCH_FILES_FOR_POST_SUCCESS
}
]), getState);
};
Expand Down
2 changes: 1 addition & 1 deletion packages/mattermost-redux/src/actions/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {batchActions} from 'redux-batched-actions';

import Client from 'client';
import {bindClientFunc, FormattedError} from './helpers.js';
import {GeneralTypes} from 'constants';
import {GeneralTypes} from 'action_types';
import {getMyChannelMembers} from './channels';
import {getLogErrorAction} from './errors';
import {loadMe} from './users';
Expand Down
6 changes: 3 additions & 3 deletions packages/mattermost-redux/src/actions/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

import {batchActions} from 'redux-batched-actions';
import Client from 'client';
import {UsersTypes} from 'constants';
import {UserTypes} from 'action_types';
import {getLogErrorAction} from './errors';
const HTTP_UNAUTHORIZED = 401;

export async function forceLogoutIfNecessary(err, dispatch) {
if (err.status_code === HTTP_UNAUTHORIZED && err.url.indexOf('/login') === -1) {
dispatch({type: UsersTypes.LOGOUT_REQUEST});
dispatch({type: UserTypes.LOGOUT_REQUEST});
await Client.logout();
dispatch({type: UsersTypes.LOGOUT_SUCCESS});
dispatch({type: UserTypes.LOGOUT_SUCCESS});
}
}

Expand Down
Loading

0 comments on commit 8af1e72

Please sign in to comment.