-
Notifications
You must be signed in to change notification settings - Fork 2k
/
index.jsx
83 lines (72 loc) · 1.97 KB
/
index.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
/**
* External dependencies
*/
import PropTypes from 'prop-types';
import React from 'react';
import { connect } from 'react-redux';
import classNames from 'classnames';
import { localize } from 'i18n-calypso';
import Gridicon from 'calypso/components/gridicon';
/**
* Internal dependencies
*/
import { getNormalizedPost } from 'calypso/state/posts/selectors';
/**
* Style dependencies
*/
import './style.scss';
export function PostStatus( { translate, post, showAll, showIcon = true } ) {
if ( ! post ) {
return null;
}
const { sticky, status } = post;
let text;
let classModifier;
let icon;
if ( sticky ) {
text = translate( 'Sticky' );
classModifier = 'is-sticky';
icon = 'bookmark-outline';
} else if ( 'pending' === status ) {
text = translate( 'Pending Review' );
classModifier = 'is-pending';
icon = 'aside';
} else if ( showAll && 'future' === status ) {
text = translate( 'Scheduled' );
classModifier = 'is-scheduled';
icon = 'calendar';
} else if ( showAll && 'trash' === status ) {
text = translate( 'Trashed' );
classModifier = 'is-trash';
icon = 'trash';
} else if ( showAll && 'draft' === status ) {
text = translate( 'Draft' );
classModifier = 'is-draft';
icon = 'aside';
} else if ( showAll && 'publish' === status ) {
text = translate( 'Published' );
classModifier = 'is-published';
icon = 'aside';
}
if ( ! text ) {
return null;
}
const classes = classNames( 'post-status', classModifier );
return (
<span className={ classes }>
{ showIcon && <Gridicon icon={ icon } size={ 18 } className="post-status__icon" /> }
<span className="post-status__text">{ text }</span>
</span>
);
}
PostStatus.displayName = 'PostStatus';
PostStatus.propTypes = {
globalId: PropTypes.string,
translate: PropTypes.func,
post: PropTypes.object,
showAll: PropTypes.bool,
showIcon: PropTypes.bool,
};
export default connect( ( state, { globalId } ) => ( {
post: getNormalizedPost( state, globalId ),
} ) )( localize( PostStatus ) );