901feba6db
* Replace pluralize with plural or Plural * Replace all pluralize (defined by src/lib/strings/helpers.ts) with plural or Plural (defined by @lingui/macro) to make some UI elements translatable. * Delete pluralize() and related test. * Import @formatjs polyfill libraries for plural on ios and android - ios and andorid: import `@formtjs/intl-locale` and `@formatjs/intl-pluralrules` to polyfill `Intl.Locale` and `Intl.PluralRules` which are used in `plural()` and '<Plural />'. - update `plural` use in notification messages for better translation. * Rewrite to pass lint * Add Catalan plural polyfill * more replacement * import zh plural data for zh-CN * Refactor feed header components (#2964) * Move home-related files to view/com/home * Add HomeHeader in front of FeedTabBar * Move isDekstop check outside FeedsTabBar * Remove PWI logic from tabbar * Separate platform-specific layout from shared logic * Rename Home Feed Prefs to Following Feed Prefs (#2965) * use `useOpenLink` hook for links in ALF (#2975) * use `useOpenLink` hook for links in ALF * web only for `outline` * increase timeout to 15s (#2958) * Normalize relative day (#2874) * fix: normalize relative date * chore: add comments * refactor: skip flooring normalized diff * refactor: let -> const * fix: get own copy of date to prevent mutating * refactor: rounding does the same trick * Add handle validation to create account UI (#2959) * show uiState errors in the box as well simplify copy update ui for only letters and numbers add ui validation to handle selection * simplify names * Fix accidental text-node render --------- Co-authored-by: Paul Frazee <pfrazee@gmail.com> * Make dim theme dim (#2966) * Make dim color scheme dim * Tweaks * Overall tweaks * We have to go darker * Tweak saturation of blues in dim * Increase contrast on dark-dark mode * adjust dim --------- Co-authored-by: Eric Bailey <git@esb.lol> Co-authored-by: Paul Frazee <pfrazee@gmail.com> Co-authored-by: Hailey <me@haileyok.com> * Fix dim mode unread notif color * use `showControls` to show/hide live text icon on ios (#2982) * Update .po files * fix reversed icons in validator 🤦 (#2991) * Adjust `windowSize` on `PostThread` `FlatList` (#2989) * adjust window size, cells batching period * rm batching period change * Pluralize 'follow(s)' * Include a space between the msgid count and "follower(s)/following(s)" so the translator can adjust the translated count line to fit within the Drawer. * pluralie '# following' * Fix & Update * Rewrite to use Plural * rmeove unused import * When commiting changes, disable 'simple-import-sort' plugin in .eslintrc.js to sync with bluesky-social:main * Revert simple-import-sort/imports related changes * Move ProfileHoverCard web to plural util * Followings -> following * Add plural following to hovercard * Followings -> Following --------- Co-authored-by: Takayuki KUSANO <kusano@tkusano.jp> Co-authored-by: Takayuki KUSANO <65759+tkusano@users.noreply.github.com> Co-authored-by: dan <dan.abramov@gmail.com> Co-authored-by: Hailey <me@haileyok.com> Co-authored-by: Mary <148872143+mary-ext@users.noreply.github.com> Co-authored-by: Eric Bailey <git@esb.lol>
315 lines
8.8 KiB
TypeScript
315 lines
8.8 KiB
TypeScript
import React from 'react'
|
|
import {Pressable, StyleProp, StyleSheet, View, ViewStyle} from 'react-native'
|
|
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
|
import {Text} from '../util/text/Text'
|
|
import {RichText} from '#/components/RichText'
|
|
import {usePalette} from 'lib/hooks/usePalette'
|
|
import {s} from 'lib/styles'
|
|
import {UserAvatar} from '../util/UserAvatar'
|
|
import {AtUri} from '@atproto/api'
|
|
import * as Toast from 'view/com/util/Toast'
|
|
import {sanitizeHandle} from 'lib/strings/handles'
|
|
import {logger} from '#/logger'
|
|
import {Trans, msg, Plural} from '@lingui/macro'
|
|
import {useLingui} from '@lingui/react'
|
|
import {
|
|
usePinFeedMutation,
|
|
UsePreferencesQueryResponse,
|
|
usePreferencesQuery,
|
|
useSaveFeedMutation,
|
|
useRemoveFeedMutation,
|
|
} from '#/state/queries/preferences'
|
|
import {useFeedSourceInfoQuery, FeedSourceInfo} from '#/state/queries/feed'
|
|
import {FeedLoadingPlaceholder} from '#/view/com/util/LoadingPlaceholder'
|
|
import {useTheme} from '#/alf'
|
|
import * as Prompt from '#/components/Prompt'
|
|
import {useNavigationDeduped} from 'lib/hooks/useNavigationDeduped'
|
|
|
|
export function FeedSourceCard({
|
|
feedUri,
|
|
style,
|
|
showSaveBtn = false,
|
|
showDescription = false,
|
|
showLikes = false,
|
|
pinOnSave = false,
|
|
showMinimalPlaceholder,
|
|
}: {
|
|
feedUri: string
|
|
style?: StyleProp<ViewStyle>
|
|
showSaveBtn?: boolean
|
|
showDescription?: boolean
|
|
showLikes?: boolean
|
|
pinOnSave?: boolean
|
|
showMinimalPlaceholder?: boolean
|
|
}) {
|
|
const {data: preferences} = usePreferencesQuery()
|
|
const {data: feed} = useFeedSourceInfoQuery({uri: feedUri})
|
|
|
|
return (
|
|
<FeedSourceCardLoaded
|
|
feedUri={feedUri}
|
|
feed={feed}
|
|
preferences={preferences}
|
|
style={style}
|
|
showSaveBtn={showSaveBtn}
|
|
showDescription={showDescription}
|
|
showLikes={showLikes}
|
|
pinOnSave={pinOnSave}
|
|
showMinimalPlaceholder={showMinimalPlaceholder}
|
|
/>
|
|
)
|
|
}
|
|
|
|
export function FeedSourceCardLoaded({
|
|
feedUri,
|
|
feed,
|
|
preferences,
|
|
style,
|
|
showSaveBtn = false,
|
|
showDescription = false,
|
|
showLikes = false,
|
|
pinOnSave = false,
|
|
showMinimalPlaceholder,
|
|
}: {
|
|
feedUri: string
|
|
feed?: FeedSourceInfo
|
|
preferences?: UsePreferencesQueryResponse
|
|
style?: StyleProp<ViewStyle>
|
|
showSaveBtn?: boolean
|
|
showDescription?: boolean
|
|
showLikes?: boolean
|
|
pinOnSave?: boolean
|
|
showMinimalPlaceholder?: boolean
|
|
}) {
|
|
const t = useTheme()
|
|
const pal = usePalette('default')
|
|
const {_} = useLingui()
|
|
const removePromptControl = Prompt.usePromptControl()
|
|
const navigation = useNavigationDeduped()
|
|
|
|
const {isPending: isSavePending, mutateAsync: saveFeed} =
|
|
useSaveFeedMutation()
|
|
const {isPending: isRemovePending, mutateAsync: removeFeed} =
|
|
useRemoveFeedMutation()
|
|
const {isPending: isPinPending, mutateAsync: pinFeed} = usePinFeedMutation()
|
|
|
|
const isSaved = Boolean(preferences?.feeds?.saved?.includes(feed?.uri || ''))
|
|
|
|
const onSave = React.useCallback(async () => {
|
|
if (!feed) return
|
|
|
|
try {
|
|
if (pinOnSave) {
|
|
await pinFeed({uri: feed.uri})
|
|
} else {
|
|
await saveFeed({uri: feed.uri})
|
|
}
|
|
Toast.show(_(msg`Added to my feeds`))
|
|
} catch (e) {
|
|
Toast.show(_(msg`There was an issue contacting your server`))
|
|
logger.error('Failed to save feed', {message: e})
|
|
}
|
|
}, [_, feed, pinFeed, pinOnSave, saveFeed])
|
|
|
|
const onUnsave = React.useCallback(async () => {
|
|
if (!feed) return
|
|
|
|
try {
|
|
await removeFeed({uri: feed.uri})
|
|
// await item.unsave()
|
|
Toast.show(_(msg`Removed from my feeds`))
|
|
} catch (e) {
|
|
Toast.show(_(msg`There was an issue contacting your server`))
|
|
logger.error('Failed to unsave feed', {message: e})
|
|
}
|
|
}, [_, feed, removeFeed])
|
|
|
|
const onToggleSaved = React.useCallback(async () => {
|
|
// Only feeds can be un/saved, lists are handled elsewhere
|
|
if (feed?.type !== 'feed') return
|
|
|
|
if (isSaved) {
|
|
removePromptControl.open()
|
|
} else {
|
|
await onSave()
|
|
}
|
|
}, [feed?.type, isSaved, removePromptControl, onSave])
|
|
|
|
/*
|
|
* LOAD STATE
|
|
*
|
|
* This state also captures the scenario where a feed can't load for whatever
|
|
* reason.
|
|
*/
|
|
if (!feed || !preferences)
|
|
return (
|
|
<View
|
|
style={[
|
|
pal.border,
|
|
{
|
|
borderTopWidth: showMinimalPlaceholder ? 0 : 1,
|
|
flexDirection: 'row',
|
|
alignItems: 'center',
|
|
flex: 1,
|
|
paddingRight: 18,
|
|
},
|
|
]}>
|
|
{showMinimalPlaceholder ? (
|
|
<FeedLoadingPlaceholder
|
|
style={{flex: 1}}
|
|
showTopBorder={false}
|
|
showLowerPlaceholder={false}
|
|
/>
|
|
) : (
|
|
<FeedLoadingPlaceholder style={{flex: 1}} showTopBorder={false} />
|
|
)}
|
|
|
|
{showSaveBtn && (
|
|
<Pressable
|
|
testID={`feed-${feedUri}-toggleSave`}
|
|
disabled={isRemovePending}
|
|
accessibilityRole="button"
|
|
accessibilityLabel={_(msg`Remove from my feeds`)}
|
|
accessibilityHint=""
|
|
onPress={onToggleSaved}
|
|
hitSlop={15}
|
|
style={styles.btn}>
|
|
<FontAwesomeIcon
|
|
icon={['far', 'trash-can']}
|
|
size={19}
|
|
color={pal.colors.icon}
|
|
/>
|
|
</Pressable>
|
|
)}
|
|
</View>
|
|
)
|
|
|
|
return (
|
|
<>
|
|
<Pressable
|
|
testID={`feed-${feed.displayName}`}
|
|
accessibilityRole="button"
|
|
style={[styles.container, pal.border, style]}
|
|
onPress={() => {
|
|
if (feed.type === 'feed') {
|
|
navigation.push('ProfileFeed', {
|
|
name: feed.creatorDid,
|
|
rkey: new AtUri(feed.uri).rkey,
|
|
})
|
|
} else if (feed.type === 'list') {
|
|
navigation.push('ProfileList', {
|
|
name: feed.creatorDid,
|
|
rkey: new AtUri(feed.uri).rkey,
|
|
})
|
|
}
|
|
}}
|
|
key={feed.uri}>
|
|
<View style={[styles.headerContainer]}>
|
|
<View style={[s.mr10]}>
|
|
<UserAvatar type="algo" size={36} avatar={feed.avatar} />
|
|
</View>
|
|
<View style={[styles.headerTextContainer]}>
|
|
<Text style={[pal.text, s.bold]} numberOfLines={3}>
|
|
{feed.displayName}
|
|
</Text>
|
|
<Text style={[pal.textLight]} numberOfLines={3}>
|
|
{feed.type === 'feed' ? (
|
|
<Trans>Feed by {sanitizeHandle(feed.creatorHandle, '@')}</Trans>
|
|
) : (
|
|
<Trans>List by {sanitizeHandle(feed.creatorHandle, '@')}</Trans>
|
|
)}
|
|
</Text>
|
|
</View>
|
|
|
|
{showSaveBtn && feed.type === 'feed' && (
|
|
<View style={[s.justifyCenter]}>
|
|
<Pressable
|
|
testID={`feed-${feed.displayName}-toggleSave`}
|
|
disabled={isSavePending || isPinPending || isRemovePending}
|
|
accessibilityRole="button"
|
|
accessibilityLabel={
|
|
isSaved
|
|
? _(msg`Remove from my feeds`)
|
|
: _(msg`Add to my feeds`)
|
|
}
|
|
accessibilityHint=""
|
|
onPress={onToggleSaved}
|
|
hitSlop={15}
|
|
style={styles.btn}>
|
|
{isSaved ? (
|
|
<FontAwesomeIcon
|
|
icon={['far', 'trash-can']}
|
|
size={19}
|
|
color={pal.colors.icon}
|
|
/>
|
|
) : (
|
|
<FontAwesomeIcon
|
|
icon="plus"
|
|
size={18}
|
|
color={pal.colors.link}
|
|
/>
|
|
)}
|
|
</Pressable>
|
|
</View>
|
|
)}
|
|
</View>
|
|
|
|
{showDescription && feed.description ? (
|
|
<RichText
|
|
style={[t.atoms.text_contrast_high, styles.description]}
|
|
value={feed.description}
|
|
numberOfLines={3}
|
|
/>
|
|
) : null}
|
|
|
|
{showLikes && feed.type === 'feed' ? (
|
|
<Text type="sm-medium" style={[pal.text, pal.textLight]}>
|
|
<Plural
|
|
value={feed.likeCount || 0}
|
|
one="Liked by # user"
|
|
other="Liked by # users"
|
|
/>
|
|
</Text>
|
|
) : null}
|
|
</Pressable>
|
|
|
|
<Prompt.Basic
|
|
control={removePromptControl}
|
|
title={_(msg`Remove from my feeds?`)}
|
|
description={_(
|
|
msg`Are you sure you want to remove ${feed.displayName} from your feeds?`,
|
|
)}
|
|
onConfirm={onUnsave}
|
|
confirmButtonCta={_(msg`Remove`)}
|
|
confirmButtonColor="negative"
|
|
/>
|
|
</>
|
|
)
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
container: {
|
|
paddingHorizontal: 18,
|
|
paddingVertical: 20,
|
|
flexDirection: 'column',
|
|
flex: 1,
|
|
borderTopWidth: 1,
|
|
gap: 14,
|
|
},
|
|
headerContainer: {
|
|
flexDirection: 'row',
|
|
},
|
|
headerTextContainer: {
|
|
flexDirection: 'column',
|
|
columnGap: 4,
|
|
flex: 1,
|
|
},
|
|
description: {
|
|
flex: 1,
|
|
flexWrap: 'wrap',
|
|
},
|
|
btn: {
|
|
paddingVertical: 6,
|
|
},
|
|
})
|