Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Improve normalizeShareStatus
  • Loading branch information
manzoorwanijk committed Aug 28, 2024
commit 3c5e98711d17f59d49a03e8cc8e61b402c7a4d42
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { PostShareStatus } from '../social-store/types';

/**
* Normalizes the share status object.
*
* @param {import( './types' ).PostShareStatus} shareStatus - Share status object.
* @return {import( './types' ).PostShareStatus | undefined} - Normalized share status object.
* @param {PostShareStatus} shareStatus - Share status object.
* @return {PostShareStatus} - Normalized share status object.
*/
export function normalizeShareStatus( shareStatus ) {
if ( ! shareStatus || ! ( 'shares' in shareStatus ) || ! shareStatus.done ) {
return;
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 );
}
// Sort shares to show the latest shares on the top.
shareStatus.shares.sort( ( a, b ) => b.timestamp - a.timestamp );

return shareStatus;
}