Use mattermost-redux favorite and unfavorite actions (#921)
This commit is contained in:
parent
2f631ef726
commit
59762e4fac
4 changed files with 18 additions and 46 deletions
|
|
@ -10,11 +10,12 @@ import {
|
|||
fetchMyChannelsAndMembers,
|
||||
getChannelStats,
|
||||
selectChannel,
|
||||
leaveChannel as serviceLeaveChannel
|
||||
leaveChannel as serviceLeaveChannel,
|
||||
unfavoriteChannel
|
||||
} from 'mattermost-redux/actions/channels';
|
||||
import {getPosts, getPostsWithRetry, getPostsBefore, getPostsSinceWithRetry, getPostThread} from 'mattermost-redux/actions/posts';
|
||||
import {getFilesForPost} from 'mattermost-redux/actions/files';
|
||||
import {savePreferences, deletePreferences} from 'mattermost-redux/actions/preferences';
|
||||
import {savePreferences} from 'mattermost-redux/actions/preferences';
|
||||
import {getTeamMembersByIds} from 'mattermost-redux/actions/teams';
|
||||
import {getProfilesInChannel} from 'mattermost-redux/actions/users';
|
||||
import {General, Preferences} from 'mattermost-redux/constants';
|
||||
|
|
@ -276,7 +277,7 @@ export function closeDMChannel(channel) {
|
|||
const state = getState();
|
||||
|
||||
if (channel.isFavorite) {
|
||||
unmarkFavorite(channel.id)(dispatch, getState);
|
||||
unfavoriteChannel(channel.id)(dispatch, getState);
|
||||
}
|
||||
|
||||
toggleDMChannel(channel.teammate_id, 'false')(dispatch, getState);
|
||||
|
|
@ -291,7 +292,7 @@ export function closeGMChannel(channel) {
|
|||
const state = getState();
|
||||
|
||||
if (channel.isFavorite) {
|
||||
unmarkFavorite(channel.id)(dispatch, getState);
|
||||
unfavoriteChannel(channel.id)(dispatch, getState);
|
||||
}
|
||||
|
||||
toggleGMChannel(channel.id, 'false')(dispatch, getState);
|
||||
|
|
@ -301,33 +302,6 @@ export function closeGMChannel(channel) {
|
|||
};
|
||||
}
|
||||
|
||||
export function markFavorite(channelId) {
|
||||
return async (dispatch, getState) => {
|
||||
const {currentUserId} = getState().entities.users;
|
||||
const fav = [{
|
||||
user_id: currentUserId,
|
||||
category: Preferences.CATEGORY_FAVORITE_CHANNEL,
|
||||
name: channelId,
|
||||
value: 'true'
|
||||
}];
|
||||
|
||||
savePreferences(currentUserId, fav)(dispatch, getState);
|
||||
};
|
||||
}
|
||||
|
||||
export function unmarkFavorite(channelId) {
|
||||
return async (dispatch, getState) => {
|
||||
const {currentUserId} = getState().entities.users;
|
||||
const fav = [{
|
||||
user_id: currentUserId,
|
||||
category: Preferences.CATEGORY_FAVORITE_CHANNEL,
|
||||
name: channelId
|
||||
}];
|
||||
|
||||
deletePreferences(currentUserId, fav)(dispatch, getState);
|
||||
};
|
||||
}
|
||||
|
||||
export function refreshChannelWithRetry(channelId) {
|
||||
return (dispatch, getState) => {
|
||||
getPostsWithRetry(channelId)(dispatch, getState);
|
||||
|
|
|
|||
|
|
@ -41,8 +41,8 @@ class ChannelInfo extends PureComponent {
|
|||
deleteChannel: PropTypes.func.isRequired,
|
||||
getChannelStats: PropTypes.func.isRequired,
|
||||
leaveChannel: PropTypes.func.isRequired,
|
||||
markFavorite: PropTypes.func.isRequired,
|
||||
unmarkFavorite: PropTypes.func.isRequired
|
||||
favoriteChannel: PropTypes.func.isRequired,
|
||||
unfavoriteChannel: PropTypes.func.isRequired
|
||||
})
|
||||
};
|
||||
|
||||
|
|
@ -194,8 +194,8 @@ class ChannelInfo extends PureComponent {
|
|||
|
||||
handleFavorite = () => {
|
||||
const {isFavorite, actions, currentChannel} = this.props;
|
||||
const {markFavorite, unmarkFavorite} = actions;
|
||||
const toggleFavorite = isFavorite ? unmarkFavorite : markFavorite;
|
||||
const {favoriteChannel, unfavoriteChannel} = actions;
|
||||
const toggleFavorite = isFavorite ? unfavoriteChannel : favoriteChannel;
|
||||
this.setState({isFavorite: !isFavorite});
|
||||
toggleFavorite(currentChannel.id);
|
||||
};
|
||||
|
|
@ -206,7 +206,7 @@ class ChannelInfo extends PureComponent {
|
|||
const isGroupMessage = channel.type === General.GM_CHANNEL;
|
||||
|
||||
return !isDirectMessage && !isGroupMessage;
|
||||
}
|
||||
};
|
||||
|
||||
renderLeaveOrDeleteChannelRow = () => {
|
||||
const channel = this.props.currentChannel;
|
||||
|
|
@ -215,7 +215,7 @@ class ChannelInfo extends PureComponent {
|
|||
const isGroupMessage = channel.type === General.GM_CHANNEL;
|
||||
|
||||
return !isDefaultChannel && !isDirectMessage && !isGroupMessage;
|
||||
}
|
||||
};
|
||||
|
||||
renderCloseDirect = () => {
|
||||
const channel = this.props.currentChannel;
|
||||
|
|
@ -223,7 +223,7 @@ class ChannelInfo extends PureComponent {
|
|||
const isGroupMessage = channel.type === General.GM_CHANNEL;
|
||||
|
||||
return isDirectMessage || isGroupMessage;
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
const {
|
||||
|
|
|
|||
|
|
@ -7,13 +7,11 @@ import {connect} from 'react-redux';
|
|||
import {
|
||||
closeDMChannel,
|
||||
closeGMChannel,
|
||||
leaveChannel,
|
||||
markFavorite,
|
||||
unmarkFavorite
|
||||
leaveChannel
|
||||
} from 'app/actions/views/channel';
|
||||
import {getTheme} from 'app/selectors/preferences';
|
||||
|
||||
import {getChannelStats, deleteChannel} from 'mattermost-redux/actions/channels';
|
||||
import {favoriteChannel, getChannelStats, deleteChannel, unfavoriteChannel} from 'mattermost-redux/actions/channels';
|
||||
import {General} from 'mattermost-redux/constants';
|
||||
import {
|
||||
getCurrentChannel,
|
||||
|
|
@ -69,8 +67,8 @@ function mapDispatchToProps(dispatch) {
|
|||
deleteChannel,
|
||||
getChannelStats,
|
||||
leaveChannel,
|
||||
markFavorite,
|
||||
unmarkFavorite
|
||||
favoriteChannel,
|
||||
unfavoriteChannel
|
||||
}, dispatch)
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3878,7 +3878,7 @@ makeerror@1.0.x:
|
|||
|
||||
mattermost-redux@mattermost/mattermost-redux#master:
|
||||
version "0.0.1"
|
||||
resolved "https://codeload.github.com/mattermost/mattermost-redux/tar.gz/b09a04337301c1a3cbe8a5a7e726e305a9af4f41"
|
||||
resolved "https://codeload.github.com/mattermost/mattermost-redux/tar.gz/c6115b3cfa934ed97a60a10727fa487df39a4043"
|
||||
dependencies:
|
||||
deep-equal "1.0.1"
|
||||
harmony-reflect "1.5.1"
|
||||
|
|
@ -5249,7 +5249,7 @@ redux-devtools-instrument@^1.3.3:
|
|||
symbol-observable "^1.0.2"
|
||||
|
||||
"redux-offline@git+https://github.com/enahum/redux-offline.git":
|
||||
version "1.1.4"
|
||||
version "1.1.5"
|
||||
resolved "git+https://github.com/enahum/redux-offline.git#4bd85e7e3b279a2b11fb4d587808d583d2b5e7b5"
|
||||
dependencies:
|
||||
redux-persist "^4.5.0"
|
||||
|
|
|
|||
Loading…
Reference in a new issue