Like button improvements

This commit is contained in:
Eric Bailey
2024-03-08 11:01:15 -06:00
parent 040e9bf63c
commit 1a9f6fcf73
@@ -24,6 +24,7 @@ import {pluralize} from '#/lib/strings/helpers'
import {atoms as a, useTheme} from '#/alf' import {atoms as a, useTheme} from '#/alf'
import {Button, ButtonText} from '#/components/Button' import {Button, ButtonText} from '#/components/Button'
import {Text} from '#/components/Typography'
import * as Toast from '#/view/com/util/Toast' import * as Toast from '#/view/com/util/Toast'
import {ProfileHeaderShell} from './Shell' import {ProfileHeaderShell} from './Shell'
import {ProfileHeaderDropdownBtn} from './DropdownBtn' import {ProfileHeaderDropdownBtn} from './DropdownBtn'
@@ -86,6 +87,8 @@ let ProfileHeaderLabeler = ({
labeler.viewer?.like || '', labeler.viewer?.like || '',
) )
const isLiked = !!likeUri const isLiked = !!likeUri
const likeCount =
isLiked && likeUri ? (labeler.likeCount || 0) + 1 : labeler.likeCount || 0
const onToggleLiked = React.useCallback(async () => { const onToggleLiked = React.useCallback(async () => {
if (!labeler) { if (!labeler) {
@@ -216,7 +219,7 @@ let ProfileHeaderLabeler = ({
/> />
</View> </View>
) : undefined} ) : undefined}
<View style={[a.flex_row, a.gap_xs, a.align_center, a.pt_md]}> <View style={[a.flex_row, a.gap_xs, a.align_center, a.pt_lg]}>
<Button <Button
testID="toggleLikeBtn" testID="toggleLikeBtn"
size="small" size="small"
@@ -235,26 +238,25 @@ let ProfileHeaderLabeler = ({
{typeof labeler.likeCount === 'number' && ( {typeof labeler.likeCount === 'number' && (
<Button <Button
variant="ghost"
size="tiny" size="tiny"
onPress={() => likesControl.open()} onPress={() => likesControl.open()}
label={_( label={_(
msg`Liked by ${labeler.likeCount} ${pluralize( msg`Liked by ${likeCount} ${pluralize(likeCount, 'user')}`,
labeler.likeCount,
'user',
)}`,
)}> )}>
<ButtonText {({hovered, focused, pressed}) => (
style={[ <Text
t.atoms.text_contrast_medium, style={[
a.font_bold, a.font_bold,
a.text_sm, a.text_sm,
]}> t.atoms.text_contrast_medium,
<Trans> (hovered || focused || pressed) &&
Liked by {labeler.likeCount}{' '} t.atoms.text_contrast_high,
{pluralize(labeler.likeCount, 'user')} ]}>
</Trans> <Trans>
</ButtonText> Liked by {likeCount} {pluralize(likeCount, 'user')}
</Trans>
</Text>
)}
</Button> </Button>
)} )}
</View> </View>