This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
index.js
84 lines (72 loc) · 3.22 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {createSelector} from 'reselect';
import {getInt} from 'mattermost-redux/selectors/entities/preferences';
import {getCurrentChannel} from 'mattermost-redux/selectors/entities/channels';
import {getMyChannelRoles} from 'mattermost-redux/selectors/entities/roles';
import {getRoles} from 'mattermost-redux/selectors/entities/roles_helpers';
import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users';
import {getConfig, getLicense} from 'mattermost-redux/selectors/entities/general';
import {withRouter} from 'react-router-dom';
import {getProfiles} from 'mattermost-redux/actions/users';
import {getDirectTeammate} from 'utils/utils.jsx';
import {TutorialSteps, Preferences} from 'utils/constants';
import {goToLastViewedChannel} from 'actions/views/channel';
import {setShowNextStepsView} from 'actions/views/next_steps';
import {isOnboardingHidden, showNextSteps, showNextStepsTips} from 'components/next_steps_view/steps';
import ChannelView from './channel_view.jsx';
// Temporary selector until getDirectTeammate is converted to be redux-friendly
const getDeactivatedChannel = createSelector(
(state, channelId) => {
return getDirectTeammate(state, channelId);
},
(teammate) => {
return Boolean(teammate && teammate.delete_at);
},
);
function mapStateToProps(state) {
const channel = getCurrentChannel(state);
const config = getConfig(state);
const enableTutorial = config.EnableTutorial === 'true';
const tutorialStep = getInt(state, Preferences.TUTORIAL_STEP, getCurrentUserId(state), TutorialSteps.FINISHED);
const viewArchivedChannels = config.ExperimentalViewArchivedChannels === 'true';
let channelRolesLoading = true;
if (channel && channel.id) {
const roles = getRoles(state);
const myChannelRoles = getMyChannelRoles(state);
if (myChannelRoles[channel.id]) {
const channelRoles = myChannelRoles[channel.id].values();
for (const roleName of channelRoles) {
if (roles[roleName]) {
channelRolesLoading = false;
}
break;
}
}
}
return {
channelId: channel ? channel.id : '',
channelRolesLoading,
deactivatedChannel: channel ? getDeactivatedChannel(state, channel.id) : false,
showTutorial: enableTutorial && tutorialStep <= TutorialSteps.INTRO_SCREENS,
showNextSteps: showNextSteps(state),
showNextStepsTips: showNextStepsTips(state),
isOnboardingHidden: isOnboardingHidden(state),
showNextStepsEphemeral: state.views.nextSteps.show,
channelIsArchived: channel ? channel.delete_at !== 0 : false,
viewArchivedChannels,
isCloud: getLicense(state).Cloud === 'true',
};
}
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators({
setShowNextStepsView,
goToLastViewedChannel,
getProfiles,
}, dispatch),
};
}
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(ChannelView));