Skip to content

Commit

Permalink
Fix type errors and simplify lists connect()
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardo Artemio Morales committed Jan 13, 2025
1 parent eb0f789 commit 8888f2a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
1 change: 1 addition & 0 deletions client/lib/user/user.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export type OptionalUserData = {
has_jetpack_partner_access?: boolean;
jetpack_partner_types?: string[];
social_login_connections: unknown;
user_login: string;
user_ip_country_code: string;
user_URL: string;
username: string;
Expand Down
2 changes: 1 addition & 1 deletion client/reader/user-stream/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function UserStream( { userId, requestUser, user, streamKey, isLoading }:
case `/read/users/${ userId }`:
return <UserPosts streamKey={ streamKey as string } user={ user } />;
case `/read/users/${ userId }/lists`:
return <UserLists user={ user } userSlug={ user.user_login } />;
return <UserLists user={ user } />;
default:
return null;
}
Expand Down
29 changes: 10 additions & 19 deletions client/reader/user-stream/views/lists.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,18 @@ interface AppState {

interface UserListsProps {
user: UserData;
userId: string;
userSlug: string;
lists: List[];
isLoading: boolean;
requestUserLists: ( userSlug: string ) => void;
requestUserLists?: ( userSlug: string ) => void;
lists?: List[];
isLoading?: boolean;
}

const UserLists = ( {
user,
userSlug,
lists,
isLoading,
requestUserLists,
}: 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 ) {
if ( ! hasRequested && requestUserLists && userSlug ) {
requestUserLists( userSlug );
setHasRequested( true );
}
Expand Down Expand Up @@ -86,12 +79,10 @@ const UserLists = ( {
};

export default connect(
( state: AppState, ownProps: UserListsProps ) => {
return {
lists: state.reader.lists.userLists[ ownProps.userSlug ] ?? [],
isLoading: state.reader.lists.isRequestingUserLists[ ownProps.userSlug ] ?? false,
};
},
( state: AppState, ownProps: UserListsProps ) => ( {
lists: state.reader.lists.userLists[ ownProps.user.user_login ?? '' ] ?? [],
isLoading: state.reader.lists.isRequestingUserLists[ ownProps.user.user_login ?? '' ] ?? false,
} ),
{
requestUserLists,
}
Expand Down

0 comments on commit 8888f2a

Please sign in to comment.