Update FeedItem.tsx

This commit is contained in:
Minseo Lee
2024-06-10 14:35:02 +09:00
parent 0b6ae76139
commit 89fc356eb7
+75 -31
View File
@@ -1,4 +1,4 @@
import React, {memo, useEffect, useMemo, useState} from 'react'
import React, {memo, ReactElement, useEffect, useMemo, useState} from 'react'
import {
Animated,
Pressable,
@@ -154,7 +154,22 @@ let FeedItem = ({
)
}
let action = ''
let formattedCount = authors.length > 1 ? formatCount(authors.length - 1) : ''
let author = (
<TextLink
key={authors[0].href}
style={[pal.text, s.bold]}
href={authors[0].href}
text={sanitizeDisplayName(
authors[0].profile.displayName || authors[0].profile.handle,
)}
disableMismatchWarning
/>
)
let action: ReactElement
let actionPlural: ReactElement
let icon = (
<HeartIconFilled
size="xl"
@@ -164,21 +179,73 @@ let FeedItem = ({
]}
/>
)
if (item.type === 'post-like') {
action = _(msg`liked your post`)
action = <Trans>{author} liked your post</Trans>
actionPlural = (
<Trans>
{author} and{' '}
<Text style={[pal.text, s.bold]}>
<Plural
value={authors.length - 1}
one={`${formattedCount} other`}
other={`${formattedCount} others`}
/>
</Text>{' '}
liked your post
</Trans>
)
} else if (item.type === 'repost') {
action = _(msg`reposted your post`)
action = <Trans>{author} reposted your post</Trans>
actionPlural = (
<Trans>
{author} and{' '}
<Text style={[pal.text, s.bold]}>
<Plural
value={authors.length - 1}
one={`${formattedCount} other`}
other={`${formattedCount} others`}
/>
</Text>{' '}
reposted your post
</Trans>
)
icon = <RepostIcon size="xl" style={{color: t.palette.positive_600}} />
} else if (item.type === 'follow') {
action = _(msg`followed you`)
action = <Trans>{author} followed you</Trans>
actionPlural = (
<Trans>
{author} and{' '}
<Text style={[pal.text, s.bold]}>
<Plural
value={authors.length - 1}
one={`${formattedCount} other`}
other={`${formattedCount} others`}
/>
</Text>{' '}
followed you
</Trans>
)
icon = <PersonPlusIcon size="xl" style={{color: t.palette.primary_500}} />
} else if (item.type === 'feedgen-like') {
action = _(msg`liked your custom feed`)
action = <Trans>{author} liked your custom feed</Trans>
actionPlural = (
<Trans>
{author} and{' '}
<Text style={[pal.text, s.bold]}>
<Plural
value={authors.length - 1}
one={`${formattedCount} other`}
other={`${formattedCount} others`}
/>
</Text>{' '}
liked your custom feed
</Trans>
)
} else {
return null
}
let formattedCount = authors.length > 1 ? formatCount(authors.length - 1) : ''
return (
<Link
testID={`feedItem-by-${item.notification.author.handle}`}
@@ -242,30 +309,7 @@ let FeedItem = ({
/>
<ExpandedAuthorsList visible={isAuthorsExpanded} authors={authors} />
<Text style={[styles.meta, pal.text]}>
<Trans context="notification">
<TextLink
key={authors[0].href}
style={[pal.text, s.bold]}
href={authors[0].href}
text={sanitizeDisplayName(
authors[0].profile.displayName || authors[0].profile.handle,
)}
disableMismatchWarning
/>
{authors.length > 1 ? (
<Trans context="notification">
<Text style={[pal.text]}> and </Text>
<Text style={[pal.text, s.bold]}>
<Plural
value={authors.length - 1}
one={`${formattedCount} other`}
other={`${formattedCount} others`}
/>
</Text>
</Trans>
) : undefined}
<Text style={[pal.text]}> {action}</Text>
</Trans>
{authors.length > 1 ? actionPlural : action}
<TimeElapsed timestamp={item.notification.indexedAt}>
{({timeElapsed}) => (
<Text