-
Notifications
You must be signed in to change notification settings - Fork 2k
/
index.jsx
133 lines (119 loc) · 3.7 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
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
128
129
130
131
132
133
/**
* External dependencies
*/
import React from 'react';
import classNames from 'classnames';
/**
* Internal dependencies
*/
import Item from './item';
import Publish from './publish';
import Notifications from './notifications';
import Gravatar from 'components/gravatar';
import layoutFocus from 'lib/layout-focus';
import config from 'config';
export default React.createClass( {
displayName: 'Masterbar',
propTypes: {
user: React.PropTypes.object,
sites: React.PropTypes.object,
section: React.PropTypes.oneOfType( [ React.PropTypes.string, React.PropTypes.bool ] ),
},
getInitialState() {
return {
// whether we show the notifications panel
showNotifications: false,
};
},
clickMySites() {
layoutFocus.setNext( 'sidebar' );
},
clickReader() {
layoutFocus.setNext( 'content' );
},
clickNotifications() {
this.setState( {
showNotifications: ! this.state.showNotifications
} );
},
isActive( section ) {
return section === this.props.section && ! this.state.showNotifications;
},
wordpressIcon() {
// WP icon replacement for "horizon" environment
if ( config( 'hostname' ) === 'horizon.wordpress.com' ) {
return 'my-sites-horizon';
}
return 'my-sites';
},
render() {
const classes = classNames( 'masterbar', {
collapsible: !! this.props.user,
} );
if ( this.props.user ) { // Logged in
return (
<header id="header" className={ classes }>
<Item
url="/stats"
icon={ this.wordpressIcon() }
onClick={ this.clickMySites }
isActive={ this.isActive( 'sites' ) }
tooltip={ this.translate( 'View a list of your sites and access their dashboards', { textOnly: true } ) }
>
{ this.props.user.get().visible_site_count > 1
? this.translate( 'My Sites', { comment: 'Toolbar, must be shorter than ~12 chars' } )
: this.translate( 'My Site', { comment: 'Toolbar, must be shorter than ~12 chars' } )
}
</Item>
<Item
url="/"
icon="reader"
onClick={ this.clickReader }
isActive={ this.isActive( 'reader' ) }
tooltip={ this.translate( 'Read the blogs and topics you follow', { textOnly: true } ) }
>
{ this.translate( 'Reader', { comment: 'Toolbar, must be shorter than ~12 chars' } ) }
</Item>
<Publish
sites={ this.props.sites }
user={ this.props.user }
isActive={ this.isActive( 'post' ) }
className="masterbar__item-new"
tooltip={ this.translate( 'Create a New Post', { textOnly: true } ) }
>
{ this.translate( 'New Post' ) }
</Publish>
<Item
url="/me"
icon="user-circle"
isActive={ this.isActive( 'me' ) }
className="masterbar__item-me"
tooltip={ this.translate( 'Update your profile, personal settings, and more', { textOnly: true } ) }
>
<Gravatar user={ this.props.user.get() } alt="Me" size={ 18 } />
<span className="masterbar__item-me-label">
{ this.translate( 'Me', { context: 'Toolbar, must be shorter than ~12 chars' } ) }
</span>
</Item>
<Notifications
user={ this.props.user }
onClick={ this.clickNotifications }
isActive={ this.isActive( 'notifications' ) }
className="masterbar__item-notifications"
tooltip={ this.translate( 'Manage your notifications', { textOnly: true } ) }
>
<span className="masterbar__item-notifications-label">{ this.translate( 'Notifications', { comment: 'Toolbar, must be shorter than ~12 chars' } ) }</span>
</Notifications>
</header>
);
}
// Logged out
return (
<header id="header" className={ classes }>
<Item url="/" icon="my-sites" className="masterbar__item-logo">
WordPress<span className="tld">.com</span>
</Item>
</header>
);
}
} );