forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
permalink_view.jsx
99 lines (86 loc) · 2.79 KB
/
permalink_view.jsx
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
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import React from 'react';
import PropTypes from 'prop-types';
import {FormattedMessage} from 'react-intl';
import {Link} from 'react-router-dom';
import ChannelHeader from 'components/channel_header';
import PostView from 'components/post_view';
import {emitPostFocusEvent} from 'actions/global_actions.jsx';
export default class PermalinkView extends React.PureComponent {
static propTypes = {
channelId: PropTypes.string,
channelName: PropTypes.string,
/*
* Object from react-router
*/
match: PropTypes.shape({
params: PropTypes.shape({
postid: PropTypes.string.isRequired,
}).isRequired,
}).isRequired,
returnTo: PropTypes.string.isRequired,
teamName: PropTypes.string,
};
constructor(props) {
super(props);
this.state = {valid: false};
}
componentDidMount() {
this.doPermalinkEvent(this.props);
document.body.classList.add('app__body');
}
componentWillUnmount() {
document.body.classList.remove('app__body');
}
componentWillReceiveProps(nextProps) {
if (this.props.match.params.postid !== nextProps.match.params.postid) {
this.doPermalinkEvent(nextProps);
}
}
doPermalinkEvent = async (props) => {
this.setState({valid: false});
const postId = props.match.params.postid;
await emitPostFocusEvent(postId, this.props.returnTo);
this.setState({valid: true});
}
isStateValid = () => {
return this.state.valid && this.props.channelId && this.props.teamName;
}
render() {
const {
channelId,
channelName,
match,
teamName,
} = this.props;
if (!this.isStateValid()) {
return null;
}
return (
<div
id='app-content'
className='app__content'
>
<ChannelHeader
channelId={channelId}
/>
<PostView
channelId={channelId}
focusedPostId={match.params.postid}
/>
<div id='archive-link-home'>
<Link
to={'/' + teamName + '/channels/' + channelName}
>
<FormattedMessage
id='center_panel.recent'
defaultMessage='Click here to jump to recent messages. '
/>
<i className='fa fa-arrow-down'/>
</Link>
</div>
</div>
);
}
}