-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.tsx
127 lines (105 loc) · 3.92 KB
/
index.tsx
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import React from 'react';
import { RootState } from '../../../store/reducer';
import { connectContainer } from '../../../store/redux-container';
import { PostPayload as PayloadPostMessage } from '../../../store/posts/saga';
import { Channel } from '../../../store/channels';
import { sendPost } from '../../../store/posts';
import { ConversationHeaderContainer as ConversationHeader } from '../conversation-header/container';
import { LeaveGroupDialogContainer } from '../../group-management/leave-group-dialog/container';
import { LeaveGroupDialogStatus, setLeaveGroupStatus } from '../../../store/group-management';
import { Switch, Route } from 'react-router-dom';
import { denormalizedChannelSelector } from '../../../store/channels/selectors';
import { bemClassName } from '../../../lib/bem';
import './styles.scss';
// should move this to a shared location
import { Media } from '../../message-input/utils';
import { PostView } from '../../../apps/feed/components/post-view-container';
import { MainFeed } from '../../../apps/feed/components/main-feed';
const cn = bemClassName('messenger-feed');
export interface PublicProperties {}
export interface Properties extends PublicProperties {
channel: Channel;
activeConversationId: string;
isSocialChannel: boolean;
isJoiningConversation: boolean;
leaveGroupDialogStatus: LeaveGroupDialogStatus;
isSubmittingPost: boolean;
sendPost: (payload: PayloadPostMessage) => void;
setLeaveGroupStatus: (status: LeaveGroupDialogStatus) => void;
}
export class Container extends React.Component<Properties> {
static mapState(state: RootState): Partial<Properties> {
const {
chat: { activeConversationId, isJoiningConversation },
groupManagement,
posts,
} = state;
const currentChannel = denormalizedChannelSelector(state, activeConversationId) || null;
return {
channel: currentChannel,
isJoiningConversation,
activeConversationId,
isSubmittingPost: posts?.isSubmitting,
leaveGroupDialogStatus: groupManagement.leaveGroupDialogStatus,
isSocialChannel: currentChannel?.isSocialChannel,
};
}
static mapActions(): Partial<Properties> {
return {
sendPost: sendPost,
setLeaveGroupStatus,
};
}
submitPost = (message: string, media: Media[] = []) => {
const { activeConversationId } = this.props;
let payloadPostMessage = {
channelId: activeConversationId,
message: message,
files: media,
};
this.props.sendPost(payloadPostMessage);
};
get isSubmitting() {
return this.props.isSubmittingPost;
}
get isLeaveGroupDialogOpen() {
return this.props.leaveGroupDialogStatus !== LeaveGroupDialogStatus.CLOSED;
}
closeLeaveGroupDialog = () => {
this.props.setLeaveGroupStatus(LeaveGroupDialogStatus.CLOSED);
};
renderLeaveGroupDialog = (): JSX.Element => {
return (
<LeaveGroupDialogContainer
groupName={this.props.channel.name}
onClose={this.closeLeaveGroupDialog}
roomId={this.props.activeConversationId}
/>
);
};
render() {
const { isJoiningConversation, activeConversationId, isSocialChannel } = this.props;
if (!activeConversationId || !isSocialChannel || isJoiningConversation) {
return null;
}
return (
<div {...cn('')}>
<div {...cn('header-position', !this.props.channel?.hasLoadedMessages && 'message-loading')}>
<div {...cn('header')}>
<ConversationHeader />
</div>
</div>
<Switch>
<Route
path='/conversation/:conversationId/:postId'
exact
render={(props) => <PostView postId={props.match.params.postId} />}
/>
<Route path='/conversation/:conversationId' exact component={MainFeed} />
</Switch>
{this.isLeaveGroupDialogOpen && this.renderLeaveGroupDialog()}
</div>
);
}
}
export const MessengerFeed = connectContainer<PublicProperties>(Container);