File size: 4,500 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 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 134 135 136 137 138 139 |
import { localize } from 'i18n-calypso';
import { Component } from 'react';
import { connect } from 'react-redux';
import DocumentHead from 'calypso/components/data/document-head';
import QueryReaderList from 'calypso/components/data/query-reader-list';
import { recordAction, recordGaEvent } from 'calypso/reader/stats';
import Stream from 'calypso/reader/stream';
import { getCurrentUser } from 'calypso/state/current-user/selectors';
import { recordReaderTracksEvent } from 'calypso/state/reader/analytics/actions';
import { followList, unfollowList } from 'calypso/state/reader/lists/actions';
import {
getListByOwnerAndSlug,
isSubscribedByOwnerAndSlug,
hasRequestedListByOwnerAndSlug,
isMissingByOwnerAndSlug,
} from 'calypso/state/reader/lists/selectors';
import EmptyContent from './empty';
import ListStreamHeader from './header';
import ListMissing from './missing';
import './style.scss';
const createEmptyContent = ( list ) => {
const EmptyContentWithList = () => <EmptyContent list={ list } />;
EmptyContentWithList.displayName = 'EmptyContentWithList';
return EmptyContentWithList;
};
class ListStream extends Component {
constructor( props ) {
super( props );
this.title = props.translate( 'Loading list' );
}
toggleFollowing = ( isFollowRequested ) => {
const list = this.props.list;
if ( isFollowRequested ) {
this.props.followList( list.owner, list.slug );
} else {
this.props.unfollowList( list.owner, list.slug );
}
recordAction( isFollowRequested ? 'followed_list' : 'unfollowed_list' );
recordGaEvent(
isFollowRequested ? 'Clicked Follow List' : 'Clicked Unfollow List',
list.owner + ':' + list.slug
);
this.props.recordReaderTracksEvent(
isFollowRequested
? 'calypso_reader_reader_list_followed'
: 'calypso_reader_reader_list_unfollowed',
{
list_owner: list.owner,
list_slug: list.slug,
}
);
};
render() {
const list = this.props.list;
const shouldShowFollow = list && ! list.is_owner;
const listStreamIconClasses = 'gridicon gridicon__list';
if ( ! this.props.hasRequested ) {
return <QueryReaderList owner={ this.props.owner } slug={ this.props.slug } />;
}
if ( list ) {
// Show author name in parentheses if the list is owned by someone other than the current user
const isOwnedByCurrentUser =
this.props.currentUser && list.owner === this.props.currentUser.username;
this.title = isOwnedByCurrentUser ? list.title : `${ list.title } (${ list.owner })`;
}
if ( this.props.isMissing ) {
return <ListMissing owner={ this.props.owner } slug={ this.props.slug } />;
}
return (
<Stream
{ ...this.props }
listName={ this.title }
emptyContent={ createEmptyContent( list ) }
showFollowInHeader={ shouldShowFollow }
>
<DocumentHead
title={ this.props.translate( '%s ‹ Reader', {
args: this.title,
comment: '%s is the section name. For example: "My Likes"',
} ) }
/>
<QueryReaderList owner={ this.props.owner } slug={ this.props.slug } />
<ListStreamHeader
isPublic={ list?.is_public }
icon={
<svg
className={ listStreamIconClasses }
height="32"
width="32"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
>
<g>
<path
d="M9 19h10v-2H9v2zm0-6h10v-2H9v2zm0-8v2h10V5H9zm-3-.5c-.828
0-1.5.672-1.5 1.5S5.172 7.5 6 7.5 7.5 6.828 7.5 6 6.828 4.5 6
4.5zm0 6c-.828 0-1.5.672-1.5 1.5s.672 1.5 1.5 1.5 1.5-.672
1.5-1.5-.672-1.5-1.5-1.5zm0 6c-.828 0-1.5.672-1.5 1.5s.672 1.5
1.5 1.5 1.5-.672 1.5-1.5-.672-1.5-1.5-1.5z"
/>
</g>
</svg>
}
title={ this.title }
description={ list?.description }
showFollow={ shouldShowFollow }
following={ this.props.isSubscribed }
onFollowToggle={ this.toggleFollowing }
showEdit={ list && list.is_owner }
editUrl={ window.location.href + '/edit' }
/>
</Stream>
);
}
}
export default connect(
( state, ownProps ) => {
return {
list: getListByOwnerAndSlug( state, ownProps.owner, ownProps.slug ),
isSubscribed: isSubscribedByOwnerAndSlug( state, ownProps.owner, ownProps.slug ),
hasRequested: hasRequestedListByOwnerAndSlug( state, ownProps.owner, ownProps.slug ),
isMissing: isMissingByOwnerAndSlug( state, ownProps.owner, ownProps.slug ),
currentUser: getCurrentUser( state ),
};
},
{ followList, recordReaderTracksEvent, unfollowList }
)( localize( ListStream ) );
|