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.ts
72 lines (60 loc) · 2.9 KB
/
index.ts
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
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {connect} from 'react-redux';
import {ActionCreatorsMapObject, bindActionCreators, Dispatch} from 'redux';
import {createSelector} from 'reselect';
import {RequestStatus} from 'mattermost-redux/constants';
import {Channel} from 'mattermost-redux/types/channels';
import {getConfig} from 'mattermost-redux/selectors/entities/general';
import {ActionFunc, ActionResult} from 'mattermost-redux/types/actions';
import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams';
import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users';
import {getChannels, getArchivedChannels, joinChannel} from 'mattermost-redux/actions/channels';
import {getOtherChannels, getChannelsInCurrentTeam} from 'mattermost-redux/selectors/entities/channels';
import {searchMoreChannels} from 'actions/channel_actions.jsx';
import {openModal, closeModal} from 'actions/views/modals';
import {GlobalState} from '../../types/store';
import MoreChannels from './more_channels';
const getNotArchivedOtherChannels = createSelector(
getOtherChannels,
(channels: Channel[]) => channels && channels.filter((c) => c.delete_at === 0),
);
const getArchivedOtherChannels = createSelector(
getChannelsInCurrentTeam,
(channels: Channel[]) => channels && channels.filter((c) => c.delete_at !== 0),
);
function mapStateToProps(state: GlobalState) {
const team = getCurrentTeam(state) || {};
return {
channels: getNotArchivedOtherChannels(state) || [],
archivedChannels: getArchivedOtherChannels(state) || [],
currentUserId: getCurrentUserId(state),
teamId: team.id,
teamName: team.name,
channelsRequestStarted: state.requests.channels.getChannels.status === RequestStatus.STARTED,
canShowArchivedChannels: (getConfig(state).ExperimentalViewArchivedChannels === 'true'),
};
}
type Actions = {
getChannels: (teamId: string, page: number, perPage: number) => ActionFunc | void;
getArchivedChannels: (teamId: string, page: number, channelsPerPage: number) => ActionFunc | void;
joinChannel: (currentUserId: string, teamId: string, channelId: string) => Promise<ActionResult>;
searchMoreChannels: (term: string, shouldShowArchivedChannels: boolean) => Promise<ActionResult>;
openModal: (modalData: {modalId: string; dialogType: any; dialogProps?: any}) => Promise<{
data: boolean;
}>;
closeModal: (modalId: string) => void;
}
function mapDispatchToProps(dispatch: Dispatch) {
return {
actions: bindActionCreators<ActionCreatorsMapObject<ActionFunc>, Actions>({
getChannels,
getArchivedChannels,
joinChannel,
searchMoreChannels,
openModal,
closeModal,
}, dispatch),
};
}
export default connect(mapStateToProps, mapDispatchToProps)(MoreChannels);