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 = () => ; 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 ; } 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 ; } return ( } 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' } /> ); } } 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 ) );