-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User Profile: List component (#98225)
* Add first pass at list component * Fix infinite API calls in UserLists by removing isLoading from useEffect * Initial working commit * Improve styles * Revert unnecessary changes to user stream component and store * Remove unused action types * Add clarifying comments * Revert changes to list items store * Fix typo * Fix type errors and simplify lists connect() * Make the whole lists card a link; fix styles --------- Co-authored-by: Ricardo Artemio Morales <[email protected]> Co-authored-by: DustyReagan <[email protected]>
- Loading branch information
1 parent
94473bd
commit ed3c9fc
Showing
8 changed files
with
158 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,88 @@ | ||
import { formatListBullets, Icon } from '@wordpress/icons'; | ||
import { useTranslate } from 'i18n-calypso'; | ||
import { useEffect, useState } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import EmptyContent from 'calypso/components/empty-content'; | ||
import { UserData } from 'calypso/lib/user/user'; | ||
import { List } from 'calypso/reader/list-manage/types'; | ||
import UserProfileHeader from 'calypso/reader/user-stream/components/user-profile-header'; | ||
import { requestUserLists } from 'calypso/state/reader/lists/actions'; | ||
|
||
interface AppState { | ||
reader: { | ||
lists: { | ||
userLists: Record< string, List[] >; | ||
isRequestingUserLists: Record< string, boolean >; | ||
}; | ||
}; | ||
} | ||
|
||
interface UserListsProps { | ||
user: UserData; | ||
requestUserLists?: ( userSlug: string ) => void; | ||
lists?: List[]; | ||
isLoading?: boolean; | ||
} | ||
|
||
const UserLists = ( { user }: UserListsProps ): JSX.Element => { | ||
const UserLists = ( { user, requestUserLists, lists, isLoading }: UserListsProps ): JSX.Element => { | ||
const translate = useTranslate(); | ||
const [ hasRequested, setHasRequested ] = useState( false ); | ||
const userSlug = user.user_login; | ||
|
||
useEffect( () => { | ||
if ( ! hasRequested && requestUserLists && userSlug ) { | ||
requestUserLists( userSlug ); | ||
setHasRequested( true ); | ||
} | ||
}, [ userSlug, requestUserLists, hasRequested ] ); | ||
|
||
if ( isLoading || ! hasRequested ) { | ||
return <></>; | ||
} | ||
|
||
if ( ! lists || lists.length === 0 ) { | ||
return ( | ||
<div className="user-profile__lists"> | ||
<UserProfileHeader user={ user } /> | ||
<EmptyContent | ||
illustration={ null } | ||
icon={ <Icon icon={ formatListBullets } size={ 48 } /> } | ||
title={ null } | ||
line={ translate( 'No lists yet.' ) } | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="user-stream__lists"> | ||
<div className="user-profile__lists"> | ||
<UserProfileHeader user={ user } /> | ||
<EmptyContent | ||
illustration={ null } | ||
icon={ <Icon icon={ formatListBullets } size={ 48 } /> } | ||
title={ null } | ||
line={ translate( 'No lists yet.' ) } | ||
/> | ||
<div className="user-profile__lists-body"> | ||
{ lists.map( ( list: List ) => ( | ||
<a | ||
className="user-profile__lists-body-link" | ||
href={ `/read/list/${ list.owner }/${ list.slug }` } | ||
key={ list.ID } | ||
> | ||
<div className="card reader-post-card is-compact is-clickable"> | ||
<div className="reader-post-card__post-heading"> | ||
<h2 className="reader-post-card__title">{ list.title }</h2> | ||
</div> | ||
<div className="reader-post-card__post-content">{ list.description }</div> | ||
</div> | ||
</a> | ||
) ) } | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default UserLists; | ||
export default connect( | ||
( state: AppState, ownProps: UserListsProps ) => ( { | ||
lists: state.reader.lists.userLists[ ownProps.user.user_login ?? '' ] ?? [], | ||
isLoading: state.reader.lists.isRequestingUserLists[ ownProps.user.user_login ?? '' ] ?? false, | ||
} ), | ||
{ | ||
requestUserLists, | ||
} | ||
)( UserLists ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters