File size: 1,105 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import PropTypes from 'prop-types';
import { PureComponent } from 'react';
import Connection from './connection';

class ConnectionsList extends PureComponent {
	static propTypes = {
		connections: PropTypes.array,
		onToggle: PropTypes.func,
		siteId: PropTypes.number,
		siteSlug: PropTypes.string,
	};

	static defaultProps = {
		connections: [],
	};

	renderEmptyPlaceholder() {
		return (
			<div className="post-share__main">
				<div className="post-share__form is-placeholder" />
				<div className="post-share__services is-placeholder" />
			</div>
		);
	}

	render() {
		const { connections, onToggle, siteId } = this.props;

		if ( ! siteId || ! connections.length ) {
			return null;
		}

		if ( ! this.props.hasFetchedConnections ) {
			return this.renderEmptyPlaceholder();
		}

		return (
			<div className="post-share__connections">
				{ connections.map( ( connection ) => (
					<Connection
						key={ connection.ID }
						{ ...{
							connection,
							onToggle,
							isActive: connection.isActive,
						} }
					/>
				) ) }
			</div>
		);
	}
}

export default ConnectionsList;