From f285d759e4ee80da3fb3e845fab3e730cc8ef3ec Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Tue, 1 Oct 2024 10:53:47 -0500 Subject: [PATCH] Cleanups --- src/view/com/notifications/FeedItem.tsx | 309 +++++++++++------------- 1 file changed, 139 insertions(+), 170 deletions(-) diff --git a/src/view/com/notifications/FeedItem.tsx b/src/view/com/notifications/FeedItem.tsx index 53e3561fab..c773c01da6 100644 --- a/src/view/com/notifications/FeedItem.tsx +++ b/src/view/com/notifications/FeedItem.tsx @@ -170,19 +170,16 @@ let FeedItem = ({ ) } - const formattedCount = - authors.length > 1 ? formatCount(i18n, authors.length - 1) : '' - const firstAuthorName = sanitizeDisplayName( - authors[0].profile.displayName || authors[0].profile.handle, - ) const niceTimestamp = niceDate(i18n, item.notification.indexedAt) - - let a11yAuthor = firstAuthorName - let author = ( + const firstAuthor = authors[0] + const firstAuthorName = sanitizeDisplayName( + firstAuthor.profile.displayName || firstAuthor.profile.handle, + ) + const firstAuthorLink = ( {forceLTR(firstAuthorName)} @@ -191,9 +188,14 @@ let FeedItem = ({ disableMismatchWarning /> ) + const additionalAuthorsCount = authors.length - 1 + const hasMultipleAuthors = additionalAuthorsCount > 0 + const formattedAuthorsCount = hasMultipleAuthors + ? formatCount(i18n, additionalAuthorsCount) + : '' let a11yLabel = '' - let action: ReactElement + let notificationContent: ReactElement let icon = ( 1 - ? _( - msg`${a11yAuthor} and ${plural(authors.length - 1, { - one: `${formattedCount} other`, - other: `${formattedCount} others`, - })} liked your post`, - ) - : _(msg`${a11yAuthor} liked your post`) - action = - authors.length > 1 ? ( - - {author} and{' '} - - - {' '} - liked your post - - ) : ( - {author} liked your post - ) + a11yLabel = hasMultipleAuthors + ? _( + msg`${firstAuthorName} and ${plural(additionalAuthorsCount, { + one: `${formattedAuthorsCount} other`, + other: `${formattedAuthorsCount} others`, + })} liked your post`, + ) + : _(msg`${firstAuthorName} liked your post`) + notificationContent = hasMultipleAuthors ? ( + + {firstAuthorLink} and{' '} + + + {' '} + liked your post + + ) : ( + {firstAuthorLink} liked your post + ) } else if (item.type === 'repost') { - a11yLabel = - authors.length > 1 - ? _( - msg`${a11yAuthor} and ${plural(authors.length - 1, { - one: `${formattedCount} other`, - other: `${formattedCount} others`, - })} reposted your post`, - ) - : _(msg`${a11yAuthor} reposted your post`) - action = - authors.length > 1 ? ( - - {author} and{' '} - - - {' '} - reposted your post - - ) : ( - {author} reposted your post - ) + a11yLabel = hasMultipleAuthors + ? _( + msg`${firstAuthorName} and ${plural(additionalAuthorsCount, { + one: `${formattedAuthorsCount} other`, + other: `${formattedAuthorsCount} others`, + })} reposted your post`, + ) + : _(msg`${firstAuthorName} reposted your post`) + notificationContent = hasMultipleAuthors ? ( + + {firstAuthorLink} and{' '} + + + {' '} + reposted your post + + ) : ( + {firstAuthorLink} reposted your post + ) icon = } else if (item.type === 'follow') { let isFollowBack = false @@ -279,112 +277,87 @@ let FeedItem = ({ } } - if (isFollowBack) { - a11yLabel = - authors.length > 1 - ? _( - msg`${a11yAuthor} and ${plural(authors.length - 1, { - one: `${formattedCount} other`, - other: `${formattedCount} others`, - })} followed you back`, - ) - : _(msg`${a11yAuthor} followed you back`) - action = - authors.length > 1 ? ( - - {author} and{' '} - - - {' '} - followed you back - - ) : ( - {author} followed you back - ) + if (isFollowBack && !hasMultipleAuthors) { + /* + * Follow-backs are ungrouped, grouped follow-backs not supported atm, + * see `src/state/queries/notifications/util.ts` + */ + a11yLabel = _(msg`${firstAuthorName} followed you back`) + notificationContent = {firstAuthorLink} followed you back } else { - a11yLabel = - authors.length > 1 - ? _( - msg`${a11yAuthor} and ${plural(authors.length - 1, { - one: `${formattedCount} other`, - other: `${formattedCount} others`, - })} followed you`, - ) - : _(msg`${a11yAuthor} followed you`) - action = - authors.length > 1 ? ( - - {author} and{' '} - - - {' '} - followed you - - ) : ( - {author} followed you - ) + a11yLabel = hasMultipleAuthors + ? _( + msg`${firstAuthorName} and ${plural(additionalAuthorsCount, { + one: `${formattedAuthorsCount} other`, + other: `${formattedAuthorsCount} others`, + })} followed you`, + ) + : _(msg`${firstAuthorName} followed you`) + notificationContent = hasMultipleAuthors ? ( + + {firstAuthorLink} and{' '} + + + {' '} + followed you + + ) : ( + {firstAuthorLink} followed you + ) } icon = } else if (item.type === 'feedgen-like') { - a11yLabel = - authors.length > 1 - ? _( - msg`${a11yAuthor} and ${plural(authors.length - 1, { - one: `${formattedCount} other`, - other: `${formattedCount} others`, - })} liked your custom feed`, - ) - : _(msg`${a11yAuthor} liked your custom feed`) - action = - authors.length > 1 ? ( - - {author} and{' '} - - - {' '} - liked your custom feed - - ) : ( - {author} liked your custom feed - ) + a11yLabel = hasMultipleAuthors + ? _( + msg`${firstAuthorName} and ${plural(additionalAuthorsCount, { + one: `${formattedAuthorsCount} other`, + other: `${formattedAuthorsCount} others`, + })} liked your custom feed`, + ) + : _(msg`${firstAuthorName} liked your custom feed`) + notificationContent = hasMultipleAuthors ? ( + + {firstAuthorLink} and{' '} + + + {' '} + liked your custom feed + + ) : ( + {firstAuthorLink} liked your custom feed + ) } else if (item.type === 'starterpack-joined') { - a11yLabel = - authors.length > 1 - ? _( - msg`${a11yAuthor} and ${plural(authors.length - 1, { - one: `${formattedCount} other`, - other: `${formattedCount} others`, - })} signed up with your starter pack`, - ) - : _(msg`${a11yAuthor} signed up with your starter pack`) - action = - authors.length > 1 ? ( - - {author} and{' '} - - - {' '} - signed up with your starter pack - - ) : ( - {author} signed up with your starter pack - ) + a11yLabel = hasMultipleAuthors + ? _( + msg`${firstAuthorName} and ${plural(additionalAuthorsCount, { + one: `${formattedAuthorsCount} other`, + other: `${formattedAuthorsCount} others`, + })} signed up with your starter pack`, + ) + : _(msg`${firstAuthorName} signed up with your starter pack`) + notificationContent = hasMultipleAuthors ? ( + + {firstAuthorLink} and{' '} + + + {' '} + signed up with your starter pack + + ) : ( + {firstAuthorLink} signed up with your starter pack + ) icon = ( @@ -416,7 +389,7 @@ let FeedItem = ({ accessibilityLabel={a11yLabel} accessible={!isAuthorsExpanded} accessibilityActions={ - authors.length > 1 + hasMultipleAuthors ? [ { name: 'toggleAuthorsExpanded', @@ -445,14 +418,10 @@ let FeedItem = ({ } }} onBeforePress={onBeforePress}> - - {/* TODO: Prevent conditional rendering and move toward composable - notifications for clearer accessibility labeling */} - {icon} - + {icon} 1} + hasMultipleAuthors={hasMultipleAuthors} onToggleAuthorsExpanded={onToggleAuthorsExpanded}> - {action} + {notificationContent} {({timeElapsed}) => ( <>