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
/
post_time.jsx
73 lines (61 loc) · 1.84 KB
/
post_time.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
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import PropTypes from 'prop-types';
import React from 'react';
import {Link} from 'react-router-dom';
import * as GlobalActions from 'actions/global_actions.jsx';
import {isMobile} from 'utils/user_agent.jsx';
import {isMobile as isMobileView} from 'utils/utils.jsx';
import LocalDateTime from 'components/local_date_time';
export default class PostTime extends React.PureComponent {
static propTypes = {
/*
* If true, time will be rendered as a permalink to the post
*/
isPermalink: PropTypes.bool.isRequired,
/*
* The time to display
*/
eventTime: PropTypes.number.isRequired,
location: PropTypes.oneOf(['CENTER', 'RHS_ROOT', 'RHS_COMMENT', 'SEARCH']).isRequired,
/*
* The post id of posting being rendered
*/
postId: PropTypes.string,
teamUrl: PropTypes.string,
};
static defaultProps = {
eventTime: 0,
location: 'CENTER',
};
handleClick = () => {
if (isMobileView()) {
GlobalActions.emitCloseRightHandSide();
}
};
render() {
const localDateTime = (
<LocalDateTime
eventTime={this.props.eventTime}
/>
);
if (isMobile() || !this.props.isPermalink) {
return localDateTime;
}
const {
location,
postId,
teamUrl,
} = this.props;
return (
<Link
id={`${location}_time_${postId}`}
to={`${teamUrl}/pl/${postId}`}
className='post__permalink'
onClick={this.handleClick}
>
{localDateTime}
</Link>
);
}
}