Move instances of Client.leaveChannel() in components to an action (#5131)
* Move instances of Client.leaveChannel() in components to an action * create isFavoriteChannelId
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
e8d7701b60
Коммит
6097f93704
@@ -6,6 +6,7 @@ import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
|
|||||||
import TeamStore from 'stores/team_store.jsx';
|
import TeamStore from 'stores/team_store.jsx';
|
||||||
import UserStore from 'stores/user_store.jsx';
|
import UserStore from 'stores/user_store.jsx';
|
||||||
import ChannelStore from 'stores/channel_store.jsx';
|
import ChannelStore from 'stores/channel_store.jsx';
|
||||||
|
import * as ChannelUtils from 'utils/channel_utils.jsx';
|
||||||
import PreferenceStore from 'stores/preference_store.jsx';
|
import PreferenceStore from 'stores/preference_store.jsx';
|
||||||
|
|
||||||
import {loadProfilesAndTeamMembersForDMSidebar} from 'actions/user_actions.jsx';
|
import {loadProfilesAndTeamMembersForDMSidebar} from 'actions/user_actions.jsx';
|
||||||
@@ -434,3 +435,29 @@ export function getChannelMembersForUserIds(channelId, userIds, success, error)
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function leaveChannel(channelId, success, error) {
|
||||||
|
Client.leaveChannel(channelId,
|
||||||
|
() => {
|
||||||
|
loadChannelsForCurrentUser();
|
||||||
|
|
||||||
|
if (ChannelUtils.isFavoriteChannelId(channelId)) {
|
||||||
|
unmarkFavorite(channelId);
|
||||||
|
}
|
||||||
|
|
||||||
|
const townsquare = ChannelStore.getByName('town-square');
|
||||||
|
browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/channels/' + townsquare.name);
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
success();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(err) => {
|
||||||
|
AsyncClient.dispatchError(err, 'handleLeave');
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
error(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -29,15 +29,12 @@ import * as ChannelActions from 'actions/channel_actions.jsx';
|
|||||||
import * as Utils from 'utils/utils.jsx';
|
import * as Utils from 'utils/utils.jsx';
|
||||||
import * as ChannelUtils from 'utils/channel_utils.jsx';
|
import * as ChannelUtils from 'utils/channel_utils.jsx';
|
||||||
import * as TextFormatting from 'utils/text_formatting.jsx';
|
import * as TextFormatting from 'utils/text_formatting.jsx';
|
||||||
import Client from 'client/web_client.jsx';
|
|
||||||
import * as AsyncClient from 'utils/async_client.jsx';
|
|
||||||
import {getFlaggedPosts} from 'actions/post_actions.jsx';
|
import {getFlaggedPosts} from 'actions/post_actions.jsx';
|
||||||
|
|
||||||
import {Constants, Preferences, UserStatuses} from 'utils/constants.jsx';
|
import {Constants, Preferences, UserStatuses} from 'utils/constants.jsx';
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {FormattedMessage} from 'react-intl';
|
import {FormattedMessage} from 'react-intl';
|
||||||
import {browserHistory} from 'react-router/es6';
|
|
||||||
import {Tooltip, OverlayTrigger, Popover} from 'react-bootstrap';
|
import {Tooltip, OverlayTrigger, Popover} from 'react-bootstrap';
|
||||||
|
|
||||||
const PreReleaseFeatures = Constants.PRE_RELEASE_FEATURES;
|
const PreReleaseFeatures = Constants.PRE_RELEASE_FEATURES;
|
||||||
@@ -131,21 +128,7 @@ export default class ChannelHeader extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleLeave() {
|
handleLeave() {
|
||||||
Client.leaveChannel(this.state.channel.id,
|
ChannelActions.leaveChannel(this.state.channel.id);
|
||||||
() => {
|
|
||||||
const channelId = this.state.channel.id;
|
|
||||||
|
|
||||||
if (this.state.isFavorite) {
|
|
||||||
ChannelActions.unmarkFavorite(channelId);
|
|
||||||
}
|
|
||||||
|
|
||||||
const townsquare = ChannelStore.getByName('town-square');
|
|
||||||
browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/channels/' + townsquare.name);
|
|
||||||
},
|
|
||||||
(err) => {
|
|
||||||
AsyncClient.dispatchError(err, 'handleLeave');
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleFavorite = (e) => {
|
toggleFavorite = (e) => {
|
||||||
|
|||||||
@@ -22,8 +22,6 @@ import PreferenceStore from 'stores/preference_store.jsx';
|
|||||||
|
|
||||||
import ChannelSwitchModal from './channel_switch_modal.jsx';
|
import ChannelSwitchModal from './channel_switch_modal.jsx';
|
||||||
|
|
||||||
import Client from 'client/web_client.jsx';
|
|
||||||
import * as AsyncClient from 'utils/async_client.jsx';
|
|
||||||
import * as Utils from 'utils/utils.jsx';
|
import * as Utils from 'utils/utils.jsx';
|
||||||
import * as ChannelUtils from 'utils/channel_utils.jsx';
|
import * as ChannelUtils from 'utils/channel_utils.jsx';
|
||||||
import * as ChannelActions from 'actions/channel_actions.jsx';
|
import * as ChannelActions from 'actions/channel_actions.jsx';
|
||||||
@@ -37,7 +35,7 @@ import {FormattedMessage} from 'react-intl';
|
|||||||
|
|
||||||
import {Popover, OverlayTrigger} from 'react-bootstrap';
|
import {Popover, OverlayTrigger} from 'react-bootstrap';
|
||||||
|
|
||||||
import {Link, browserHistory} from 'react-router/es6';
|
import {Link} from 'react-router/es6';
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
@@ -111,23 +109,7 @@ export default class Navbar extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleLeave() {
|
handleLeave() {
|
||||||
var channelId = this.state.channel.id;
|
ChannelActions.leaveChannel(this.state.channel.id);
|
||||||
|
|
||||||
Client.leaveChannel(channelId,
|
|
||||||
() => {
|
|
||||||
ChannelActions.loadChannelsForCurrentUser();
|
|
||||||
|
|
||||||
if (this.state.isFavorite) {
|
|
||||||
ChannelActions.unmarkFavorite(channelId);
|
|
||||||
}
|
|
||||||
|
|
||||||
const townsquare = ChannelStore.getByName('town-square');
|
|
||||||
browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/channels/' + townsquare.name);
|
|
||||||
},
|
|
||||||
(err) => {
|
|
||||||
AsyncClient.dispatchError(err, 'handleLeave');
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hideSidebars(e) {
|
hideSidebars(e) {
|
||||||
|
|||||||
@@ -43,6 +43,10 @@ export function isFavoriteChannel(channel) {
|
|||||||
return PreferenceStore.getBool(Preferences.CATEGORY_FAVORITE_CHANNEL, channel.id);
|
return PreferenceStore.getBool(Preferences.CATEGORY_FAVORITE_CHANNEL, channel.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isFavoriteChannelId(channelId) {
|
||||||
|
return PreferenceStore.getBool(Preferences.CATEGORY_FAVORITE_CHANNEL, channelId);
|
||||||
|
}
|
||||||
|
|
||||||
export function isNotDeletedChannel(channel) {
|
export function isNotDeletedChannel(channel) {
|
||||||
return channel.delete_at === 0;
|
return channel.delete_at === 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user