-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Social: Add Social Share Status modal for published posts (#39051)
* Register meta with name of `jetpack_social_post_shares` * Add new meta to usePostMeta hook * Add bare components with fetching data * changelog * Add moment * Populate the modal * Remove moment and schema as we use store * Improve share retrieval and css * Only order the list * Rebase onto the global modal * Remove leftover file * revert bad change * Fix minification issue * remove external_id from types * Improve normalizeShareStatus --------- Co-authored-by: Manzoor Wani <[email protected]>
- Loading branch information
1 parent
79a7757
commit 48ac019
Showing
13 changed files
with
283 additions
and
41 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
projects/js-packages/publicize-components/changelog/add-social-share-status-shares-modal
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: added | ||
|
||
Add share status log modal to published posts |
29 changes: 0 additions & 29 deletions
29
projects/js-packages/publicize-components/src/components/share-status-modal/index.tsx
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
...cts/js-packages/publicize-components/src/components/share-status-modal/styles.module.scss
This file was deleted.
Oops, something went wrong.
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
38 changes: 38 additions & 0 deletions
38
projects/js-packages/publicize-components/src/components/share-status/share-info.tsx
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { getDate, humanTimeDiff } from '@wordpress/date'; | ||
import ConnectionIcon from '../connection-icon'; | ||
import { ShareStatusAction } from './share-status-action'; | ||
import { ShareStatusLabel } from './share-status-label'; | ||
import styles from './styles.module.scss'; | ||
|
||
/** | ||
* | ||
* ShareInfo component | ||
* | ||
* @param {object} props - component props | ||
* @param {object} props.share - share object | ||
* @return {import('react').ReactNode} - React element | ||
*/ | ||
export function ShareInfo( { share } ) { | ||
const { service, external_name, profile_picture, timestamp, status, message } = share; | ||
|
||
return ( | ||
<div className={ styles[ 'share-item' ] }> | ||
<ConnectionIcon | ||
serviceName={ service } | ||
label={ external_name } | ||
profilePicture={ profile_picture } | ||
/> | ||
<div className={ styles[ 'share-item-name-wrapper' ] }> | ||
<div className={ styles[ 'share-item-name' ] }>{ external_name }</div> | ||
</div> | ||
<div> | ||
{ | ||
// @ts-expect-error - humanTimeDiff is incorrectly typed, first argument can be a timestamp | ||
humanTimeDiff( timestamp * 1000, getDate() ) | ||
} | ||
</div> | ||
<ShareStatusLabel status={ status } message={ message } /> | ||
<ShareStatusAction status={ status } shareLink={ 'success' === status ? message : '' } /> | ||
</div> | ||
); | ||
} |
46 changes: 46 additions & 0 deletions
46
projects/js-packages/publicize-components/src/components/share-status/share-list.tsx
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Spinner } from '@wordpress/components'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { store as editorStore } from '@wordpress/editor'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { store as socialStore } from '../../social-store'; | ||
import { ShareInfo } from './share-info'; | ||
import styles from './styles.module.scss'; | ||
|
||
/** | ||
* ShareList component | ||
* | ||
* @return {import('react').ReactNode} - Share status modal component. | ||
*/ | ||
export function ShareList() { | ||
const { shareStatus } = useSelect( select => { | ||
const store = select( socialStore ); | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- `@wordpress/editor` is a nightmare to work with TypeScript | ||
const _editorStore = select( editorStore ) as any; | ||
|
||
return { | ||
shareStatus: store.getPostShareStatus( _editorStore.getCurrentPostId() ), | ||
}; | ||
}, [] ); | ||
|
||
return ( | ||
<div className="connection-management"> | ||
{ shareStatus.loading && ( | ||
<div className={ styles.spinner }> | ||
<Spinner /> { __( 'Loading…', 'jetpack' ) } | ||
</div> | ||
) } | ||
{ shareStatus.shares.length > 0 && ( | ||
<ul className={ styles[ 'share-log-list' ] }> | ||
{ shareStatus.shares.map( ( share, idx ) => ( | ||
<li | ||
key={ `${ share.external_id || share.connection_id }${ idx }}` } | ||
className={ styles[ 'share-log-list-item' ] } | ||
> | ||
<ShareInfo share={ share } /> | ||
</li> | ||
) ) } | ||
</ul> | ||
) } | ||
</div> | ||
); | ||
} |
26 changes: 26 additions & 0 deletions
26
...ects/js-packages/publicize-components/src/components/share-status/share-status-action.tsx
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { ExternalLink } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import styles from './styles.module.scss'; | ||
|
||
/** | ||
* | ||
* Share status action component. | ||
* | ||
* @param {object} props - component props | ||
* @param {boolean} props.status - status of the share | ||
* @param {string} props.shareLink - link to the share | ||
* @return {import('react').ReactNode} - React element | ||
*/ | ||
export function ShareStatusAction( { status, shareLink } ) { | ||
return ( | ||
<div className={ styles[ 'share-status-action-wrapper' ] }> | ||
{ 'success' !== status ? ( | ||
<span>Retry</span> | ||
) : ( | ||
<ExternalLink className={ styles[ 'profile-link' ] } href={ shareLink }> | ||
{ __( 'View', 'jetpack' ) } | ||
</ExternalLink> | ||
) } | ||
</div> | ||
); | ||
} |
46 changes: 46 additions & 0 deletions
46
projects/js-packages/publicize-components/src/components/share-status/share-status-label.tsx
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { IconTooltip, Text } from '@automattic/jetpack-components'; | ||
import { __, _x } from '@wordpress/i18n'; | ||
import { Icon, check } from '@wordpress/icons'; | ||
import clsx from 'clsx'; | ||
import React from 'react'; | ||
import styles from './styles.module.scss'; | ||
|
||
/** | ||
* | ||
* Share status label component. | ||
* | ||
* @param {object} props - component props | ||
* @param {boolean} props.status - status of the share | ||
* @param {string} props.message - link to the share, or error message if failed | ||
* @return {import('react').ReactNode} - React element | ||
*/ | ||
export function ShareStatusLabel( { status, message } ) { | ||
const isSuccessful = 'success' === status; | ||
|
||
const icon = isSuccessful ? ( | ||
<Icon className={ styles[ 'share-status-icon' ] } icon={ check } /> | ||
) : ( | ||
<IconTooltip | ||
title={ __( 'Sharing failed with the following message:', 'jetpack' ) } | ||
className={ styles[ 'share-status-icon-tooltip' ] } | ||
> | ||
<Text variant="body-small">{ message }</Text> | ||
</IconTooltip> | ||
); | ||
|
||
return ( | ||
<div | ||
className={ clsx( styles[ 'share-status-wrapper' ], { | ||
[ styles[ 'share-status-success' ] ]: isSuccessful, | ||
[ styles[ 'share-status-failure' ] ]: ! isSuccessful, | ||
} ) } | ||
> | ||
<div className={ styles[ 'share-status-icon' ] }>{ icon }</div> | ||
<div className={ styles[ 'share-status-label' ] }> | ||
{ isSuccessful | ||
? _x( 'Shared', 'The sharing is successful', 'jetpack' ) | ||
: __( 'Failed', 'jetpack' ) } | ||
</div> | ||
</div> | ||
); | ||
} |
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
16 changes: 16 additions & 0 deletions
16
projects/js-packages/publicize-components/src/utils/share-status.ts
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { PostShareStatus } from '../social-store/types'; | ||
|
||
/** | ||
* Normalizes the share status object. | ||
* | ||
* @param {PostShareStatus} shareStatus - Share status object. | ||
* @return {PostShareStatus} - Normalized share status object. | ||
*/ | ||
export function normalizeShareStatus( shareStatus: PostShareStatus ) { | ||
if ( shareStatus && 'shares' in shareStatus && shareStatus.done ) { | ||
// Sort shares to show the latest shares on the top. | ||
shareStatus.shares.sort( ( a, b ) => b.timestamp - a.timestamp ); | ||
} | ||
|
||
return shareStatus; | ||
} |
4 changes: 4 additions & 0 deletions
4
projects/packages/publicize/changelog/add-social-share-status-shares-modal
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: added | ||
|
||
Add share status log modal to published posts |
4 changes: 4 additions & 0 deletions
4
projects/packages/sync/changelog/add-social-share-status-shares-modal
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: added | ||
|
||
Add share status log modal to published posts |