-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathexample.jsx
46 lines (40 loc) · 1.23 KB
/
example.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
/**
* External dependencies
*/
import React from 'react';
import { connect } from 'react-redux';
import { get } from 'lodash';
/**
* Internal dependencies
*/
import QueryPosts from 'components/data/query-posts';
import QuerySites from 'components/data/query-sites';
import PostItem from '../';
import { getCurrentUser } from 'state/current-user/selectors';
import { getSitePosts } from 'state/posts/selectors';
function PostItemExample( { primarySiteId, globalId } ) {
return (
<div className="docs__design-assets-group">
<h2>
<a href="/devdocs/blocks/post-item">Post Item</a>
</h2>
{ primarySiteId && <QuerySites siteId={ primarySiteId } /> }
{ primarySiteId && (
<QueryPosts
siteId={ primarySiteId }
query={ { number: 1, type: 'any' } } />
) }
{ ! globalId && <em>No posts found</em> }
{ globalId && <PostItem globalId={ globalId } /> }
</div>
);
}
const ConnectedPostItemExample = connect( ( state ) => {
const primarySiteId = get( getCurrentUser( state ), 'primary_blog' );
return {
primarySiteId,
globalId: get( getSitePosts( state, primarySiteId ), [ 0, 'global_ID' ] )
};
} )( PostItemExample );
ConnectedPostItemExample.displayName = 'PostItem';
export default ConnectedPostItemExample;