diff options
Diffstat (limited to 'src/view')
68 files changed, 2567 insertions, 616 deletions
diff --git a/src/view/com/auth/create/Step1.tsx b/src/view/com/auth/create/Step1.tsx index ac0d706d7..57747f070 100644 --- a/src/view/com/auth/create/Step1.tsx +++ b/src/view/com/auth/create/Step1.tsx @@ -32,7 +32,7 @@ export const Step1 = observer(({model}: {model: CreateAccountModel}) => { model.setServiceDescription(undefined) }, [setIsDefaultSelected, model]) - const fetchServiceDesription = React.useMemo( + const fetchServiceDescription = React.useMemo( () => debounce(() => model.fetchServiceDescription(), 1e3), [model], ) @@ -40,9 +40,9 @@ export const Step1 = observer(({model}: {model: CreateAccountModel}) => { const onChangeServiceUrl = React.useCallback( (v: string) => { model.setServiceUrl(v) - fetchServiceDesription() + fetchServiceDescription() }, - [model, fetchServiceDesription], + [model, fetchServiceDescription], ) const onDebugChangeServiceUrl = React.useCallback( diff --git a/src/view/com/auth/login/Login.tsx b/src/view/com/auth/login/Login.tsx index 87512287b..9f5d581b6 100644 --- a/src/view/com/auth/login/Login.tsx +++ b/src/view/com/auth/login/Login.tsx @@ -420,6 +420,7 @@ const LoginForm = ({ textContentType="oneTimeCode" value={password} onChangeText={setPassword} + onSubmitEditing={onPressNext} editable={!isProcessing} accessibilityLabel="Password" accessibilityHint={ diff --git a/src/view/com/composer/Composer.tsx b/src/view/com/composer/Composer.tsx index 3891fa268..d7a4a42d5 100644 --- a/src/view/com/composer/Composer.tsx +++ b/src/view/com/composer/Composer.tsx @@ -37,8 +37,7 @@ import {useExternalLinkFetch} from './useExternalLinkFetch' import {isDesktopWeb, isAndroid} from 'platform/detection' import {GalleryModel} from 'state/models/media/gallery' import {Gallery} from './photos/Gallery' - -const MAX_GRAPHEME_LENGTH = 300 +import {MAX_GRAPHEME_LENGTH} from 'lib/constants' type Props = ComposerOpts & { onClose: () => void @@ -310,7 +309,7 @@ export const ComposePost = observer(function ComposePost({ onError={setError} accessible={true} accessibilityLabel="Write post" - accessibilityHint="Compose posts up to 300 characters in length" + accessibilityHint={`Compose posts up to ${MAX_GRAPHEME_LENGTH} characters in length`} /> </View> diff --git a/src/view/com/composer/char-progress/CharProgress.tsx b/src/view/com/composer/char-progress/CharProgress.tsx index eaaaea5e5..6b3b98e47 100644 --- a/src/view/com/composer/char-progress/CharProgress.tsx +++ b/src/view/com/composer/char-progress/CharProgress.tsx @@ -7,9 +7,9 @@ import ProgressCircle from 'react-native-progress/Circle' import ProgressPie from 'react-native-progress/Pie' import {s} from 'lib/styles' import {usePalette} from 'lib/hooks/usePalette' +import {MAX_GRAPHEME_LENGTH} from 'lib/constants' -const MAX_LENGTH = 300 -const DANGER_LENGTH = MAX_LENGTH +const DANGER_LENGTH = MAX_GRAPHEME_LENGTH export function CharProgress({count}: {count: number}) { const pal = usePalette('default') @@ -17,7 +17,9 @@ export function CharProgress({count}: {count: number}) { const circleColor = count > DANGER_LENGTH ? '#e60000' : pal.colors.link return ( <> - <Text style={[s.mr10, {color: textColor}]}>{MAX_LENGTH - count}</Text> + <Text style={[s.mr10, {color: textColor}]}> + {MAX_GRAPHEME_LENGTH - count} + </Text> <View> {count > DANGER_LENGTH ? ( <ProgressPie @@ -25,7 +27,10 @@ export function CharProgress({count}: {count: number}) { borderWidth={4} borderColor={circleColor} color={circleColor} - progress={Math.min((count - MAX_LENGTH) / MAX_LENGTH, 1)} + progress={Math.min( + (count - MAX_GRAPHEME_LENGTH) / MAX_GRAPHEME_LENGTH, + 1, + )} /> ) : ( <ProgressCircle @@ -33,7 +38,7 @@ export function CharProgress({count}: {count: number}) { borderWidth={1} borderColor={pal.colors.border} color={circleColor} - progress={count / MAX_LENGTH} + progress={count / MAX_GRAPHEME_LENGTH} /> )} </View> diff --git a/src/view/com/composer/photos/Gallery.tsx b/src/view/com/composer/photos/Gallery.tsx index 436824952..f46c05333 100644 --- a/src/view/com/composer/photos/Gallery.tsx +++ b/src/view/com/composer/photos/Gallery.tsx @@ -104,63 +104,61 @@ export const Gallery = observer(function ({gallery}: Props) { return !gallery.isEmpty ? ( <View testID="selectedPhotosView" style={styles.gallery}> - {gallery.images.map(image => - image.compressed !== undefined ? ( - <View key={`selected-image-${image.path}`} style={[imageStyle]}> + {gallery.images.map(image => ( + <View key={`selected-image-${image.path}`} style={[imageStyle]}> + <TouchableOpacity + testID="altTextButton" + accessibilityRole="button" + accessibilityLabel="Add alt text" + accessibilityHint="" + onPress={() => { + handleAddImageAltText(image) + }} + style={imageControlLabelStyle}> + <Text style={styles.imageControlTextContent}>ALT</Text> + </TouchableOpacity> + <View style={imageControlsSubgroupStyle}> <TouchableOpacity - testID="altTextButton" + testID="editPhotoButton" accessibilityRole="button" - accessibilityLabel="Add alt text" + accessibilityLabel="Edit image" accessibilityHint="" onPress={() => { - handleAddImageAltText(image) + handleEditPhoto(image) }} - style={imageControlLabelStyle}> - <Text style={styles.imageControlTextContent}>ALT</Text> + style={styles.imageControl}> + <FontAwesomeIcon + icon="pen" + size={12} + style={{color: colors.white}} + /> + </TouchableOpacity> + <TouchableOpacity + testID="removePhotoButton" + accessibilityRole="button" + accessibilityLabel="Remove image" + accessibilityHint="" + onPress={() => handleRemovePhoto(image)} + style={styles.imageControl}> + <FontAwesomeIcon + icon="xmark" + size={16} + style={{color: colors.white}} + /> </TouchableOpacity> - <View style={imageControlsSubgroupStyle}> - <TouchableOpacity - testID="editPhotoButton" - accessibilityRole="button" - accessibilityLabel="Edit image" - accessibilityHint="" - onPress={() => { - handleEditPhoto(image) - }} - style={styles.imageControl}> - <FontAwesomeIcon - icon="pen" - size={12} - style={{color: colors.white}} - /> - </TouchableOpacity> - <TouchableOpacity - testID="removePhotoButton" - accessibilityRole="button" - accessibilityLabel="Remove image" - accessibilityHint="" - onPress={() => handleRemovePhoto(image)} - style={styles.imageControl}> - <FontAwesomeIcon - icon="xmark" - size={16} - style={{color: colors.white}} - /> - </TouchableOpacity> - </View> - - <Image - testID="selectedPhotoImage" - style={[styles.image, imageStyle] as ImageStyle} - source={{ - uri: image.compressed.path, - }} - accessible={true} - accessibilityIgnoresInvertColors - /> </View> - ) : null, - )} + + <Image + testID="selectedPhotoImage" + style={[styles.image, imageStyle] as ImageStyle} + source={{ + uri: image.cropped?.path ?? image.path, + }} + accessible={true} + accessibilityIgnoresInvertColors + /> + </View> + ))} </View> ) : null }) diff --git a/src/view/com/composer/useExternalLinkFetch.ts b/src/view/com/composer/useExternalLinkFetch.ts index 45c2dfd0d..8d3b8cac2 100644 --- a/src/view/com/composer/useExternalLinkFetch.ts +++ b/src/view/com/composer/useExternalLinkFetch.ts @@ -2,9 +2,9 @@ import {useState, useEffect} from 'react' import {useStores} from 'state/index' import * as apilib from 'lib/api/index' import {getLinkMeta} from 'lib/link-meta/link-meta' -import {getPostAsQuote} from 'lib/link-meta/bsky' +import {getPostAsQuote, getFeedAsEmbed} from 'lib/link-meta/bsky' import {downloadAndResize} from 'lib/media/manip' -import {isBskyPostUrl} from 'lib/strings/url-helpers' +import {isBskyPostUrl, isBskyCustomFeedUrl} from 'lib/strings/url-helpers' import {ComposerOpts} from 'state/models/ui/shell' import {POST_IMG_MAX} from 'lib/constants' @@ -41,6 +41,24 @@ export function useExternalLinkFetch({ setExtLink(undefined) }, ) + } else if (isBskyCustomFeedUrl(extLink.uri)) { + getFeedAsEmbed(store, extLink.uri).then( + ({embed, meta}) => { + if (aborted) { + return + } + setExtLink({ + uri: extLink.uri, + isLoading: false, + meta, + embed, + }) + }, + err => { + store.log.error('Failed to fetch feed for embedding', {err}) + setExtLink(undefined) + }, + ) } else { getLinkMeta(store, extLink.uri).then(meta => { if (aborted) { diff --git a/src/view/com/feeds/CustomFeed.tsx b/src/view/com/feeds/CustomFeed.tsx new file mode 100644 index 000000000..748b89c02 --- /dev/null +++ b/src/view/com/feeds/CustomFeed.tsx @@ -0,0 +1,162 @@ +import React from 'react' +import { + Pressable, + StyleProp, + StyleSheet, + View, + ViewStyle, + TouchableOpacity, +} from 'react-native' +import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' +import {Text} from '../util/text/Text' +import {usePalette} from 'lib/hooks/usePalette' +import {s} from 'lib/styles' +import {UserAvatar} from '../util/UserAvatar' +import {observer} from 'mobx-react-lite' +import {CustomFeedModel} from 'state/models/feeds/custom-feed' +import {useNavigation} from '@react-navigation/native' +import {NavigationProp} from 'lib/routes/types' +import {useStores} from 'state/index' +import {pluralize} from 'lib/strings/helpers' +import {AtUri} from '@atproto/api' +import * as Toast from 'view/com/util/Toast' + +export const CustomFeed = observer( + ({ + item, + style, + showSaveBtn = false, + showDescription = false, + showLikes = false, + }: { + item: CustomFeedModel + style?: StyleProp<ViewStyle> + showSaveBtn?: boolean + showDescription?: boolean + showLikes?: boolean + }) => { + const store = useStores() + const pal = usePalette('default') + const navigation = useNavigation<NavigationProp>() + + const onToggleSaved = React.useCallback(async () => { + if (item.isSaved) { + store.shell.openModal({ + name: 'confirm', + title: 'Remove from my feeds', + message: `Remove ${item.displayName} from my feeds?`, + onPressConfirm: async () => { + try { + await store.me.savedFeeds.unsave(item) + Toast.show('Removed from my feeds') + } catch (e) { + Toast.show('There was an issue contacting your server') + store.log.error('Failed to unsave feed', {e}) + } + }, + }) + } else { + try { + await store.me.savedFeeds.save(item) + Toast.show('Added to my feeds') + } catch (e) { + Toast.show('There was an issue contacting your server') + store.log.error('Failed to save feed', {e}) + } + } + }, [store, item]) + + return ( + <TouchableOpacity + accessibilityRole="button" + style={[styles.container, pal.border, style]} + onPress={() => { + navigation.navigate('CustomFeed', { + name: item.data.creator.did, + rkey: new AtUri(item.data.uri).rkey, + }) + }} + key={item.data.uri}> + <View style={[styles.headerContainer]}> + <View style={[s.mr10]}> + <UserAvatar type="algo" size={36} avatar={item.data.avatar} /> + </View> + <View style={[styles.headerTextContainer]}> + <Text style={[pal.text, s.bold]} numberOfLines={3}> + {item.displayName} + </Text> + <Text style={[pal.textLight]} numberOfLines={3}> + by @{item.data.creator.handle} + </Text> + </View> + {showSaveBtn && ( + <View> + <Pressable + accessibilityRole="button" + accessibilityLabel={ + item.isSaved ? 'Remove from my feeds' : 'Add to my feeds' + } + accessibilityHint="" + onPress={onToggleSaved} + hitSlop={15} + style={styles.btn}> + {item.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 && item.data.description ? ( + <Text style={[pal.textLight, styles.description]} numberOfLines={3}> + {item.data.description} + </Text> + ) : null} + + {showLikes ? ( + <Text type="sm-medium" style={[pal.text, pal.textLight]}> + Liked by {item.data.likeCount || 0}{' '} + {pluralize(item.data.likeCount || 0, 'user')} + </Text> + ) : null} + </TouchableOpacity> + ) + }, +) + +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, + }, +}) diff --git a/src/view/com/lightbox/Lightbox.web.tsx b/src/view/com/lightbox/Lightbox.web.tsx index d389279b1..61446519d 100644 --- a/src/view/com/lightbox/Lightbox.web.tsx +++ b/src/view/com/lightbox/Lightbox.web.tsx @@ -65,30 +65,34 @@ function LightboxInner({ const canGoLeft = index >= 1 const canGoRight = index < imgs.length - 1 - const onPressLeft = () => { + const onPressLeft = useCallback(() => { if (canGoLeft) { setIndex(index - 1) } - } - const onPressRight = () => { + }, [index, canGoLeft]) + const onPressRight = useCallback(() => { if (canGoRight) { setIndex(index + 1) } - } + }, [index, canGoRight]) - const onEscape = useCallback( + const onKeyDown = useCallback( (e: KeyboardEvent) => { if (e.key === 'Escape') { onClose() + } else if (e.key === 'ArrowLeft') { + onPressLeft() + } else if (e.key === 'ArrowRight') { + onPressRight() } }, - [onClose], + [onClose, onPressLeft, onPressRight], ) useEffect(() => { - window.addEventListener('keydown', onEscape) - return () => window.removeEventListener('keydown', onEscape) - }, [onEscape]) + window.addEventListener('keydown', onKeyDown) + return () => window.removeEventListener('keydown', onKeyDown) + }, [onKeyDown]) return ( <View style={styles.mask}> diff --git a/src/view/com/lists/ListCard.tsx b/src/view/com/lists/ListCard.tsx index 7cbdaaf64..0e13ca333 100644 --- a/src/view/com/lists/ListCard.tsx +++ b/src/view/com/lists/ListCard.tsx @@ -60,7 +60,7 @@ export const ListCard = ({ anchorNoUnderline> <View style={styles.layout}> <View style={styles.layoutAvi}> - <UserAvatar size={40} avatar={list.avatar} /> + <UserAvatar type="list" size={40} avatar={list.avatar} /> </View> <View style={styles.layoutContent}> <Text diff --git a/src/view/com/lists/ListItems.tsx b/src/view/com/lists/ListItems.tsx index 32cafdb83..914f446a1 100644 --- a/src/view/com/lists/ListItems.tsx +++ b/src/view/com/lists/ListItems.tsx @@ -341,7 +341,7 @@ const ListHeader = observer( )} </View> <View> - <UserAvatar avatar={list.avatar} size={64} /> + <UserAvatar type="list" avatar={list.avatar} size={64} /> </View> </View> <View style={[styles.fakeSelector, pal.border]}> diff --git a/src/view/com/modals/ContentFilteringSettings.tsx b/src/view/com/modals/ContentFilteringSettings.tsx index 1256bd420..5215c9cb4 100644 --- a/src/view/com/modals/ContentFilteringSettings.tsx +++ b/src/view/com/modals/ContentFilteringSettings.tsx @@ -52,8 +52,8 @@ export const Component = observer(({}: {}) => { Adult content can only be enabled via the Web at{' '} <TextLink style={pal.link} - href="https://staging.bsky.app" - text="staging.bsky.app" + href="https://bsky.app" + text="bsky.app" /> . </Text> diff --git a/src/view/com/modals/ContentLanguagesSettings.tsx b/src/view/com/modals/ContentLanguagesSettings.tsx index 0c750fe0e..700f1cbcb 100644 --- a/src/view/com/modals/ContentLanguagesSettings.tsx +++ b/src/view/com/modals/ContentLanguagesSettings.tsx @@ -41,8 +41,8 @@ export function Component({}: {}) { <View testID="contentLanguagesModal" style={[pal.view, styles.container]}> <Text style={[pal.text, styles.title]}>Content Languages</Text> <Text style={[pal.text, styles.description]}> - Which languages would you like to see in the What's Hot feed? (Leave - them all unchecked to see any language.) + Which languages would you like to see in the your feed? (Leave them all + unchecked to see any language.) </Text> <ScrollView style={styles.scrollContainer}> {languages.map(lang => ( diff --git a/src/view/com/modals/CreateOrEditMuteList.tsx b/src/view/com/modals/CreateOrEditMuteList.tsx index 0c13f243a..736deae74 100644 --- a/src/view/com/modals/CreateOrEditMuteList.tsx +++ b/src/view/com/modals/CreateOrEditMuteList.tsx @@ -143,6 +143,7 @@ export function Component({ <Text style={[styles.label, pal.text]}>List Avatar</Text> <View style={[styles.avi, {borderColor: pal.colors.background}]}> <UserAvatar + type="list" size={80} avatar={avatar} onSelectNewAvatar={onSelectNewAvatar} diff --git a/src/view/com/modals/EditImage.tsx b/src/view/com/modals/EditImage.tsx index eab472a78..09ae01943 100644 --- a/src/view/com/modals/EditImage.tsx +++ b/src/view/com/modals/EditImage.tsx @@ -118,9 +118,9 @@ export const Component = observer(function ({image, gallery}: Props) { ) useEffect(() => { - image.prev = image.compressed + image.prev = image.cropped image.prevAttributes = image.attributes - image.resetCompressed() + image.resetCropped() }, [image]) const onCloseModal = useCallback(() => { @@ -152,7 +152,7 @@ export const Component = observer(function ({image, gallery}: Props) { : {}), }) - image.prev = image.compressed + image.prev = image.cropped image.prevAttributes = image.attributes onCloseModal() }, [altText, image, position, scale, onCloseModal]) @@ -168,8 +168,7 @@ export const Component = observer(function ({image, gallery}: Props) { } }, []) - // Prevents preliminary flash when transformations are being applied - if (image.compressed === undefined) { + if (image.cropped === undefined) { return null } @@ -177,7 +176,7 @@ export const Component = observer(function ({image, gallery}: Props) { windowDimensions.width > 500 ? 410 : windowDimensions.width - 80 const sideLength = isDesktopWeb ? 300 : computedWidth - const dimensions = image.getDisplayDimensions(aspectRatio, sideLength) + const dimensions = image.getResizedDimensions(aspectRatio, sideLength) const imgContainerStyles = {width: sideLength, height: sideLength} const imgControlStyles = { @@ -196,7 +195,7 @@ export const Component = observer(function ({image, gallery}: Props) { <ImageEditor ref={editorRef} style={styles.imgEditor} - image={image.compressed.path} + image={image.cropped.path} scale={scale} border={0} position={position} diff --git a/src/view/com/modals/Modal.tsx b/src/view/com/modals/Modal.tsx index 08ee74b02..1043db20e 100644 --- a/src/view/com/modals/Modal.tsx +++ b/src/view/com/modals/Modal.tsx @@ -15,6 +15,7 @@ import * as RepostModal from './Repost' import * as CreateOrEditMuteListModal from './CreateOrEditMuteList' import * as ListAddRemoveUserModal from './ListAddRemoveUser' import * as AltImageModal from './AltImage' +import * as EditImageModal from './AltImage' import * as ReportAccountModal from './ReportAccount' import * as DeleteAccountModal from './DeleteAccount' import * as ChangeHandleModal from './ChangeHandle' @@ -83,6 +84,9 @@ export const ModalsContainer = observer(function ModalsContainer() { } else if (activeModal?.name === 'alt-text-image') { snapPoints = AltImageModal.snapPoints element = <AltImageModal.Component {...activeModal} /> + } else if (activeModal?.name === 'edit-image') { + snapPoints = AltImageModal.snapPoints + element = <EditImageModal.Component {...activeModal} /> } else if (activeModal?.name === 'change-handle') { snapPoints = ChangeHandleModal.snapPoints element = <ChangeHandleModal.Component {...activeModal} /> @@ -119,7 +123,7 @@ export const ModalsContainer = observer(function ModalsContainer() { snapPoints={snapPoints} index={store.shell.isModalActive ? 0 : -1} enablePanDownToClose - keyboardBehavior="extend" + android_keyboardInputMode="adjustResize" keyboardBlurBehavior="restore" backdropComponent={ store.shell.isModalActive ? createCustomBackdrop(onClose) : undefined diff --git a/src/view/com/modals/crop-image/CropImage.tsx b/src/view/com/modals/crop-image/CropImage.tsx deleted file mode 100644 index 9ac3f277f..000000000 --- a/src/view/com/modals/crop-image/CropImage.tsx +++ /dev/null @@ -1,11 +0,0 @@ -/** - * NOTE - * This modal is used only in the web build - * Native uses a third-party library - */ - -export const snapPoints = ['0%'] - -export function Component() { - return null -} diff --git a/src/view/com/notifications/Feed.tsx b/src/view/com/notifications/Feed.tsx index 50bdc5dc9..d457d7136 100644 --- a/src/view/com/notifications/Feed.tsx +++ b/src/view/com/notifications/Feed.tsx @@ -154,6 +154,7 @@ export const Feed = observer(function Feed({ onEndReached={onEndReached} onEndReachedThreshold={0.6} onScroll={onScroll} + scrollEventThrottle={100} contentContainerStyle={s.contentContainer} /> ) : null} diff --git a/src/view/com/pager/DraggableScrollView.tsx b/src/view/com/pager/DraggableScrollView.tsx new file mode 100644 index 000000000..4b7396eaa --- /dev/null +++ b/src/view/com/pager/DraggableScrollView.tsx @@ -0,0 +1,15 @@ +import {useDraggableScroll} from 'lib/hooks/useDraggableScrollView' +import React, {ComponentProps} from 'react' +import {ScrollView} from 'react-native' + +export const DraggableScrollView = React.forwardRef< + ScrollView, + ComponentProps<typeof ScrollView> +>(function DraggableScrollView(props, ref) { + const {refs} = useDraggableScroll<ScrollView>({ + outerRef: ref, + cursor: 'grab', // optional, default + }) + + return <ScrollView ref={refs} horizontal {...props} /> +}) diff --git a/src/view/com/pager/FeedsTabBar.web.tsx b/src/view/com/pager/FeedsTabBar.web.tsx index 0fc1b7310..0df915950 100644 --- a/src/view/com/pager/FeedsTabBar.web.tsx +++ b/src/view/com/pager/FeedsTabBar.web.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import React, {useMemo} from 'react' import {Animated, StyleSheet} from 'react-native' import {observer} from 'mobx-react-lite' import {TabBar} from 'view/com/pager/TabBar' @@ -27,6 +27,10 @@ const FeedsTabBarDesktop = observer( props: RenderTabBarFnProps & {testID?: string; onPressSelected: () => void}, ) => { const store = useStores() + const items = useMemo( + () => ['Following', ...store.me.savedFeeds.pinnedFeedNames], + [store.me.savedFeeds.pinnedFeedNames], + ) const pal = usePalette('default') const interp = useAnimatedValue(0) @@ -44,13 +48,14 @@ const FeedsTabBarDesktop = observer( {translateY: Animated.multiply(interp, -100)}, ], } + return ( // @ts-ignore the type signature for transform wrong here, translateX and translateY need to be in separate objects -prf <Animated.View style={[pal.view, styles.tabBar, transform]}> <TabBar + key={items.join(',')} {...props} - items={['Following', "What's hot"]} - indicatorPosition="bottom" + items={items} indicatorColor={pal.colors.link} /> </Animated.View> diff --git a/src/view/com/pager/FeedsTabBarMobile.tsx b/src/view/com/pager/FeedsTabBarMobile.tsx index 725c44603..9c7138815 100644 --- a/src/view/com/pager/FeedsTabBarMobile.tsx +++ b/src/view/com/pager/FeedsTabBarMobile.tsx @@ -1,12 +1,17 @@ -import React from 'react' -import {Animated, StyleSheet, TouchableOpacity} from 'react-native' +import React, {useMemo} from 'react' +import {Animated, StyleSheet, TouchableOpacity, View} from 'react-native' import {observer} from 'mobx-react-lite' import {TabBar} from 'view/com/pager/TabBar' import {RenderTabBarFnProps} from 'view/com/pager/Pager' -import {UserAvatar} from '../util/UserAvatar' import {useStores} from 'state/index' import {usePalette} from 'lib/hooks/usePalette' import {useAnimatedValue} from 'lib/hooks/useAnimatedValue' +import {useColorSchemeStyle} from 'lib/hooks/useColorSchemeStyle' +import {Link} from '../util/Link' +import {Text} from '../util/text/Text' +import {CogIcon} from 'lib/icons' +import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' +import {s} from 'lib/styles' export const FeedsTabBar = observer( ( @@ -28,25 +33,51 @@ export const FeedsTabBar = observer( transform: [{translateY: Animated.multiply(interp, -100)}], } + const brandBlue = useColorSchemeStyle(s.brandBlue, s.blue3) + const onPressAvi = React.useCallback(() => { store.shell.openDrawer() }, [store]) + const items = useMemo( + () => ['Following', ...store.me.savedFeeds.pinnedFeedNames], + [store.me.savedFeeds.pinnedFeedNames], + ) + return ( <Animated.View style={[pal.view, pal.border, styles.tabBar, transform]}> - <TouchableOpacity - testID="viewHeaderDrawerBtn" - style={styles.tabBarAvi} - onPress={onPressAvi} - accessibilityRole="button" - accessibilityLabel="Open navigation" - accessibilityHint="Access profile and other navigation links"> - <UserAvatar avatar={store.me.avatar} size={30} /> - </TouchableOpacity> + <View style={[pal.view, styles.topBar]}> + <View style={[pal.view]}> + <TouchableOpacity + testID="viewHeaderDrawerBtn" + onPress={onPressAvi} + accessibilityRole="button" + accessibilityLabel="Open navigation" + accessibilityHint="Access profile and other navigation links" + hitSlop={10}> + <FontAwesomeIcon + icon="bars" + size={18} + color={pal.colors.textLight} + /> + </TouchableOpacity> + </View> + <Text style={[brandBlue, s.bold, styles.title]}>Bluesky</Text> + <View style={[pal.view]}> + <Link + href="/settings/saved-feeds" + hitSlop={10} + accessibilityRole="button" + accessibilityLabel="Edit Saved Feeds" + accessibilityHint="Opens screen to edit Saved Feeds"> + <CogIcon size={21} strokeWidth={2} style={pal.textLight} /> + </Link> + </View> + </View> <TabBar + key={items.join(',')} {...props} - items={['Following', "What's hot"]} - indicatorPosition="bottom" + items={items} indicatorColor={pal.colors.link} /> </Animated.View> @@ -61,13 +92,20 @@ const styles = StyleSheet.create({ left: 0, right: 0, top: 0, + flexDirection: 'column', + alignItems: 'center', + borderBottomWidth: 1, + }, + topBar: { flexDirection: 'row', + justifyContent: 'space-between', alignItems: 'center', paddingHorizontal: 18, - borderBottomWidth: 1, + paddingTop: 8, + paddingBottom: 2, + width: '100%', }, - tabBarAvi: { - marginTop: 1, - marginRight: 18, + title: { + fontSize: 21, }, }) diff --git a/src/view/com/pager/Pager.tsx b/src/view/com/pager/Pager.tsx index 34747db6d..e2c8bf6d2 100644 --- a/src/view/com/pager/Pager.tsx +++ b/src/view/com/pager/Pager.tsx @@ -1,16 +1,17 @@ -import React from 'react' +import React, {forwardRef} from 'react' import {Animated, View} from 'react-native' import PagerView, {PagerViewOnPageSelectedEvent} from 'react-native-pager-view' -import {useAnimatedValue} from 'lib/hooks/useAnimatedValue' import {s} from 'lib/styles' export type PageSelectedEvent = PagerViewOnPageSelectedEvent const AnimatedPagerView = Animated.createAnimatedComponent(PagerView) +export interface PagerRef { + setPage: (index: number) => void +} + export interface RenderTabBarFnProps { selectedPage: number - position: Animated.Value - offset: Animated.Value onSelect?: (index: number) => void } export type RenderTabBarFn = (props: RenderTabBarFnProps) => JSX.Element @@ -22,68 +23,60 @@ interface Props { onPageSelected?: (index: number) => void testID?: string } -export const Pager = ({ - children, - tabBarPosition = 'top', - initialPage = 0, - renderTabBar, - onPageSelected, - testID, -}: React.PropsWithChildren<Props>) => { - const [selectedPage, setSelectedPage] = React.useState(0) - const position = useAnimatedValue(0) - const offset = useAnimatedValue(0) - const pagerView = React.useRef<PagerView>() +export const Pager = forwardRef<PagerRef, React.PropsWithChildren<Props>>( + ( + { + children, + tabBarPosition = 'top', + initialPage = 0, + renderTabBar, + onPageSelected, + testID, + }: React.PropsWithChildren<Props>, + ref, + ) => { + const [selectedPage, setSelectedPage] = React.useState(0) + const pagerView = React.useRef<PagerView>() - const onPageSelectedInner = React.useCallback( - (e: PageSelectedEvent) => { - setSelectedPage(e.nativeEvent.position) - onPageSelected?.(e.nativeEvent.position) - }, - [setSelectedPage, onPageSelected], - ) + React.useImperativeHandle(ref, () => ({ + setPage: (index: number) => pagerView.current?.setPage(index), + })) - const onTabBarSelect = React.useCallback( - (index: number) => { - pagerView.current?.setPage(index) - }, - [pagerView], - ) + const onPageSelectedInner = React.useCallback( + (e: PageSelectedEvent) => { + setSelectedPage(e.nativeEvent.position) + onPageSelected?.(e.nativeEvent.position) + }, + [setSelectedPage, onPageSelected], + ) - return ( - <View testID={testID}> - {tabBarPosition === 'top' && - renderTabBar({ - selectedPage, - position, - offset, - onSelect: onTabBarSelect, - })} - <AnimatedPagerView - ref={pagerView} - style={s.h100pct} - initialPage={initialPage} - onPageSelected={onPageSelectedInner} - onPageScroll={Animated.event( - [ - { - nativeEvent: { - position: position, - offset: offset, - }, - }, - ], - {useNativeDriver: true}, - )}> - {children} - </AnimatedPagerView> - {tabBarPosition === 'bottom' && - renderTabBar({ - selectedPage, - position, - offset, - onSelect: onTabBarSelect, - })} - </View> - ) -} + const onTabBarSelect = React.useCallback( + (index: number) => { + pagerView.current?.setPage(index) + }, + [pagerView], + ) + + return ( + <View testID={testID}> + {tabBarPosition === 'top' && + renderTabBar({ + selectedPage, + onSelect: onTabBarSelect, + })} + <AnimatedPagerView + ref={pagerView} + style={s.h100pct} + initialPage={initialPage} + onPageSelected={onPageSelectedInner}> + {children} + </AnimatedPagerView> + {tabBarPosition === 'bottom' && + renderTabBar({ + selectedPage, + onSelect: onTabBarSelect, + })} + </View> + ) + }, +) diff --git a/src/view/com/pager/Pager.web.tsx b/src/view/com/pager/Pager.web.tsx index 107497f6f..7be2b11ec 100644 --- a/src/view/com/pager/Pager.web.tsx +++ b/src/view/com/pager/Pager.web.tsx @@ -1,12 +1,9 @@ import React from 'react' -import {Animated, View} from 'react-native' -import {useAnimatedValue} from 'lib/hooks/useAnimatedValue' +import {View} from 'react-native' import {s} from 'lib/styles' export interface RenderTabBarFnProps { selectedPage: number - position: Animated.Value - offset: Animated.Value onSelect?: (index: number) => void } export type RenderTabBarFn = (props: RenderTabBarFnProps) => JSX.Element @@ -17,53 +14,51 @@ interface Props { renderTabBar: RenderTabBarFn onPageSelected?: (index: number) => void } -export const Pager = ({ - children, - tabBarPosition = 'top', - initialPage = 0, - renderTabBar, - onPageSelected, -}: React.PropsWithChildren<Props>) => { - const [selectedPage, setSelectedPage] = React.useState(initialPage) - const position = useAnimatedValue(0) - const offset = useAnimatedValue(0) +export const Pager = React.forwardRef( + ( + { + children, + tabBarPosition = 'top', + initialPage = 0, + renderTabBar, + onPageSelected, + }: React.PropsWithChildren<Props>, + ref, + ) => { + const [selectedPage, setSelectedPage] = React.useState(initialPage) - const onTabBarSelect = React.useCallback( - (index: number) => { - setSelectedPage(index) - onPageSelected?.(index) - Animated.timing(position, { - toValue: index, - duration: 200, - useNativeDriver: true, - }).start() - }, - [setSelectedPage, onPageSelected, position], - ) + React.useImperativeHandle(ref, () => ({ + setPage: (index: number) => setSelectedPage(index), + })) - return ( - <View> - {tabBarPosition === 'top' && - renderTabBar({ - selectedPage, - position, - offset, - onSelect: onTabBarSelect, - })} - {React.Children.map(children, (child, i) => ( - <View - style={selectedPage === i ? undefined : s.hidden} - key={`page-${i}`}> - {child} - </View> - ))} - {tabBarPosition === 'bottom' && - renderTabBar({ - selectedPage, - position, - offset, - onSelect: onTabBarSelect, - })} - </View> - ) -} + const onTabBarSelect = React.useCallback( + (index: number) => { + setSelectedPage(index) + onPageSelected?.(index) + }, + [setSelectedPage, onPageSelected], + ) + + return ( + <View> + {tabBarPosition === 'top' && + renderTabBar({ + selectedPage, + onSelect: onTabBarSelect, + })} + {React.Children.map(children, (child, i) => ( + <View + style={selectedPage === i ? undefined : s.hidden} + key={`page-${i}`}> + {child} + </View> + ))} + {tabBarPosition === 'bottom' && + renderTabBar({ + selectedPage, + onSelect: onTabBarSelect, + })} + </View> + ) + }, +) diff --git a/src/view/com/pager/TabBar.tsx b/src/view/com/pager/TabBar.tsx index a0b72a93f..d7121fde9 100644 --- a/src/view/com/pager/TabBar.tsx +++ b/src/view/com/pager/TabBar.tsx @@ -1,22 +1,22 @@ -import React, {createRef, useState, useMemo, useRef} from 'react' -import {Animated, StyleSheet, View} from 'react-native' +import React, { + useRef, + createRef, + useMemo, + useEffect, + useState, + useCallback, +} from 'react' +import {StyleSheet, View, ScrollView} from 'react-native' import {Text} from '../util/text/Text' import {PressableWithHover} from '../util/PressableWithHover' import {usePalette} from 'lib/hooks/usePalette' -import {isDesktopWeb} from 'platform/detection' - -interface Layout { - x: number - width: number -} +import {isDesktopWeb, isMobileWeb} from 'platform/detection' +import {DraggableScrollView} from './DraggableScrollView' export interface TabBarProps { testID?: string selectedPage: number items: string[] - position: Animated.Value - offset: Animated.Value - indicatorPosition?: 'top' | 'bottom' indicatorColor?: string onSelect?: (index: number) => void onPressSelected?: () => void @@ -26,105 +26,81 @@ export function TabBar({ testID, selectedPage, items, - position, - offset, - indicatorPosition = 'bottom', indicatorColor, onSelect, onPressSelected, }: TabBarProps) { const pal = usePalette('default') - const [itemLayouts, setItemLayouts] = useState<Layout[]>( - items.map(() => ({x: 0, width: 0})), - ) + const scrollElRef = useRef<ScrollView>(null) + const [itemXs, setItemXs] = useState<number[]>([]) const itemRefs = useMemo( () => Array.from({length: items.length}).map(() => createRef<View>()), [items.length], ) - const panX = Animated.add(position, offset) - const containerRef = useRef<View>(null) + const indicatorStyle = useMemo( + () => ({borderBottomColor: indicatorColor || pal.colors.link}), + [indicatorColor, pal], + ) - const indicatorStyle = { - backgroundColor: indicatorColor || pal.colors.link, - bottom: - indicatorPosition === 'bottom' ? (isDesktopWeb ? 0 : -1) : undefined, - top: indicatorPosition === 'top' ? (isDesktopWeb ? 0 : -1) : undefined, - transform: [ - { - translateX: panX.interpolate({ - inputRange: items.map((_item, i) => i), - outputRange: itemLayouts.map(l => l.x + l.width / 2), - }), - }, - { - scaleX: panX.interpolate({ - inputRange: items.map((_item, i) => i), - outputRange: itemLayouts.map(l => l.width), - }), - }, - ], - } + useEffect(() => { + scrollElRef.current?.scrollTo({x: itemXs[selectedPage] || 0}) + }, [scrollElRef, itemXs, selectedPage]) + + const onPressItem = useCallback( + (index: number) => { + onSelect?.(index) + if (index === selectedPage) { + onPressSelected?.() + } + }, + [onSelect, onPressSelected, selectedPage], + ) const onLayout = React.useCallback(() => { const promises = [] for (let i = 0; i < items.length; i++) { promises.push( - new Promise<Layout>(resolve => { - if (!containerRef.current || !itemRefs[i].current) { - return resolve({x: 0, width: 0}) + new Promise<number>(resolve => { + if (!itemRefs[i].current) { + return resolve(0) } - itemRefs[i].current?.measureLayout( - containerRef.current, - (x: number, _y: number, width: number) => { - resolve({x, width}) - }, - ) + itemRefs[i].current?.measure((x: number) => resolve(x)) }), ) } - Promise.all(promises).then((layouts: Layout[]) => { - setItemLayouts(layouts) + Promise.all(promises).then((Xs: number[]) => { + setItemXs(Xs) }) - }, [containerRef, itemRefs, setItemLayouts, items.length]) - - const onPressItem = React.useCallback( - (index: number) => { - onSelect?.(index) - if (index === selectedPage) { - onPressSelected?.() - } - }, - [onSelect, onPressSelected, selectedPage], - ) + }, [itemRefs, setItemXs, items.length]) return ( - <View - testID={testID} - style={[pal.view, styles.outer]} - onLayout={onLayout} - ref={containerRef}> - <Animated.View style={[styles.indicator, indicatorStyle]} /> - {items.map((item, i) => { - const selected = i === selectedPage - return ( - <PressableWithHover - ref={itemRefs[i]} - key={item} - style={ - indicatorPosition === 'top' ? styles.itemTop : styles.itemBottom - } - hoverStyle={pal.viewLight} - onPress={() => onPressItem(i)}> - <Text - type="xl-bold" - testID={testID ? `${testID}-${item}` : undefined} - style={selected ? pal.text : pal.textLight}> - {item} - </Text> - </PressableWithHover> - ) - })} + <View testID={testID} style={[pal.view, styles.outer]}> + <DraggableScrollView + horizontal={true} + showsHorizontalScrollIndicator={false} + ref={scrollElRef} + contentContainerStyle={styles.contentContainer} + onLayout={onLayout}> + {items.map((item, i) => { + const selected = i === selectedPage + return ( + <PressableWithHover + ref={itemRefs[i]} + key={item} + style={[styles.item, selected && indicatorStyle]} + hoverStyle={pal.viewLight} + onPress={() => onPressItem(i)}> + <Text + type={isDesktopWeb ? 'xl-bold' : 'lg-bold'} + testID={testID ? `${testID}-${item}` : undefined} + style={selected ? pal.text : pal.textLight}> + {item} + </Text> + </PressableWithHover> + ) + })} + </DraggableScrollView> </View> ) } @@ -133,45 +109,39 @@ const styles = isDesktopWeb ? StyleSheet.create({ outer: { flexDirection: 'row', - paddingHorizontal: 18, + width: 598, }, - itemTop: { - paddingTop: 16, - paddingBottom: 14, - paddingHorizontal: 12, + contentContainer: { + columnGap: 8, + marginLeft: 14, + paddingRight: 14, + backgroundColor: 'transparent', }, - itemBottom: { + item: { paddingTop: 14, - paddingBottom: 16, - paddingHorizontal: 12, - }, - indicator: { - position: 'absolute', - left: 0, - width: 1, - height: 3, - zIndex: 1, + paddingBottom: 12, + paddingHorizontal: 10, + borderBottomWidth: 3, + borderBottomColor: 'transparent', }, }) : StyleSheet.create({ outer: { + flex: 1, flexDirection: 'row', - paddingHorizontal: 14, + backgroundColor: 'transparent', }, - itemTop: { + contentContainer: { + columnGap: isMobileWeb ? 0 : 20, + marginLeft: isMobileWeb ? 0 : 18, + paddingRight: isMobileWeb ? 0 : 36, + backgroundColor: 'transparent', + }, + item: { paddingTop: 10, paddingBottom: 10, - marginRight: 24, - }, - itemBottom: { - paddingTop: 8, - paddingBottom: 12, - marginRight: 24, - }, - indicator: { - position: 'absolute', - left: 0, - width: 1, - height: 3, + paddingHorizontal: isMobileWeb ? 8 : 0, + borderBottomWidth: 3, + borderBottomColor: 'transparent', }, }) diff --git a/src/view/com/post-thread/PostThreadItem.tsx b/src/view/com/post-thread/PostThreadItem.tsx index 084e30a25..4ba2e1a40 100644 --- a/src/view/com/post-thread/PostThreadItem.tsx +++ b/src/view/com/post-thread/PostThreadItem.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import React, {useCallback, useMemo} from 'react' import {observer} from 'mobx-react-lite' import {Linking, StyleSheet, View} from 'react-native' import Clipboard from '@react-native-clipboard/clipboard' @@ -99,7 +99,11 @@ export const PostThreadItem = observer(function PostThreadItem({ const onOpenTranslate = React.useCallback(() => { Linking.openURL( - encodeURI(`https://translate.google.com/#auto|en|${record?.text || ''}`), + encodeURI( + `https://translate.google.com/?sl=auto&tl=en&text=${ + record?.text || '' + }`, + ), ) }, [record]) @@ -129,6 +133,40 @@ export const PostThreadItem = observer(function PostThreadItem({ ) }, [item, store]) + const accessibilityActions = useMemo( + () => [ + { + name: 'reply', + label: 'Reply', + }, + { + name: 'repost', + label: item.post.viewer?.repost ? 'Undo repost' : 'Repost', + }, + {name: 'like', label: item.post.viewer?.like ? 'Unlike' : 'Like'}, + ], + [item.post.viewer?.like, item.post.viewer?.repost], + ) + + const onAccessibilityAction = useCallback( + event => { + switch (event.nativeEvent.actionName) { + case 'like': + onPressToggleLike() + break + case 'reply': + onPressReply() + break + case 'repost': + onPressToggleRepost() + break + default: + break + } + }, + [onPressReply, onPressToggleLike, onPressToggleRepost], + ) + if (!record) { return <ErrorMessage message="Invalid or unsupported post record" /> } @@ -150,7 +188,9 @@ export const PostThreadItem = observer(function PostThreadItem({ <PostHider testID={`postThreadItem-by-${item.post.author.handle}`} style={[styles.outer, styles.outerHighlighted, pal.border, pal.view]} - moderation={item.moderation.thread}> + moderation={item.moderation.thread} + accessibilityActions={accessibilityActions} + onAccessibilityAction={onAccessibilityAction}> <View style={styles.layout}> <View style={styles.layoutAvi}> <Link @@ -320,7 +360,9 @@ export const PostThreadItem = observer(function PostThreadItem({ pal.view, item._showParentReplyLine && styles.noTopBorder, ]} - moderation={item.moderation.thread}> + moderation={item.moderation.thread} + accessibilityActions={accessibilityActions} + onAccessibilityAction={onAccessibilityAction}> {item._showParentReplyLine && ( <View style={[ diff --git a/src/view/com/post/Post.tsx b/src/view/com/post/Post.tsx index 614c5ea77..a1f8298ff 100644 --- a/src/view/com/post/Post.tsx +++ b/src/view/com/post/Post.tsx @@ -1,4 +1,4 @@ -import React, {useState, useEffect} from 'react' +import React, {useCallback, useEffect, useMemo, useState} from 'react' import { ActivityIndicator, Linking, @@ -170,7 +170,9 @@ const PostLoaded = observer( const onOpenTranslate = React.useCallback(() => { Linking.openURL( encodeURI( - `https://translate.google.com/#auto|en|${record?.text || ''}`, + `https://translate.google.com/?sl=auto&tl=en&text=${ + record?.text || '' + }`, ), ) }, [record]) @@ -203,11 +205,47 @@ const PostLoaded = observer( ) }, [item, setDeleted, store]) + const accessibilityActions = useMemo( + () => [ + { + name: 'reply', + label: 'Reply', + }, + { + name: 'repost', + label: item.post.viewer?.repost ? 'Undo repost' : 'Repost', + }, + {name: 'like', label: item.post.viewer?.like ? 'Unlike' : 'Like'}, + ], + [item.post.viewer?.like, item.post.viewer?.repost], + ) + + const onAccessibilityAction = useCallback( + event => { + switch (event.nativeEvent.actionName) { + case 'like': + onPressToggleLike() + break + case 'reply': + onPressReply() + break + case 'repost': + onPressToggleRepost() + break + default: + break + } + }, + [onPressReply, onPressToggleLike, onPressToggleRepost], + ) + return ( <PostHider href={itemHref} style={[styles.outer, pal.view, pal.border, style]} - moderation={item.moderation.list}> + moderation={item.moderation.list} + accessibilityActions={accessibilityActions} + onAccessibilityAction={onAccessibilityAction}> {showReplyLine && <View style={styles.replyLine} />} <View style={styles.layout}> <View style={styles.layoutAvi}> diff --git a/src/view/com/posts/WhatsHotEmptyState.tsx b/src/view/com/posts/CustomFeedEmptyState.tsx index ade94ca3f..e83a94f03 100644 --- a/src/view/com/posts/WhatsHotEmptyState.tsx +++ b/src/view/com/posts/CustomFeedEmptyState.tsx @@ -1,5 +1,6 @@ import React from 'react' import {StyleSheet, View} from 'react-native' +import {useNavigation} from '@react-navigation/native' import { FontAwesomeIcon, FontAwesomeIconStyle, @@ -7,18 +8,24 @@ import { import {Text} from '../util/text/Text' import {Button} from '../util/forms/Button' import {MagnifyingGlassIcon} from 'lib/icons' -import {useStores} from 'state/index' +import {NavigationProp} from 'lib/routes/types' import {usePalette} from 'lib/hooks/usePalette' import {s} from 'lib/styles' +import {isWeb} from 'platform/detection' -export function WhatsHotEmptyState() { +export function CustomFeedEmptyState() { const pal = usePalette('default') const palInverted = usePalette('inverted') - const store = useStores() + const navigation = useNavigation<NavigationProp>() - const onPressSettings = React.useCallback(() => { - store.shell.openModal({name: 'content-languages-settings'}) - }, [store]) + const onPressFindAccounts = React.useCallback(() => { + if (isWeb) { + navigation.navigate('Search', {}) + } else { + navigation.navigate('SearchTab') + navigation.popToTop() + } + }, [navigation]) return ( <View style={styles.emptyContainer}> @@ -26,12 +33,15 @@ export function WhatsHotEmptyState() { <MagnifyingGlassIcon style={[styles.emptyIcon, pal.text]} size={62} /> </View> <Text type="xl-medium" style={[s.textCenter, pal.text]}> - Your What's Hot feed is empty! This is because there aren't enough users - posting in your selected language. + This feed is empty! You may need to follow more users or tune your + language settings. </Text> - <Button type="inverted" style={styles.emptyBtn} onPress={onPressSettings}> + <Button + type="inverted" + style={styles.emptyBtn} + onPress={onPressFindAccounts}> <Text type="lg-medium" style={palInverted.text}> - Update my settings + Find accounts to follow </Text> <FontAwesomeIcon icon="angle-right" diff --git a/src/view/com/posts/Feed.tsx b/src/view/com/posts/Feed.tsx index 998cfe0c9..8206ca509 100644 --- a/src/view/com/posts/Feed.tsx +++ b/src/view/com/posts/Feed.tsx @@ -18,6 +18,7 @@ import {OnScrollCb} from 'lib/hooks/useOnMainScroll' import {s} from 'lib/styles' import {useAnalytics} from 'lib/analytics' import {usePalette} from 'lib/hooks/usePalette' +import {useTheme} from 'lib/ThemeContext' const LOADING_ITEM = {_reactKey: '__loading__'} const EMPTY_FEED_ITEM = {_reactKey: '__empty__'} @@ -31,9 +32,12 @@ export const Feed = observer(function Feed({ scrollElRef, onPressTryAgain, onScroll, + scrollEventThrottle, renderEmptyState, testID, headerOffset = 0, + ListHeaderComponent, + extraData, }: { feed: PostsFeedModel style?: StyleProp<ViewStyle> @@ -41,11 +45,15 @@ export const Feed = observer(function Feed({ scrollElRef?: MutableRefObject<FlatList<any> | null> onPressTryAgain?: () => void onScroll?: OnScrollCb + scrollEventThrottle?: number renderEmptyState?: () => JSX.Element testID?: string headerOffset?: number + ListHeaderComponent?: () => JSX.Element + extraData?: any }) { const pal = usePalette('default') + const theme = useTheme() const {track} = useAnalytics() const [isRefreshing, setIsRefreshing] = React.useState(false) @@ -163,6 +171,7 @@ export const Feed = observer(function Feed({ keyExtractor={item => item._reactKey} renderItem={renderItem} ListFooterComponent={FeedFooter} + ListHeaderComponent={ListHeaderComponent} refreshControl={ <RefreshControl refreshing={isRefreshing} @@ -175,10 +184,13 @@ export const Feed = observer(function Feed({ contentContainerStyle={s.contentContainer} style={{paddingTop: headerOffset}} onScroll={onScroll} + scrollEventThrottle={scrollEventThrottle} + indicatorStyle={theme.colorScheme === 'dark' ? 'white' : 'black'} onEndReached={onEndReached} onEndReachedThreshold={0.6} removeClippedSubviews={true} contentOffset={{x: 0, y: headerOffset * -1}} + extraData={extraData} // @ts-ignore our .web version only -prf desktopFixedHeight /> diff --git a/src/view/com/posts/FeedItem.tsx b/src/view/com/posts/FeedItem.tsx index fa6131d61..413300bbc 100644 --- a/src/view/com/posts/FeedItem.tsx +++ b/src/view/com/posts/FeedItem.tsx @@ -1,4 +1,4 @@ -import React, {useMemo, useState} from 'react' +import React, {useCallback, useMemo, useState} from 'react' import {observer} from 'mobx-react-lite' import {Linking, StyleSheet, View} from 'react-native' import Clipboard from '@react-native-clipboard/clipboard' @@ -99,7 +99,11 @@ export const FeedItem = observer(function ({ const onOpenTranslate = React.useCallback(() => { Linking.openURL( - encodeURI(`https://translate.google.com/#auto|en|${record?.text || ''}`), + encodeURI( + `https://translate.google.com/?sl=auto&tl=en&text=${ + record?.text || '' + }`, + ), ) }, [record]) @@ -154,12 +158,48 @@ export const FeedItem = observer(function ({ moderation = {behavior: ModerationBehaviorCode.Show} } + const accessibilityActions = useMemo( + () => [ + { + name: 'reply', + label: 'Reply', + }, + { + name: 'repost', + label: item.post.viewer?.repost ? 'Undo repost' : 'Repost', + }, + {name: 'like', label: item.post.viewer?.like ? 'Unlike' : 'Like'}, + ], + [item.post.viewer?.like, item.post.viewer?.repost], + ) + + const onAccessibilityAction = useCallback( + event => { + switch (event.nativeEvent.actionName) { + case 'like': + onPressToggleLike() + break + case 'reply': + onPressReply() + break + case 'repost': + onPressToggleRepost() + break + default: + break + } + }, + [onPressReply, onPressToggleLike, onPressToggleRepost], + ) + return ( <PostHider testID={`feedItem-by-${item.post.author.handle}`} style={outerStyles} href={itemHref} - moderation={moderation}> + moderation={moderation} + accessibilityActions={accessibilityActions} + onAccessibilityAction={onAccessibilityAction}> {isThreadChild && ( <View style={[styles.topReplyLine, {borderColor: pal.colors.replyLine}]} diff --git a/src/view/com/posts/FeedSlice.tsx b/src/view/com/posts/FeedSlice.tsx index 824fd0c4b..888466200 100644 --- a/src/view/com/posts/FeedSlice.tsx +++ b/src/view/com/posts/FeedSlice.tsx @@ -1,6 +1,6 @@ import React from 'react' import {StyleSheet, View} from 'react-native' -import {PostsFeedSliceModel} from 'state/models/feeds/posts' +import {PostsFeedSliceModel} from 'state/models/feeds/post' import {AtUri} from '@atproto/api' import {Link} from '../util/Link' import {Text} from '../util/text/Text' diff --git a/src/view/com/posts/FollowingEmptyState.tsx b/src/view/com/posts/FollowingEmptyState.tsx index b37298179..d1843900b 100644 --- a/src/view/com/posts/FollowingEmptyState.tsx +++ b/src/view/com/posts/FollowingEmptyState.tsx @@ -11,6 +11,7 @@ import {MagnifyingGlassIcon} from 'lib/icons' import {NavigationProp} from 'lib/routes/types' import {usePalette} from 'lib/hooks/usePalette' import {s} from 'lib/styles' +import {isWeb} from 'platform/detection' export function FollowingEmptyState() { const pal = usePalette('default') @@ -18,8 +19,12 @@ export function FollowingEmptyState() { const navigation = useNavigation<NavigationProp>() const onPressFindAccounts = React.useCallback(() => { - navigation.navigate('SearchTab') - navigation.popToTop() + if (isWeb) { + navigation.navigate('Search', {}) + } else { + navigation.navigate('SearchTab') + navigation.popToTop() + } }, [navigation]) return ( diff --git a/src/view/com/posts/MultiFeed.tsx b/src/view/com/posts/MultiFeed.tsx new file mode 100644 index 000000000..db353909c --- /dev/null +++ b/src/view/com/posts/MultiFeed.tsx @@ -0,0 +1,246 @@ +import React, {MutableRefObject} from 'react' +import {observer} from 'mobx-react-lite' +import { + ActivityIndicator, + RefreshControl, + StyleProp, + StyleSheet, + View, + ViewStyle, +} from 'react-native' +import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' +import {FlatList} from '../util/Views' +import {PostFeedLoadingPlaceholder} from '../util/LoadingPlaceholder' +import {ErrorMessage} from '../util/error/ErrorMessage' +import {PostsMultiFeedModel, MultiFeedItem} from 'state/models/feeds/multi-feed' +import {FeedSlice} from './FeedSlice' +import {Text} from '../util/text/Text' +import {Link} from '../util/Link' +import {UserAvatar} from '../util/UserAvatar' +import {OnScrollCb} from 'lib/hooks/useOnMainScroll' +import {s} from 'lib/styles' +import {useAnalytics} from 'lib/analytics' +import {usePalette} from 'lib/hooks/usePalette' +import {useTheme} from 'lib/ThemeContext' +import {isDesktopWeb} from 'platform/detection' +import {CogIcon} from 'lib/icons' + +export const MultiFeed = observer(function Feed({ + multifeed, + style, + showPostFollowBtn, + scrollElRef, + onScroll, + scrollEventThrottle, + testID, + headerOffset = 0, + extraData, +}: { + multifeed: PostsMultiFeedModel + style?: StyleProp<ViewStyle> + showPostFollowBtn?: boolean + scrollElRef?: MutableRefObject<FlatList<any> | null> + onPressTryAgain?: () => void + onScroll?: OnScrollCb + scrollEventThrottle?: number + renderEmptyState?: () => JSX.Element + testID?: string + headerOffset?: number + extraData?: any +}) { + const pal = usePalette('default') + const theme = useTheme() + const {track} = useAnalytics() + const [isRefreshing, setIsRefreshing] = React.useState(false) + + // events + // = + + const onRefresh = React.useCallback(async () => { + track('MultiFeed:onRefresh') + setIsRefreshing(true) + try { + await multifeed.refresh() + } catch (err) { + multifeed.rootStore.log.error('Failed to refresh posts feed', err) + } + setIsRefreshing(false) + }, [multifeed, track, setIsRefreshing]) + + const onEndReached = React.useCallback(async () => { + track('MultiFeed:onEndReached') + try { + await multifeed.loadMore() + } catch (err) { + multifeed.rootStore.log.error('Failed to load more posts', err) + } + }, [multifeed, track]) + + // rendering + // = + + const renderItem = React.useCallback( + ({item}: {item: MultiFeedItem}) => { + if (item.type === 'header') { + if (isDesktopWeb) { + return ( + <View style={[pal.view, pal.border, styles.headerDesktop]}> + <Text type="2xl-bold" style={pal.text}> + My Feeds + </Text> + <Link href="/settings/saved-feeds"> + <CogIcon strokeWidth={1.5} style={pal.icon} size={28} /> + </Link> + </View> + ) + } + return <View style={[styles.header, pal.border]} /> + } else if (item.type === 'feed-header') { + return ( + <View style={styles.feedHeader}> + <UserAvatar type="algo" avatar={item.avatar} size={28} /> + <Text type="title-lg" style={[pal.text, styles.feedHeaderTitle]}> + {item.title} + </Text> + </View> + ) + } else if (item.type === 'feed-slice') { + return ( + <FeedSlice slice={item.slice} showFollowBtn={showPostFollowBtn} /> + ) + } else if (item.type === 'feed-loading') { + return <PostFeedLoadingPlaceholder /> + } else if (item.type === 'feed-error') { + return <ErrorMessage message={item.error} /> + } else if (item.type === 'feed-footer') { + return ( + <Link + href={item.uri} + style={[styles.feedFooter, pal.border, pal.view]}> + <Text type="lg" style={pal.link}> + See more from {item.title} + </Text> + <FontAwesomeIcon + icon="angle-right" + size={18} + color={pal.colors.link} + /> + </Link> + ) + } else if (item.type === 'footer') { + return ( + <Link style={[styles.footerLink, pal.viewLight]} href="/search/feeds"> + <FontAwesomeIcon icon="search" size={18} color={pal.colors.text} /> + <Text type="xl-medium" style={pal.text}> + Discover new feeds + </Text> + </Link> + ) + } + return null + }, + [showPostFollowBtn, pal], + ) + + const FeedFooter = React.useCallback( + () => + multifeed.isLoading && !isRefreshing ? ( + <View style={styles.loadMore}> + <ActivityIndicator color={pal.colors.text} /> + </View> + ) : ( + <View /> + ), + [multifeed.isLoading, isRefreshing, pal], + ) + + return ( + <View testID={testID} style={style}> + {multifeed.items.length > 0 && ( + <FlatList + testID={testID ? `${testID}-flatlist` : undefined} + ref={scrollElRef} + data={multifeed.items} + keyExtractor={item => item._reactKey} + renderItem={renderItem} + ListFooterComponent={FeedFooter} + refreshControl={ + <RefreshControl + refreshing={isRefreshing} + onRefresh={onRefresh} + tintColor={pal.colors.text} + titleColor={pal.colors.text} + progressViewOffset={headerOffset} + /> + } + contentContainerStyle={s.contentContainer} + style={[{paddingTop: headerOffset}, pal.view, styles.container]} + onScroll={onScroll} + scrollEventThrottle={scrollEventThrottle} + indicatorStyle={theme.colorScheme === 'dark' ? 'white' : 'black'} + onEndReached={onEndReached} + onEndReachedThreshold={0.6} + removeClippedSubviews={true} + contentOffset={{x: 0, y: headerOffset * -1}} + extraData={extraData} + // @ts-ignore our .web version only -prf + desktopFixedHeight + /> + )} + </View> + ) +}) + +const styles = StyleSheet.create({ + container: { + height: '100%', + }, + header: { + borderTopWidth: 1, + marginBottom: 4, + }, + headerDesktop: { + flexDirection: 'row', + alignItems: 'center', + justifyContent: 'space-between', + borderBottomWidth: 1, + marginBottom: 4, + paddingHorizontal: 16, + paddingVertical: 8, + }, + feedHeader: { + flexDirection: 'row', + gap: 8, + alignItems: 'center', + paddingHorizontal: 16, + paddingBottom: 8, + marginTop: 12, + }, + feedHeaderTitle: { + fontWeight: 'bold', + }, + feedFooter: { + flexDirection: 'row', + justifyContent: 'space-between', + alignItems: 'center', + paddingHorizontal: 16, + paddingVertical: 16, + marginBottom: 12, + borderTopWidth: 1, + borderBottomWidth: 1, + }, + footerLink: { + flexDirection: 'row', + alignItems: 'center', + justifyContent: 'center', + borderRadius: 8, + paddingHorizontal: 14, + paddingVertical: 12, + marginHorizontal: 8, + marginBottom: 8, + gap: 8, + }, + loadMore: { + paddingTop: 10, + }, +}) diff --git a/src/view/com/profile/FollowButton.tsx b/src/view/com/profile/FollowButton.tsx index 7715358cf..fcb2225da 100644 --- a/src/view/com/profile/FollowButton.tsx +++ b/src/view/com/profile/FollowButton.tsx @@ -33,7 +33,7 @@ export const FollowButton = observer( store.me.follows.removeFollow(did) onToggleFollow?.(false) } catch (e: any) { - store.log.error('Failed fo delete follow', e) + store.log.error('Failed to delete follow', e) Toast.show('An issue occurred, please try again.') } } else if (updatedFollowState === FollowState.NotFollowing) { @@ -42,7 +42,7 @@ export const FollowButton = observer( store.me.follows.addFollow(did, res.uri) onToggleFollow?.(true) } catch (e: any) { - store.log.error('Failed fo create follow', e) + store.log.error('Failed to create follow', e) Toast.show('An issue occurred, please try again.') } } diff --git a/src/view/com/profile/ProfileHeader.tsx b/src/view/com/profile/ProfileHeader.tsx index 3b9ca67c9..9b4df0989 100644 --- a/src/view/com/profile/ProfileHeader.tsx +++ b/src/view/com/profile/ProfileHeader.tsx @@ -218,7 +218,7 @@ const ProfileHeaderLoaded = observer( onRefreshAll() Toast.show('Account unblocked') } catch (e: any) { - store.log.error('Failed to block unaccount', e) + store.log.error('Failed to unblock account', e) Toast.show(`There was an issue! ${e.toString()}`) } }, @@ -289,6 +289,9 @@ const ProfileHeaderLoaded = observer( ]) const blockHide = !isMe && (view.viewer.blocking || view.viewer.blockedBy) + const following = formatCount(view.followsCount) + const followers = formatCount(view.followersCount) + const pluralizedFollowers = pluralize(view.followersCount, 'follower') return ( <View style={pal.view}> @@ -394,13 +397,13 @@ const ProfileHeaderLoaded = observer( style={[s.flexRow, s.mr10]} onPress={onPressFollowers} accessibilityRole="button" - accessibilityLabel={`Show ${view.handle}'s followers`} - accessibilityHint={`Shows folks following ${view.handle}`}> + accessibilityLabel={`${followers} ${pluralizedFollowers}`} + accessibilityHint={'Opens followers list'}> <Text type="md" style={[s.bold, s.mr2, pal.text]}> - {formatCount(view.followersCount)} + {followers} </Text> <Text type="md" style={[pal.textLight]}> - {pluralize(view.followersCount, 'follower')} + {pluralizedFollowers} </Text> </TouchableOpacity> <TouchableOpacity @@ -408,10 +411,10 @@ const ProfileHeaderLoaded = observer( style={[s.flexRow, s.mr10]} onPress={onPressFollows} accessibilityRole="button" - accessibilityLabel={`Show ${view.handle}'s follows`} - accessibilityHint={`Shows folks followed by ${view.handle}`}> + accessibilityLabel={`${following} following`} + accessibilityHint={'Opens following list'}> <Text type="md" style={[s.bold, s.mr2, pal.text]}> - {formatCount(view.followsCount)} + {following} </Text> <Text type="md" style={[pal.textLight]}> following diff --git a/src/view/com/search/HeaderWithInput.tsx b/src/view/com/search/HeaderWithInput.tsx index 7a9e0cc62..d44673717 100644 --- a/src/view/com/search/HeaderWithInput.tsx +++ b/src/view/com/search/HeaderWithInput.tsx @@ -4,7 +4,6 @@ import { FontAwesomeIcon, FontAwesomeIconStyle, } from '@fortawesome/react-native-fontawesome' -import {UserAvatar} from 'view/com/util/UserAvatar' import {Text} from 'view/com/util/text/Text' import {MagnifyingGlassIcon} from 'lib/icons' import {useTheme} from 'lib/ThemeContext' @@ -56,9 +55,9 @@ export function HeaderWithInput({ hitSlop={MENU_HITSLOP} style={styles.headerMenuBtn} accessibilityRole="button" - accessibilityLabel="Back" - accessibilityHint=""> - <UserAvatar size={30} avatar={store.me.avatar} /> + accessibilityLabel="Menu" + accessibilityHint="Access navigation links and settings"> + <FontAwesomeIcon icon="bars" size={18} color={pal.colors.textLight} /> </TouchableOpacity> <View style={[ @@ -87,6 +86,8 @@ export function HeaderWithInput({ accessibilityRole="search" accessibilityLabel="Search" accessibilityHint="" + autoCorrect={false} + autoCapitalize="none" /> {query ? ( <TouchableOpacity @@ -119,6 +120,7 @@ const styles = StyleSheet.create({ header: { flexDirection: 'row', alignItems: 'center', + justifyContent: 'center', paddingHorizontal: 12, paddingVertical: 4, }, @@ -126,7 +128,10 @@ const styles = StyleSheet.create({ width: 30, height: 30, borderRadius: 30, - marginHorizontal: 6, + marginRight: 6, + paddingBottom: 2, + alignItems: 'center', + justifyContent: 'center', }, headerSearchContainer: { flex: 1, diff --git a/src/view/com/util/UserAvatar.tsx b/src/view/com/util/UserAvatar.tsx index f3679326f..3294c8168 100644 --- a/src/view/com/util/UserAvatar.tsx +++ b/src/view/com/util/UserAvatar.tsx @@ -1,6 +1,6 @@ import React, {useMemo} from 'react' import {StyleSheet, View} from 'react-native' -import Svg, {Circle, Path} from 'react-native-svg' +import Svg, {Circle, Rect, Path} from 'react-native-svg' import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' import {IconProp} from '@fortawesome/fontawesome-svg-core' import {HighPriorityImage} from 'view/com/util/images/Image' @@ -17,9 +17,54 @@ import {isWeb, isAndroid} from 'platform/detection' import {Image as RNImage} from 'react-native-image-crop-picker' import {AvatarModeration} from 'lib/labeling/types' +type Type = 'user' | 'algo' | 'list' + const BLUR_AMOUNT = isWeb ? 5 : 100 -function DefaultAvatar({size}: {size: number}) { +function DefaultAvatar({type, size}: {type: Type; size: number}) { + if (type === 'algo') { + // Font Awesome Pro 6.4.0 by @fontawesome -https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. + return ( + <Svg + testID="userAvatarFallback" + width={size} + height={size} + viewBox="0 0 32 32" + fill="none" + stroke="none"> + <Rect width="32" height="32" rx="4" fill="#0070FF" /> + <Path + d="M13.5 7.25C13.5 6.55859 14.0586 6 14.75 6C20.9648 6 26 11.0352 26 17.25C26 17.9414 25.4414 18.5 24.75 18.5C24.0586 18.5 23.5 17.9414 23.5 17.25C23.5 12.418 19.582 8.5 14.75 8.5C14.0586 8.5 13.5 7.94141 13.5 7.25ZM8.36719 14.6172L12.4336 18.6836L13.543 17.5742C13.5156 17.4727 13.5 17.3633 13.5 17.25C13.5 16.5586 14.0586 16 14.75 16C15.4414 16 16 16.5586 16 17.25C16 17.9414 15.4414 18.5 14.75 18.5C14.6367 18.5 14.5312 18.4844 14.4258 18.457L13.3164 19.5664L17.3828 23.6328C17.9492 24.1992 17.8438 25.1484 17.0977 25.4414C16.1758 25.8008 15.1758 26 14.125 26C9.63672 26 6 22.3633 6 17.875C6 16.8242 6.19922 15.8242 6.5625 14.9023C6.85547 14.1602 7.80469 14.0508 8.37109 14.6172H8.36719ZM14.75 9.75C18.8906 9.75 22.25 13.1094 22.25 17.25C22.25 17.9414 21.6914 18.5 21 18.5C20.3086 18.5 19.75 17.9414 19.75 17.25C19.75 14.4883 17.5117 12.25 14.75 12.25C14.0586 12.25 13.5 11.6914 13.5 11C13.5 10.3086 14.0586 9.75 14.75 9.75Z" + fill="white" + /> + </Svg> + ) + } + if (type === 'list') { + // Font Awesome Pro 6.4.0 by @fontawesome -https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. + return ( + <Svg + testID="userAvatarFallback" + width={size} + height={size} + viewBox="0 0 32 32" + fill="none" + stroke="none"> + <Path + d="M28 0H4C1.79086 0 0 1.79086 0 4V28C0 30.2091 1.79086 32 4 32H28C30.2091 32 32 30.2091 32 28V4C32 1.79086 30.2091 0 28 0Z" + fill="#0070FF" + /> + <Path + d="M22.1529 22.3542C23.4522 22.4603 24.7593 22.293 25.9899 21.8629C26.0369 21.2838 25.919 20.7032 25.6497 20.1884C25.3805 19.6735 24.9711 19.2454 24.4687 18.9535C23.9663 18.6617 23.3916 18.518 22.8109 18.5392C22.2303 18.5603 21.6676 18.7454 21.1878 19.0731M22.1529 22.3542C22.1489 21.1917 21.8142 20.0534 21.1878 19.0741ZM10.8111 19.0741C10.3313 18.7468 9.7687 18.5619 9.18826 18.5409C8.60781 18.5199 8.03327 18.6636 7.53107 18.9554C7.02888 19.2472 6.61953 19.6752 6.35036 20.1899C6.08119 20.7046 5.96319 21.285 6.01001 21.8639C7.23969 22.2964 8.5461 22.4632 9.84497 22.3531M10.8111 19.0741C10.1851 20.0535 9.84865 21.1908 9.84497 22.3531ZM19.0759 10.077C19.0759 10.8931 18.7518 11.6757 18.1747 12.2527C17.5977 12.8298 16.815 13.154 15.9989 13.154C15.1829 13.154 14.4002 12.8298 13.8232 12.2527C13.2461 11.6757 12.922 10.8931 12.922 10.077C12.922 9.26092 13.2461 8.47828 13.8232 7.90123C14.4002 7.32418 15.1829 7 15.9989 7C16.815 7 17.5977 7.32418 18.1747 7.90123C18.7518 8.47828 19.0759 9.26092 19.0759 10.077ZM25.2299 13.154C25.2299 13.457 25.1702 13.7571 25.0542 14.0371C24.9383 14.3171 24.7683 14.5715 24.554 14.7858C24.3397 15.0001 24.0853 15.1701 23.8053 15.2861C23.5253 15.402 23.2252 15.4617 22.9222 15.4617C22.6191 15.4617 22.319 15.402 22.039 15.2861C21.759 15.1701 21.5046 15.0001 21.2903 14.7858C21.0761 14.5715 20.9061 14.3171 20.7901 14.0371C20.6741 13.7571 20.6144 13.457 20.6144 13.154C20.6144 12.5419 20.8576 11.9549 21.2903 11.5222C21.7231 11.0894 22.3101 10.8462 22.9222 10.8462C23.5342 10.8462 24.1212 11.0894 24.554 11.5222C24.9868 11.9549 25.2299 12.5419 25.2299 13.154ZM11.3835 13.154C11.3835 13.457 11.3238 13.7571 11.2078 14.0371C11.0918 14.3171 10.9218 14.5715 10.7075 14.7858C10.4932 15.0001 10.2388 15.1701 9.95886 15.2861C9.67887 15.402 9.37878 15.4617 9.07572 15.4617C8.77266 15.4617 8.47257 15.402 8.19259 15.2861C7.9126 15.1701 7.6582 15.0001 7.4439 14.7858C7.22961 14.5715 7.05962 14.3171 6.94365 14.0371C6.82767 13.7571 6.76798 13.457 6.76798 13.154C6.76798 12.5419 7.01112 11.9549 7.4439 11.5222C7.87669 11.0894 8.46367 10.8462 9.07572 10.8462C9.68777 10.8462 10.2748 11.0894 10.7075 11.5222C11.1403 11.9549 11.3835 12.5419 11.3835 13.154Z" + fill="white" + /> + <Path + d="M22 22C22 25.3137 19.3137 25.5 16 25.5C12.6863 25.5 10 25.3137 10 22C10 18.6863 12.6863 16 16 16C19.3137 16 22 18.6863 22 22Z" + fill="white" + /> + </Svg> + ) + } return ( <Svg testID="userAvatarFallback" @@ -41,11 +86,13 @@ function DefaultAvatar({size}: {size: number}) { } export function UserAvatar({ + type = 'user', size, avatar, moderation, onSelectNewAvatar, }: { + type?: Type size: number avatar?: string | null moderation?: AvatarModeration @@ -56,6 +103,21 @@ export function UserAvatar({ const {requestCameraAccessIfNeeded} = useCameraPermission() const {requestPhotoAccessIfNeeded} = usePhotoLibraryPermission() + const aviStyle = useMemo(() => { + if (type === 'algo' || type === 'list') { + return { + width: size, + height: size, + borderRadius: 8, + } + } + return { + width: size, + height: size, + borderRadius: Math.floor(size / 2), + } + }, [type, size]) + const dropdownItems = useMemo( () => [ !isWeb && { @@ -146,16 +208,12 @@ export function UserAvatar({ {avatar ? ( <HighPriorityImage testID="userAvatarImage" - style={{ - width: size, - height: size, - borderRadius: Math.floor(size / 2), - }} + style={aviStyle} source={{uri: avatar}} accessibilityRole="image" /> ) : ( - <DefaultAvatar size={size} /> + <DefaultAvatar type={type} size={size} /> )} <View style={[styles.editButtonContainer, pal.btn]}> <FontAwesomeIcon @@ -170,11 +228,7 @@ export function UserAvatar({ <View style={{width: size, height: size}}> <HighPriorityImage testID="userAvatarImage" - style={{ - width: size, - height: size, - borderRadius: Math.floor(size / 2), - }} + style={aviStyle} contentFit="cover" source={{uri: avatar}} blurRadius={moderation?.blur ? BLUR_AMOUNT : 0} @@ -183,7 +237,7 @@ export function UserAvatar({ </View> ) : ( <View style={{width: size, height: size}}> - <DefaultAvatar size={size} /> + <DefaultAvatar type={type} size={size} /> {warning} </View> ) @@ -201,11 +255,6 @@ const styles = StyleSheet.create({ justifyContent: 'center', backgroundColor: colors.gray5, }, - avatarImage: { - width: 80, - height: 80, - borderRadius: 40, - }, warningIconContainer: { position: 'absolute', right: 0, diff --git a/src/view/com/util/ViewHeader.tsx b/src/view/com/util/ViewHeader.tsx index 97802394e..732a46d06 100644 --- a/src/view/com/util/ViewHeader.tsx +++ b/src/view/com/util/ViewHeader.tsx @@ -4,7 +4,6 @@ import {Animated, StyleSheet, TouchableOpacity, View} from 'react-native' import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' import {useNavigation} from '@react-navigation/native' import {CenteredView} from './Views' -import {UserAvatar} from './UserAvatar' import {Text} from './text/Text' import {useStores} from 'state/index' import {usePalette} from 'lib/hooks/usePalette' @@ -20,12 +19,14 @@ export const ViewHeader = observer(function ({ canGoBack, hideOnScroll, showOnDesktop, + showBorder, renderButton, }: { title: string canGoBack?: boolean hideOnScroll?: boolean showOnDesktop?: boolean + showBorder?: boolean renderButton?: () => JSX.Element }) { const pal = usePalette('default') @@ -57,7 +58,7 @@ export const ViewHeader = observer(function ({ } return ( - <Container hideOnScroll={hideOnScroll || false}> + <Container hideOnScroll={hideOnScroll || false} showBorder={showBorder}> <TouchableOpacity testID="viewHeaderDrawerBtn" onPress={canGoBack ? onPressBack : onPressMenu} @@ -65,7 +66,9 @@ export const ViewHeader = observer(function ({ style={canGoBack ? styles.backBtn : styles.backBtnWide} accessibilityRole="button" accessibilityLabel={canGoBack ? 'Back' : 'Menu'} - accessibilityHint=""> + accessibilityHint={ + canGoBack ? '' : 'Access navigation links and settings' + }> {canGoBack ? ( <FontAwesomeIcon size={18} @@ -73,7 +76,11 @@ export const ViewHeader = observer(function ({ style={[styles.backIcon, pal.text]} /> ) : ( - <UserAvatar size={30} avatar={store.me.avatar} /> + <FontAwesomeIcon + size={18} + icon="bars" + style={[styles.backIcon, pal.textLight]} + /> )} </TouchableOpacity> <View style={styles.titleContainer} pointerEvents="none"> @@ -115,9 +122,11 @@ const Container = observer( ({ children, hideOnScroll, + showBorder, }: { children: React.ReactNode hideOnScroll: boolean + showBorder?: boolean }) => { const store = useStores() const pal = usePalette('default') @@ -145,11 +154,28 @@ const Container = observer( } if (!hideOnScroll) { - return <View style={[styles.header, pal.view]}>{children}</View> + return ( + <View + style={[ + styles.header, + pal.view, + pal.border, + showBorder && styles.border, + ]}> + {children} + </View> + ) } return ( <Animated.View - style={[styles.header, pal.view, styles.headerFloating, transform]}> + style={[ + styles.header, + pal.view, + pal.border, + styles.headerFloating, + transform, + showBorder && styles.border, + ]}> {children} </Animated.View> ) @@ -172,6 +198,9 @@ const styles = StyleSheet.create({ borderBottomWidth: 1, paddingVertical: 12, }, + border: { + borderBottomWidth: 1, + }, titleContainer: { marginLeft: 'auto', diff --git a/src/view/com/util/ViewSelector.tsx b/src/view/com/util/ViewSelector.tsx index f9ef0945d..5b671d06c 100644 --- a/src/view/com/util/ViewSelector.tsx +++ b/src/view/com/util/ViewSelector.tsx @@ -1,5 +1,5 @@ import React, {useEffect, useState} from 'react' -import {Pressable, StyleSheet, View} from 'react-native' +import {Pressable, RefreshControl, StyleSheet, View} from 'react-native' import {FlatList} from './Views' import {OnScrollCb} from 'lib/hooks/useOnMainScroll' import {useColorSchemeStyle} from 'lib/hooks/useColorSchemeStyle' @@ -41,6 +41,7 @@ export function ViewSelector({ onRefresh?: () => void onEndReached?: (info: {distanceFromEnd: number}) => void }) { + const pal = usePalette('default') const [selectedIndex, setSelectedIndex] = useState<number>(0) // events @@ -93,10 +94,15 @@ export function ViewSelector({ ListFooterComponent={ListFooterComponent} // NOTE sticky header disabled on android due to major performance issues -prf stickyHeaderIndices={isAndroid ? undefined : STICKY_HEADER_INDICES} - refreshing={refreshing} onScroll={onScroll} - onRefresh={onRefresh} onEndReached={onEndReached} + refreshControl={ + <RefreshControl + refreshing={refreshing!} + onRefresh={onRefresh} + tintColor={pal.colors.text} + /> + } onEndReachedThreshold={0.6} contentContainerStyle={s.contentContainer} removeClippedSubviews={true} diff --git a/src/view/com/util/Views.web.tsx b/src/view/com/util/Views.web.tsx index 9d6501d54..3313492e1 100644 --- a/src/view/com/util/Views.web.tsx +++ b/src/view/com/util/Views.web.tsx @@ -126,5 +126,6 @@ const styles = StyleSheet.create({ }, fixedHeight: { height: '100vh', + scrollbarGutter: 'stable both-edges', }, }) diff --git a/src/view/com/util/fab/FABInner.tsx b/src/view/com/util/fab/FABInner.tsx index 5eb4a6588..76824e575 100644 --- a/src/view/com/util/fab/FABInner.tsx +++ b/src/view/com/util/fab/FABInner.tsx @@ -47,7 +47,7 @@ const styles = StyleSheet.create({ outer: { position: 'absolute', zIndex: 1, - right: 28, + right: 24, bottom: 94, width: 60, height: 60, diff --git a/src/view/com/util/forms/DropdownButton.tsx b/src/view/com/util/forms/DropdownButton.tsx index 36ef1f409..064b8211b 100644 --- a/src/view/com/util/forms/DropdownButton.tsx +++ b/src/view/com/util/forms/DropdownButton.tsx @@ -136,7 +136,12 @@ export function DropdownButton({ } return ( <View ref={ref2}> - <Button testID={testID} onPress={onPress} style={style} label={label}> + <Button + type={type} + testID={testID} + onPress={onPress} + style={style} + label={label}> {children} </Button> </View> diff --git a/src/view/com/util/load-latest/LoadLatestBtn.web.tsx b/src/view/com/util/load-latest/LoadLatestBtn.web.tsx index 839685029..fefc540c0 100644 --- a/src/view/com/util/load-latest/LoadLatestBtn.web.tsx +++ b/src/view/com/util/load-latest/LoadLatestBtn.web.tsx @@ -1,8 +1,8 @@ import React from 'react' import {StyleSheet, TouchableOpacity} from 'react-native' +import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' import {Text} from '../text/Text' import {usePalette} from 'lib/hooks/usePalette' -import {UpIcon} from 'lib/icons' import {LoadLatestBtn as LoadLatestBtnMobile} from './LoadLatestBtnMobile' import {isMobileWeb} from 'platform/detection' @@ -11,51 +11,97 @@ const HITSLOP = {left: 20, top: 20, right: 20, bottom: 20} export const LoadLatestBtn = ({ onPress, label, + showIndicator, + minimalShellMode, }: { onPress: () => void label: string + showIndicator: boolean + minimalShellMode?: boolean }) => { const pal = usePalette('default') if (isMobileWeb) { - return <LoadLatestBtnMobile onPress={onPress} label={label} /> + return ( + <LoadLatestBtnMobile + onPress={onPress} + label={label} + showIndicator={showIndicator} + /> + ) } return ( - <TouchableOpacity - style={[pal.view, pal.borderDark, styles.loadLatest]} - onPress={onPress} - hitSlop={HITSLOP} - accessibilityRole="button" - accessibilityLabel={`Load new ${label}`} - accessibilityHint=""> - <Text type="md-bold" style={pal.text}> - <UpIcon size={16} strokeWidth={1} style={[pal.text, styles.icon]} /> - Load new {label} - </Text> - </TouchableOpacity> + <> + {showIndicator && ( + <TouchableOpacity + style={[ + pal.view, + pal.borderDark, + styles.loadLatestCentered, + minimalShellMode && styles.loadLatestCenteredMinimal, + ]} + onPress={onPress} + hitSlop={HITSLOP} + accessibilityRole="button" + accessibilityLabel={label} + accessibilityHint=""> + <Text type="md-bold" style={pal.text}> + {label} + </Text> + </TouchableOpacity> + )} + <TouchableOpacity + style={[pal.view, pal.borderDark, styles.loadLatest]} + onPress={onPress} + hitSlop={HITSLOP} + accessibilityRole="button" + accessibilityLabel={label} + accessibilityHint=""> + <Text type="md-bold" style={pal.text}> + <FontAwesomeIcon + icon="angle-up" + size={21} + style={[pal.text, styles.icon]} + /> + </Text> + </TouchableOpacity> + </> ) } const styles = StyleSheet.create({ loadLatest: { flexDirection: 'row', + alignItems: 'center', + justifyContent: 'center', position: 'absolute', left: '50vw', // @ts-ignore web only -prf - transform: 'translateX(-50%)', - top: 60, - shadowColor: '#000', - shadowOpacity: 0.2, - shadowOffset: {width: 0, height: 2}, - shadowRadius: 4, - paddingLeft: 20, - paddingRight: 24, - paddingVertical: 10, + transform: 'translateX(-282px)', + bottom: 40, + width: 54, + height: 54, borderRadius: 30, borderWidth: 1, }, icon: { position: 'relative', top: 2, - marginRight: 5, + }, + loadLatestCentered: { + flexDirection: 'row', + alignItems: 'center', + justifyContent: 'center', + position: 'absolute', + left: '50vw', + // @ts-ignore web only -prf + transform: 'translateX(-50%)', + top: 60, + paddingHorizontal: 24, + paddingVertical: 14, + borderRadius: 30, + borderWidth: 1, + }, + loadLatestCenteredMinimal: { + top: 20, }, }) diff --git a/src/view/com/util/load-latest/LoadLatestBtnMobile.tsx b/src/view/com/util/load-latest/LoadLatestBtnMobile.tsx index 5279696a2..412b9b803 100644 --- a/src/view/com/util/load-latest/LoadLatestBtnMobile.tsx +++ b/src/view/com/util/load-latest/LoadLatestBtnMobile.tsx @@ -1,23 +1,35 @@ import React from 'react' -import {StyleSheet, TouchableOpacity} from 'react-native' +import {StyleSheet, TouchableOpacity, View} from 'react-native' import {observer} from 'mobx-react-lite' -import LinearGradient from 'react-native-linear-gradient' +import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' import {useSafeAreaInsets} from 'react-native-safe-area-context' -import {Text} from '../text/Text' -import {colors, gradients} from 'lib/styles' import {clamp} from 'lodash' import {useStores} from 'state/index' +import {usePalette} from 'lib/hooks/usePalette' +import {colors} from 'lib/styles' const HITSLOP = {left: 20, top: 20, right: 20, bottom: 20} export const LoadLatestBtn = observer( - ({onPress, label}: {onPress: () => void; label: string}) => { + ({ + onPress, + label, + showIndicator, + }: { + onPress: () => void + label: string + showIndicator: boolean + minimalShellMode?: boolean // NOTE not used on mobile -prf + }) => { const store = useStores() + const pal = usePalette('default') const safeAreaInsets = useSafeAreaInsets() return ( <TouchableOpacity style={[ styles.loadLatest, + pal.borderDark, + pal.view, !store.shell.minimalShellMode && { bottom: 60 + clamp(safeAreaInsets.bottom, 15, 30), }, @@ -25,17 +37,10 @@ export const LoadLatestBtn = observer( onPress={onPress} hitSlop={HITSLOP} accessibilityRole="button" - accessibilityLabel={`Load new ${label}`} - accessibilityHint={`Loads new ${label}`}> - <LinearGradient - colors={[gradients.blueLight.start, gradients.blueLight.end]} - start={{x: 0, y: 0}} - end={{x: 1, y: 1}} - style={styles.loadLatestInner}> - <Text type="md-bold" style={styles.loadLatestText}> - Load new {label} - </Text> - </LinearGradient> + accessibilityLabel={label} + accessibilityHint=""> + <FontAwesomeIcon icon="angle-up" color={pal.colors.text} size={19} /> + {showIndicator && <View style={[styles.indicator, pal.borderDark]} />} </TouchableOpacity> ) }, @@ -44,19 +49,24 @@ export const LoadLatestBtn = observer( const styles = StyleSheet.create({ loadLatest: { position: 'absolute', - left: 20, + left: 18, bottom: 35, - shadowColor: '#000', - shadowOpacity: 0.3, - shadowOffset: {width: 0, height: 1}, - }, - loadLatestInner: { + borderWidth: 1, + width: 52, + height: 52, + borderRadius: 26, flexDirection: 'row', - paddingHorizontal: 14, - paddingVertical: 10, - borderRadius: 30, + alignItems: 'center', + justifyContent: 'center', }, - loadLatestText: { - color: colors.white, + indicator: { + position: 'absolute', + top: 3, + right: 3, + backgroundColor: colors.blue3, + width: 12, + height: 12, + borderRadius: 6, + borderWidth: 1, }, }) diff --git a/src/view/com/util/moderation/ImageHider.tsx b/src/view/com/util/moderation/ImageHider.tsx index b42c6397d..40add5b67 100644 --- a/src/view/com/util/moderation/ImageHider.tsx +++ b/src/view/com/util/moderation/ImageHider.tsx @@ -27,6 +27,10 @@ export function ImageHider({ setOverride(false) }, [setOverride]) + if (moderation.behavior === ModerationBehaviorCode.Hide) { + return null + } + if (moderation.behavior !== ModerationBehaviorCode.WarnImages) { return ( <View testID={testID} style={style}> @@ -35,10 +39,6 @@ export function ImageHider({ ) } - if (moderation.behavior === ModerationBehaviorCode.Hide) { - return null - } - return ( <View style={[styles.container, containerStyle]}> <View testID={testID} style={style}> diff --git a/src/view/com/util/moderation/PostHider.tsx b/src/view/com/util/moderation/PostHider.tsx index 2cc7ea62b..50ccf595b 100644 --- a/src/view/com/util/moderation/PostHider.tsx +++ b/src/view/com/util/moderation/PostHider.tsx @@ -1,11 +1,5 @@ -import React from 'react' -import { - StyleProp, - StyleSheet, - TouchableOpacity, - View, - ViewStyle, -} from 'react-native' +import React, {ComponentProps} from 'react' +import {StyleSheet, TouchableOpacity, View} from 'react-native' import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' import {usePalette} from 'lib/hooks/usePalette' import {Link} from '../Link' @@ -13,18 +7,21 @@ import {Text} from '../text/Text' import {addStyle} from 'lib/styles' import {ModerationBehaviorCode, ModerationBehavior} from 'lib/labeling/types' +interface Props extends ComponentProps<typeof Link> { + // testID?: string + // href?: string + // style: StyleProp<ViewStyle> + moderation: ModerationBehavior +} + export function PostHider({ testID, href, moderation, style, children, -}: React.PropsWithChildren<{ - testID?: string - href?: string - moderation: ModerationBehavior - style: StyleProp<ViewStyle> -}>) { + ...props +}: Props) { const pal = usePalette('default') const [override, setOverride] = React.useState(false) const bg = override ? pal.viewLight : pal.view @@ -70,7 +67,14 @@ export function PostHider({ // NOTE: any further label enforcement should occur in ContentContainer return ( - <Link testID={testID} style={style} href={href} noFeedback> + <Link + testID={testID} + style={style} + href={href} + noFeedback + accessible={true} + accessibilityRole="none" + {...props}> {children} </Link> ) diff --git a/src/view/com/util/numeric/format.ts b/src/view/com/util/numeric/format.ts index f0e90217f..7aa5a4f4d 100644 --- a/src/view/com/util/numeric/format.ts +++ b/src/view/com/util/numeric/format.ts @@ -3,3 +3,13 @@ export const formatCount = (num: number) => notation: 'compact', maximumFractionDigits: 1, }).format(num) + +export function formatCountShortOnly(num: number): string { + if (num >= 1000000) { + return (num / 1000000).toFixed(1) + 'M' + } + if (num >= 1000) { + return (num / 1000).toFixed(1) + 'K' + } + return String(num) +} diff --git a/src/view/com/util/post-ctrls/PostCtrls.tsx b/src/view/com/util/post-ctrls/PostCtrls.tsx index 5c0296e28..12d4c48c8 100644 --- a/src/view/com/util/post-ctrls/PostCtrls.tsx +++ b/src/view/com/util/post-ctrls/PostCtrls.tsx @@ -10,9 +10,6 @@ import { FontAwesomeIcon, FontAwesomeIconStyle, } from '@fortawesome/react-native-fontawesome' -import ReactNativeHapticFeedback, { - HapticFeedbackTypes, -} from 'react-native-haptic-feedback' // DISABLED see #135 // import { // TriggerableAnimated, @@ -24,8 +21,8 @@ import {HeartIcon, HeartIconSolid, CommentBottomArrow} from 'lib/icons' import {s, colors} from 'lib/styles' import {useTheme} from 'lib/ThemeContext' import {useStores} from 'state/index' -import {isIOS, isNative} from 'platform/detection' import {RepostButton} from './RepostButton' +import {Haptics} from 'lib/haptics' interface PostCtrlsOpts { itemUri: string @@ -58,7 +55,6 @@ interface PostCtrlsOpts { } const HITSLOP = {top: 5, left: 5, bottom: 5, right: 5} -const hapticImpact: HapticFeedbackTypes = isIOS ? 'impactMedium' : 'impactLight' // Users said the medium impact was too strong on Android; see APP-537 // DISABLED see #135 /* @@ -111,9 +107,7 @@ export function PostCtrls(opts: PostCtrlsOpts) { const onRepost = useCallback(() => { store.shell.closeModal() if (!opts.isReposted) { - if (isNative) { - ReactNativeHapticFeedback.trigger(hapticImpact) - } + Haptics.default() opts.onPressToggleRepost().catch(_e => undefined) // DISABLED see #135 // repostRef.current?.trigger( @@ -139,10 +133,7 @@ export function PostCtrls(opts: PostCtrlsOpts) { indexedAt: opts.indexedAt, }, }) - - if (isNative) { - ReactNativeHapticFeedback.trigger(hapticImpact) - } + Haptics.default() }, [ opts.author, opts.indexedAt, @@ -154,7 +145,7 @@ export function PostCtrls(opts: PostCtrlsOpts) { const onPressToggleLikeWrapper = async () => { if (!opts.isLiked) { - ReactNativeHapticFeedback.trigger(hapticImpact) + Haptics.default() await opts.onPressToggleLike().catch(_e => undefined) // DISABLED see #135 // likeRef.current?.trigger( @@ -200,12 +191,10 @@ export function PostCtrls(opts: PostCtrlsOpts) { onPress={onPressToggleLikeWrapper} accessibilityRole="button" accessibilityLabel={opts.isLiked ? 'Unlike' : 'Like'} - accessibilityHint={ - opts.isReposted ? `Removes like from the post` : `Like the post` - }> + accessibilityHint=""> {opts.isLiked ? ( <HeartIconSolid - style={styles.ctrlIconLiked as StyleProp<ViewStyle>} + style={styles.ctrlIconLiked} size={opts.big ? 22 : 16} /> ) : ( diff --git a/src/view/com/util/post-ctrls/RepostButton.tsx b/src/view/com/util/post-ctrls/RepostButton.tsx index e6de4cb19..59f7f6ee1 100644 --- a/src/view/com/util/post-ctrls/RepostButton.tsx +++ b/src/view/com/util/post-ctrls/RepostButton.tsx @@ -50,11 +50,7 @@ export const RepostButton = ({ style={styles.control} accessibilityRole="button" accessibilityLabel={isReposted ? 'Undo repost' : 'Repost'} - accessibilityHint={ - isReposted - ? `Remove your repost of the post` - : `Repost or quote post the post` - }> + accessibilityHint=""> <RepostIcon style={ isReposted diff --git a/src/view/com/util/post-embeds/index.tsx b/src/view/com/util/post-embeds/index.tsx index a55ff9050..8156d7732 100644 --- a/src/view/com/util/post-embeds/index.tsx +++ b/src/view/com/util/post-embeds/index.tsx @@ -13,6 +13,7 @@ import { AppBskyEmbedRecord, AppBskyEmbedRecordWithMedia, AppBskyFeedPost, + AppBskyFeedDefs, } from '@atproto/api' import {Link} from '../Link' import {ImageLayoutGrid} from '../images/ImageLayoutGrid' @@ -24,6 +25,8 @@ import {ExternalLinkEmbed} from './ExternalLinkEmbed' import {getYoutubeVideoId} from 'lib/strings/url-helpers' import QuoteEmbed from './QuoteEmbed' import {AutoSizedImage} from '../images/AutoSizedImage' +import {CustomFeed} from 'view/com/feeds/CustomFeed' +import {CustomFeedModel} from 'state/models/feeds/custom-feed' type Embed = | AppBskyEmbedRecord.View @@ -42,6 +45,8 @@ export function PostEmbeds({ const pal = usePalette('default') const store = useStores() + // quote post with media + // = if ( AppBskyEmbedRecordWithMedia.isView(embed) && AppBskyEmbedRecord.isViewRecord(embed.record.record) && @@ -65,6 +70,8 @@ export function PostEmbeds({ ) } + // quote post + // = if (AppBskyEmbedRecord.isView(embed)) { if ( AppBskyEmbedRecord.isViewRecord(embed.record) && @@ -87,6 +94,8 @@ export function PostEmbeds({ } } + // image embed + // = if (AppBskyEmbedImages.isView(embed)) { const {images} = embed @@ -100,7 +109,7 @@ export function PostEmbeds({ RNImage.prefetch(firstImageToShow) items.forEach(item => { if (firstImageToShow !== item.uri) { - // First image already prefeched above + // First image already prefetched above RNImage.prefetch(item.uri) } }) @@ -132,10 +141,11 @@ export function PostEmbeds({ /> </View> ) - // } } } + // external link embed + // = if (AppBskyEmbedExternal.isView(embed)) { const link = embed.external const youtubeVideoId = getYoutubeVideoId(link.uri) @@ -153,9 +163,35 @@ export function PostEmbeds({ </Link> ) } + + // custom feed embed (i.e. generator view) + // = + if ( + AppBskyEmbedRecord.isView(embed) && + AppBskyFeedDefs.isGeneratorView(embed.record) + ) { + return <CustomFeedEmbed record={embed.record} /> + } + return <View /> } +function CustomFeedEmbed({record}: {record: AppBskyFeedDefs.GeneratorView}) { + const pal = usePalette('default') + const store = useStores() + const item = React.useMemo( + () => new CustomFeedModel(store, record), + [store, record], + ) + return ( + <CustomFeed + item={item} + style={[pal.view, pal.border, styles.customFeedOuter]} + showLikes + /> + ) +} + const styles = StyleSheet.create({ stackContainer: { gap: 6, @@ -172,6 +208,13 @@ const styles = StyleSheet.create({ borderRadius: 8, marginTop: 4, }, + customFeedOuter: { + borderWidth: 1, + borderRadius: 8, + marginTop: 4, + paddingHorizontal: 12, + paddingVertical: 12, + }, alt: { backgroundColor: 'rgba(0, 0, 0, 0.75)', borderRadius: 6, diff --git a/src/view/index.ts b/src/view/index.ts index b8a13f7f8..f06bdaccc 100644 --- a/src/view/index.ts +++ b/src/view/index.ts @@ -8,6 +8,7 @@ import {faAngleUp} from '@fortawesome/free-solid-svg-icons/faAngleUp' import {faArrowLeft} from '@fortawesome/free-solid-svg-icons/faArrowLeft' import {faArrowRight} from '@fortawesome/free-solid-svg-icons/faArrowRight' import {faArrowUp} from '@fortawesome/free-solid-svg-icons/faArrowUp' +import {faArrowDown} from '@fortawesome/free-solid-svg-icons/faArrowDown' import {faArrowRightFromBracket} from '@fortawesome/free-solid-svg-icons/faArrowRightFromBracket' import {faArrowUpFromBracket} from '@fortawesome/free-solid-svg-icons/faArrowUpFromBracket' import {faArrowUpRightFromSquare} from '@fortawesome/free-solid-svg-icons/faArrowUpRightFromSquare' @@ -59,14 +60,17 @@ import {faPenNib} from '@fortawesome/free-solid-svg-icons/faPenNib' import {faPenToSquare} from '@fortawesome/free-solid-svg-icons/faPenToSquare' import {faPlus} from '@fortawesome/free-solid-svg-icons/faPlus' import {faQuoteLeft} from '@fortawesome/free-solid-svg-icons/faQuoteLeft' +import {faReply} from '@fortawesome/free-solid-svg-icons/faReply' +import {faRetweet} from '@fortawesome/free-solid-svg-icons/faRetweet' +import {faRss} from '@fortawesome/free-solid-svg-icons/faRss' +import {faSatelliteDish} from '@fortawesome/free-solid-svg-icons/faSatelliteDish' import {faShare} from '@fortawesome/free-solid-svg-icons/faShare' import {faShareFromSquare} from '@fortawesome/free-solid-svg-icons/faShareFromSquare' import {faShield} from '@fortawesome/free-solid-svg-icons/faShield' import {faSquarePlus} from '@fortawesome/free-regular-svg-icons/faSquarePlus' import {faSignal} from '@fortawesome/free-solid-svg-icons/faSignal' -import {faReply} from '@fortawesome/free-solid-svg-icons/faReply' -import {faRetweet} from '@fortawesome/free-solid-svg-icons/faRetweet' -import {faRss} from '@fortawesome/free-solid-svg-icons/faRss' +import {faTicket} from '@fortawesome/free-solid-svg-icons/faTicket' +import {faTrashCan} from '@fortawesome/free-regular-svg-icons/faTrashCan' import {faUser} from '@fortawesome/free-regular-svg-icons/faUser' import {faUsers} from '@fortawesome/free-solid-svg-icons/faUsers' import {faUserCheck} from '@fortawesome/free-solid-svg-icons/faUserCheck' @@ -74,12 +78,11 @@ import {faUserSlash} from '@fortawesome/free-solid-svg-icons/faUserSlash' import {faUserPlus} from '@fortawesome/free-solid-svg-icons/faUserPlus' import {faUserXmark} from '@fortawesome/free-solid-svg-icons/faUserXmark' import {faUsersSlash} from '@fortawesome/free-solid-svg-icons/faUsersSlash' -import {faTicket} from '@fortawesome/free-solid-svg-icons/faTicket' -import {faTrashCan} from '@fortawesome/free-regular-svg-icons/faTrashCan' import {faX} from '@fortawesome/free-solid-svg-icons/faX' import {faXmark} from '@fortawesome/free-solid-svg-icons/faXmark' import {faPlay} from '@fortawesome/free-solid-svg-icons/faPlay' import {faPause} from '@fortawesome/free-solid-svg-icons/faPause' +import {faThumbtack} from '@fortawesome/free-solid-svg-icons/faThumbtack' export function setup() { library.add( @@ -91,6 +94,7 @@ export function setup() { faArrowLeft, faArrowRight, faArrowUp, + faArrowDown, faArrowRightFromBracket, faArrowUpFromBracket, faArrowUpRightFromSquare, @@ -145,6 +149,7 @@ export function setup() { faReply, faRetweet, faRss, + faSatelliteDish, faShare, faShareFromSquare, faShield, @@ -159,6 +164,7 @@ export function setup() { faUsersSlash, faTicket, faTrashCan, + faThumbtack, faX, faXmark, faPlay, diff --git a/src/view/screens/AppPasswords.tsx b/src/view/screens/AppPasswords.tsx index 3adbf09df..ca60787d5 100644 --- a/src/view/screens/AppPasswords.tsx +++ b/src/view/screens/AppPasswords.tsx @@ -1,6 +1,5 @@ import React from 'react' import {StyleSheet, TouchableOpacity, View} from 'react-native' -import {Alert} from 'view/com/util/Alert' import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' import {ScrollView} from 'react-native-gesture-handler' import {Text} from '../com/util/text/Text' @@ -160,24 +159,15 @@ function AppPassword({ const store = useStores() const onDelete = React.useCallback(async () => { - Alert.alert( - 'Delete App Password', - `Are you sure you want to delete the app password "${name}"?`, - [ - { - text: 'Cancel', - style: 'cancel', - }, - { - text: 'Delete', - style: 'destructive', - onPress: async () => { - await store.me.deleteAppPassword(name) - Toast.show('App password deleted') - }, - }, - ], - ) + store.shell.openModal({ + name: 'confirm', + title: 'Delete App Password', + message: `Are you sure you want to delete the app password "${name}"?`, + async onPressConfirm() { + await store.me.deleteAppPassword(name) + Toast.show('App password deleted') + }, + }) }, [store, name]) const {contentLanguages} = store.preferences diff --git a/src/view/screens/CustomFeed.tsx b/src/view/screens/CustomFeed.tsx new file mode 100644 index 000000000..4149cd49d --- /dev/null +++ b/src/view/screens/CustomFeed.tsx @@ -0,0 +1,418 @@ +import React, {useMemo, useRef} from 'react' +import {NativeStackScreenProps} from '@react-navigation/native-stack' +import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' +import {usePalette} from 'lib/hooks/usePalette' +import {HeartIcon, HeartIconSolid} from 'lib/icons' +import {CommonNavigatorParams} from 'lib/routes/types' +import {makeRecordUri} from 'lib/strings/url-helpers' +import {colors, s} from 'lib/styles' +import {observer} from 'mobx-react-lite' +import {FlatList, StyleSheet, View} from 'react-native' +import {useStores} from 'state/index' +import {PostsFeedModel} from 'state/models/feeds/posts' +import {useCustomFeed} from 'lib/hooks/useCustomFeed' +import {withAuthRequired} from 'view/com/auth/withAuthRequired' +import {Feed} from 'view/com/posts/Feed' +import {pluralize} from 'lib/strings/helpers' +import {TextLink} from 'view/com/util/Link' +import {UserAvatar} from 'view/com/util/UserAvatar' +import {ViewHeader} from 'view/com/util/ViewHeader' +import {Button} from 'view/com/util/forms/Button' +import {Text} from 'view/com/util/text/Text' +import * as Toast from 'view/com/util/Toast' +import {isDesktopWeb} from 'platform/detection' +import {useSetTitle} from 'lib/hooks/useSetTitle' +import {shareUrl} from 'lib/sharing' +import {toShareUrl} from 'lib/strings/url-helpers' +import {Haptics} from 'lib/haptics' +import {ComposeIcon2} from 'lib/icons' +import {FAB} from '../com/util/fab/FAB' +import {LoadLatestBtn} from 'view/com/util/load-latest/LoadLatestBtn' +import {DropdownButton, DropdownItem} from 'view/com/util/forms/DropdownButton' +import {useOnMainScroll} from 'lib/hooks/useOnMainScroll' +import {EmptyState} from 'view/com/util/EmptyState' + +type Props = NativeStackScreenProps<CommonNavigatorParams, 'CustomFeed'> +export const CustomFeedScreen = withAuthRequired( + observer(({route}: Props) => { + const store = useStores() + const pal = usePalette('default') + const {rkey, name} = route.params + const uri = useMemo( + () => makeRecordUri(name, 'app.bsky.feed.generator', rkey), + [rkey, name], + ) + const scrollElRef = useRef<FlatList>(null) + const currentFeed = useCustomFeed(uri) + const algoFeed: PostsFeedModel = useMemo(() => { + const feed = new PostsFeedModel(store, 'custom', { + feed: uri, + }) + feed.setup() + return feed + }, [store, uri]) + const isPinned = store.me.savedFeeds.isPinned(uri) + const [onMainScroll, isScrolledDown, resetMainScroll] = + useOnMainScroll(store) + useSetTitle(currentFeed?.displayName) + + const onToggleSaved = React.useCallback(async () => { + try { + Haptics.default() + if (currentFeed?.isSaved) { + await currentFeed?.unsave() + } else { + await currentFeed?.save() + } + } catch (err) { + Toast.show( + 'There was an an issue updating your feeds, please check your internet connection and try again.', + ) + store.log.error('Failed up update feeds', {err}) + } + }, [store, currentFeed]) + + const onToggleLiked = React.useCallback(async () => { + Haptics.default() + try { + if (currentFeed?.isLiked) { + await currentFeed?.unlike() + } else { + await currentFeed?.like() + } + } catch (err) { + Toast.show( + 'There was an an issue contacting the server, please check your internet connection and try again.', + ) + store.log.error('Failed up toggle like', {err}) + } + }, [store, currentFeed]) + + const onTogglePinned = React.useCallback(async () => { + Haptics.default() + store.me.savedFeeds.togglePinnedFeed(currentFeed!).catch(e => { + Toast.show('There was an issue contacting the server') + store.log.error('Failed to toggle pinned feed', {e}) + }) + }, [store, currentFeed]) + + const onPressShare = React.useCallback(() => { + const url = toShareUrl(`/profile/${name}/feed/${rkey}`) + shareUrl(url) + }, [name, rkey]) + + const onScrollToTop = React.useCallback(() => { + scrollElRef.current?.scrollToOffset({offset: 0, animated: true}) + resetMainScroll() + }, [scrollElRef, resetMainScroll]) + + const onPressCompose = React.useCallback(() => { + store.shell.openComposer({}) + }, [store]) + + const dropdownItems: DropdownItem[] = React.useMemo(() => { + let items: DropdownItem[] = [ + { + testID: 'feedHeaderDropdownRemoveBtn', + label: 'Remove from my feeds', + onPress: onToggleSaved, + }, + { + testID: 'feedHeaderDropdownShareBtn', + label: 'Share link', + onPress: onPressShare, + }, + ] + return items + }, [onToggleSaved, onPressShare]) + + const renderHeaderBtns = React.useCallback(() => { + return ( + <View style={styles.headerBtns}> + <Button + type="default-light" + testID="toggleLikeBtn" + accessibilityLabel="Like this feed" + accessibilityHint="" + onPress={onToggleLiked}> + {currentFeed?.isLiked ? ( + <HeartIconSolid size={19} style={styles.liked} /> + ) : ( + <HeartIcon strokeWidth={3} size={19} style={pal.textLight} /> + )} + </Button> + {currentFeed?.isSaved ? ( + <Button + type="default-light" + accessibilityLabel={ + isPinned ? 'Unpin this feed' : 'Pin this feed' + } + accessibilityHint="" + onPress={onTogglePinned}> + <FontAwesomeIcon + icon="thumb-tack" + size={17} + color={isPinned ? colors.blue3 : pal.colors.textLight} + style={styles.top1} + /> + </Button> + ) : undefined} + {currentFeed?.isSaved ? ( + <DropdownButton + testID="feedHeaderDropdownBtn" + type="default-light" + items={dropdownItems} + menuWidth={250}> + <FontAwesomeIcon + icon="ellipsis" + color={pal.colors.textLight} + size={18} + /> + </DropdownButton> + ) : ( + <Button + type="default-light" + onPress={onToggleSaved} + accessibilityLabel="Add to my feeds" + accessibilityHint="" + style={styles.headerAddBtn}> + <FontAwesomeIcon icon="plus" color={pal.colors.link} size={19} /> + <Text type="xl-medium" style={pal.link}> + Add to My Feeds + </Text> + </Button> + )} + </View> + ) + }, [ + pal, + currentFeed?.isSaved, + currentFeed?.isLiked, + isPinned, + onToggleSaved, + onTogglePinned, + onToggleLiked, + dropdownItems, + ]) + + const renderListHeaderComponent = React.useCallback(() => { + return ( + <> + <View style={[styles.header, pal.border]}> + <View style={s.flex1}> + <Text + testID="feedName" + type="title-xl" + style={[pal.text, s.bold]}> + {currentFeed?.displayName} + </Text> + {currentFeed && ( + <Text type="md" style={[pal.textLight]} numberOfLines={1}> + by{' '} + {currentFeed.data.creator.did === store.me.did ? ( + 'you' + ) : ( + <TextLink + text={`@${currentFeed.data.creator.handle}`} + href={`/profile/${currentFeed.data.creator.did}`} + style={[pal.textLight]} + /> + )} + </Text> + )} + {isDesktopWeb && ( + <View style={[styles.headerBtns, styles.headerBtnsDesktop]}> + <Button + type={currentFeed?.isSaved ? 'default' : 'inverted'} + onPress={onToggleSaved} + accessibilityLabel={ + currentFeed?.isSaved + ? 'Unsave this feed' + : 'Save this feed' + } + accessibilityHint="" + label={ + currentFeed?.isSaved + ? 'Remove from My Feeds' + : 'Add to My Feeds' + } + /> + <Button + type="default" + accessibilityLabel={ + isPinned ? 'Unpin this feed' : 'Pin this feed' + } + accessibilityHint="" + onPress={onTogglePinned}> + <FontAwesomeIcon + icon="thumb-tack" + size={15} + color={isPinned ? colors.blue3 : pal.colors.icon} + style={styles.top2} + /> + </Button> + <Button + type="default" + accessibilityLabel="Like this feed" + accessibilityHint="" + onPress={onToggleLiked}> + {currentFeed?.isLiked ? ( + <HeartIconSolid size={18} style={styles.liked} /> + ) : ( + <HeartIcon strokeWidth={3} size={18} style={pal.icon} /> + )} + </Button> + <Button + type="default" + accessibilityLabel="Share this feed" + accessibilityHint="" + onPress={onPressShare}> + <FontAwesomeIcon + icon="share" + size={18} + color={pal.colors.icon} + /> + </Button> + </View> + )} + </View> + <View> + <UserAvatar + type="algo" + avatar={currentFeed?.data.avatar} + size={64} + /> + </View> + </View> + <View style={styles.headerDetails}> + {currentFeed?.data.description ? ( + <Text style={[pal.text, s.mb10]} numberOfLines={6}> + {currentFeed.data.description} + </Text> + ) : null} + <View style={styles.headerDetailsFooter}> + {currentFeed ? ( + <TextLink + type="md-medium" + style={pal.textLight} + href={`/profile/${name}/feed/${rkey}/liked-by`} + text={`Liked by ${currentFeed.data.likeCount} ${pluralize( + currentFeed?.data.likeCount || 0, + 'user', + )}`} + /> + ) : null} + </View> + </View> + <View style={[styles.fakeSelector, pal.border]}> + <View + style={[styles.fakeSelectorItem, {borderColor: pal.colors.link}]}> + <Text type="md-medium" style={[pal.text]}> + Feed + </Text> + </View> + </View> + </> + ) + }, [ + pal, + currentFeed, + store.me.did, + onToggleSaved, + onToggleLiked, + onPressShare, + name, + rkey, + isPinned, + onTogglePinned, + ]) + + const renderEmptyState = React.useCallback(() => { + return <EmptyState icon="feed" message="This list is empty!" /> + }, []) + + return ( + <View style={s.hContentRegion}> + <ViewHeader title="" renderButton={currentFeed && renderHeaderBtns} /> + <Feed + scrollElRef={scrollElRef} + feed={algoFeed} + onScroll={onMainScroll} + scrollEventThrottle={100} + ListHeaderComponent={renderListHeaderComponent} + renderEmptyState={renderEmptyState} + extraData={[uri, isPinned]} + /> + {isScrolledDown ? ( + <LoadLatestBtn + onPress={onScrollToTop} + label="Scroll to top" + showIndicator={false} + /> + ) : null} + <FAB + testID="composeFAB" + onPress={onPressCompose} + icon={<ComposeIcon2 strokeWidth={1.5} size={29} style={s.white} />} + accessibilityRole="button" + accessibilityLabel="Compose post" + accessibilityHint="" + /> + </View> + ) + }), +) + +const styles = StyleSheet.create({ + header: { + flexDirection: 'row', + gap: 12, + paddingHorizontal: 16, + paddingTop: 12, + paddingBottom: 16, + borderTopWidth: 1, + }, + headerBtns: { + flexDirection: 'row', + alignItems: 'center', + }, + headerBtnsDesktop: { + marginTop: 8, + gap: 4, + }, + headerAddBtn: { + flexDirection: 'row', + alignItems: 'center', + gap: 4, + paddingLeft: 4, + }, + headerDetails: { + paddingHorizontal: 16, + paddingBottom: 16, + }, + headerDetailsFooter: { + flexDirection: 'row', + alignItems: 'center', + justifyContent: 'space-between', + }, + fakeSelector: { + flexDirection: 'row', + paddingHorizontal: isDesktopWeb ? 16 : 6, + }, + fakeSelectorItem: { + paddingHorizontal: 12, + paddingBottom: 8, + borderBottomWidth: 3, + }, + liked: { + color: colors.red3, + }, + top1: { + position: 'relative', + top: 1, + }, + top2: { + position: 'relative', + top: 2, + }, +}) diff --git a/src/view/screens/CustomFeedLikedBy.tsx b/src/view/screens/CustomFeedLikedBy.tsx new file mode 100644 index 000000000..49d0d0482 --- /dev/null +++ b/src/view/screens/CustomFeedLikedBy.tsx @@ -0,0 +1,29 @@ +import React from 'react' +import {View} from 'react-native' +import {useFocusEffect} from '@react-navigation/native' +import {NativeStackScreenProps, CommonNavigatorParams} from 'lib/routes/types' +import {withAuthRequired} from 'view/com/auth/withAuthRequired' +import {ViewHeader} from '../com/util/ViewHeader' +import {PostLikedBy as PostLikedByComponent} from '../com/post-thread/PostLikedBy' +import {useStores} from 'state/index' +import {makeRecordUri} from 'lib/strings/url-helpers' + +type Props = NativeStackScreenProps<CommonNavigatorParams, 'CustomFeedLikedBy'> +export const CustomFeedLikedByScreen = withAuthRequired(({route}: Props) => { + const store = useStores() + const {name, rkey} = route.params + const uri = makeRecordUri(name, 'app.bsky.feed.generator', rkey) + + useFocusEffect( + React.useCallback(() => { + store.shell.setMinimalShellMode(false) + }, [store]), + ) + + return ( + <View> + <ViewHeader title="Liked by" /> + <PostLikedByComponent uri={uri} /> + </View> + ) +}) diff --git a/src/view/screens/DiscoverFeeds.tsx b/src/view/screens/DiscoverFeeds.tsx new file mode 100644 index 000000000..cd32ec655 --- /dev/null +++ b/src/view/screens/DiscoverFeeds.tsx @@ -0,0 +1,112 @@ +import React from 'react' +import {RefreshControl, StyleSheet, View} from 'react-native' +import {observer} from 'mobx-react-lite' +import {useFocusEffect} from '@react-navigation/native' +import {NativeStackScreenProps, CommonNavigatorParams} from 'lib/routes/types' +import {withAuthRequired} from 'view/com/auth/withAuthRequired' +import {ViewHeader} from '../com/util/ViewHeader' +import {useStores} from 'state/index' +import {FeedsDiscoveryModel} from 'state/models/discovery/feeds' +import {CenteredView, FlatList} from 'view/com/util/Views' +import {CustomFeed} from 'view/com/feeds/CustomFeed' +import {Text} from 'view/com/util/text/Text' +import {isDesktopWeb} from 'platform/detection' +import {usePalette} from 'lib/hooks/usePalette' +import {s} from 'lib/styles' + +type Props = NativeStackScreenProps<CommonNavigatorParams, 'DiscoverFeeds'> +export const DiscoverFeedsScreen = withAuthRequired( + observer(({}: Props) => { + const store = useStores() + const pal = usePalette('default') + const feeds = React.useMemo(() => new FeedsDiscoveryModel(store), [store]) + + useFocusEffect( + React.useCallback(() => { + store.shell.setMinimalShellMode(false) + feeds.refresh() + }, [store, feeds]), + ) + + const onRefresh = React.useCallback(() => { + store.me.savedFeeds.refresh() + }, [store]) + + const renderListEmptyComponent = React.useCallback(() => { + return ( + <View + style={[ + pal.border, + !isDesktopWeb && s.flex1, + pal.viewLight, + styles.empty, + ]}> + <Text type="lg" style={[pal.text]}> + {feeds.isLoading + ? 'Loading...' + : `We can't find any feeds for some reason. This is probably an error - try refreshing!`} + </Text> + </View> + ) + }, [pal, feeds.isLoading]) + + const renderItem = React.useCallback( + ({item}) => ( + <CustomFeed + key={item.data.uri} + item={item} + showSaveBtn + showDescription + showLikes + /> + ), + [], + ) + + return ( + <CenteredView style={[styles.container, pal.view]}> + <View style={[isDesktopWeb && styles.containerDesktop, pal.border]}> + <ViewHeader title="Discover Feeds" showOnDesktop /> + </View> + <FlatList + style={[!isDesktopWeb && s.flex1]} + data={feeds.feeds} + keyExtractor={item => item.data.uri} + contentContainerStyle={styles.contentContainer} + refreshControl={ + <RefreshControl + refreshing={feeds.isRefreshing} + onRefresh={onRefresh} + tintColor={pal.colors.text} + titleColor={pal.colors.text} + /> + } + renderItem={renderItem} + initialNumToRender={10} + ListEmptyComponent={renderListEmptyComponent} + extraData={feeds.isLoading} + /> + </CenteredView> + ) + }), +) + +const styles = StyleSheet.create({ + container: { + flex: 1, + }, + contentContainer: { + paddingBottom: 100, + }, + containerDesktop: { + borderLeftWidth: 1, + borderRightWidth: 1, + }, + empty: { + paddingHorizontal: 18, + paddingVertical: 16, + borderRadius: 8, + marginHorizontal: 18, + marginTop: 10, + }, +}) diff --git a/src/view/screens/Feeds.tsx b/src/view/screens/Feeds.tsx new file mode 100644 index 000000000..169f88791 --- /dev/null +++ b/src/view/screens/Feeds.tsx @@ -0,0 +1,126 @@ +import React from 'react' +import {StyleSheet, View} from 'react-native' +import {useFocusEffect} from '@react-navigation/native' +import isEqual from 'lodash.isequal' +import {withAuthRequired} from 'view/com/auth/withAuthRequired' +import {FlatList} from 'view/com/util/Views' +import {ViewHeader} from 'view/com/util/ViewHeader' +import {LoadLatestBtn} from 'view/com/util/load-latest/LoadLatestBtn' +import {FAB} from 'view/com/util/fab/FAB' +import {Link} from 'view/com/util/Link' +import {NativeStackScreenProps, FeedsTabNavigatorParams} from 'lib/routes/types' +import {observer} from 'mobx-react-lite' +import {PostsMultiFeedModel} from 'state/models/feeds/multi-feed' +import {MultiFeed} from 'view/com/posts/MultiFeed' +import {isDesktopWeb} from 'platform/detection' +import {usePalette} from 'lib/hooks/usePalette' +import {useStores} from 'state/index' +import {useOnMainScroll} from 'lib/hooks/useOnMainScroll' +import {ComposeIcon2, CogIcon} from 'lib/icons' +import {s} from 'lib/styles' + +const HEADER_OFFSET = isDesktopWeb ? 0 : 40 + +type Props = NativeStackScreenProps<FeedsTabNavigatorParams, 'Feeds'> +export const FeedsScreen = withAuthRequired( + observer<Props>(({}: Props) => { + const pal = usePalette('default') + const store = useStores() + const flatListRef = React.useRef<FlatList>(null) + const multifeed = React.useMemo<PostsMultiFeedModel>( + () => new PostsMultiFeedModel(store), + [store], + ) + const [onMainScroll, isScrolledDown, resetMainScroll] = + useOnMainScroll(store) + + const onSoftReset = React.useCallback(() => { + flatListRef.current?.scrollToOffset({offset: 0}) + resetMainScroll() + }, [flatListRef, resetMainScroll]) + + useFocusEffect( + React.useCallback(() => { + const softResetSub = store.onScreenSoftReset(onSoftReset) + const multifeedCleanup = multifeed.registerListeners() + const cleanup = () => { + softResetSub.remove() + multifeedCleanup() + } + + store.shell.setMinimalShellMode(false) + return cleanup + }, [store, multifeed, onSoftReset]), + ) + + React.useEffect(() => { + if ( + isEqual( + multifeed.feedInfos.map(f => f.uri), + store.me.savedFeeds.all.map(f => f.uri), + ) + ) { + // no changes + return + } + multifeed.refresh() + }, [multifeed, store.me.savedFeeds.all]) + + const onPressCompose = React.useCallback(() => { + store.shell.openComposer({}) + }, [store]) + + const renderHeaderBtn = React.useCallback(() => { + return ( + <Link + href="/settings/saved-feeds" + hitSlop={10} + accessibilityRole="button" + accessibilityLabel="Edit Saved Feeds" + accessibilityHint="Opens screen to edit Saved Feeds"> + <CogIcon size={22} strokeWidth={2} style={pal.textLight} /> + </Link> + ) + }, [pal]) + + return ( + <View style={[pal.view, styles.container]}> + <MultiFeed + scrollElRef={flatListRef} + multifeed={multifeed} + onScroll={onMainScroll} + scrollEventThrottle={100} + headerOffset={HEADER_OFFSET} + showPostFollowBtn + /> + <ViewHeader + title="My Feeds" + canGoBack={false} + hideOnScroll + renderButton={renderHeaderBtn} + /> + {isScrolledDown ? ( + <LoadLatestBtn + onPress={onSoftReset} + label="Scroll to top" + showIndicator={false} + /> + ) : null} + <FAB + testID="composeFAB" + onPress={onPressCompose} + icon={<ComposeIcon2 strokeWidth={1.5} size={29} style={s.white} />} + accessibilityRole="button" + accessibilityLabel="Compose post" + accessibilityHint="" + /> + </View> + ) + }), +) + +const styles = StyleSheet.create({ + container: { + flex: 1, + }, +}) diff --git a/src/view/screens/Home.tsx b/src/view/screens/Home.tsx index 0ead6b65c..d7a2aa231 100644 --- a/src/view/screens/Home.tsx +++ b/src/view/screens/Home.tsx @@ -1,18 +1,20 @@ import React from 'react' import {FlatList, View} from 'react-native' import {useFocusEffect, useIsFocused} from '@react-navigation/native' +import {AppBskyFeedGetFeed as GetCustomFeed} from '@atproto/api' import {observer} from 'mobx-react-lite' import useAppState from 'react-native-appstate-hook' +import isEqual from 'lodash.isequal' import {NativeStackScreenProps, HomeTabNavigatorParams} from 'lib/routes/types' import {PostsFeedModel} from 'state/models/feeds/posts' import {withAuthRequired} from 'view/com/auth/withAuthRequired' import {useTabFocusEffect} from 'lib/hooks/useTabFocusEffect' import {Feed} from '../com/posts/Feed' import {FollowingEmptyState} from 'view/com/posts/FollowingEmptyState' -import {WhatsHotEmptyState} from 'view/com/posts/WhatsHotEmptyState' +import {CustomFeedEmptyState} from 'view/com/posts/CustomFeedEmptyState' import {LoadLatestBtn} from '../com/util/load-latest/LoadLatestBtn' import {FeedsTabBar} from '../com/pager/FeedsTabBar' -import {Pager, RenderTabBarFnProps} from 'view/com/pager/Pager' +import {Pager, PagerRef, RenderTabBarFnProps} from 'view/com/pager/Pager' import {FAB} from '../com/util/fab/FAB' import {useStores} from 'state/index' import {s} from 'lib/styles' @@ -21,30 +23,37 @@ import {useAnalytics} from 'lib/analytics' import {ComposeIcon2} from 'lib/icons' import {isDesktopWeb} from 'platform/detection' -const HEADER_OFFSET = isDesktopWeb ? 50 : 40 +const HEADER_OFFSET = isDesktopWeb ? 50 : 78 const POLL_FREQ = 30e3 // 30sec type Props = NativeStackScreenProps<HomeTabNavigatorParams, 'Home'> export const HomeScreen = withAuthRequired( observer((_opts: Props) => { const store = useStores() + const pagerRef = React.useRef<PagerRef>(null) const [selectedPage, setSelectedPage] = React.useState(0) - const [initialLanguages] = React.useState( - store.preferences.contentLanguages, - ) - - const algoFeed: PostsFeedModel = React.useMemo(() => { - const feed = new PostsFeedModel(store, 'goodstuff', {}) - feed.setup() - return feed - }, [store]) + const [customFeeds, setCustomFeeds] = React.useState<PostsFeedModel[]>([]) React.useEffect(() => { - // refresh whats hot when lang preferences change - if (initialLanguages !== store.preferences.contentLanguages) { - algoFeed.refresh() + const {pinned} = store.me.savedFeeds + if ( + isEqual( + pinned.map(p => p.uri), + customFeeds.map(f => (f.params as GetCustomFeed.QueryParams).feed), + ) + ) { + // no changes + return + } + + const feeds = [] + for (const feed of pinned) { + const model = new PostsFeedModel(store, 'custom', {feed: feed.uri}) + model.setup() + feeds.push(model) } - }, [initialLanguages, store.preferences.contentLanguages, algoFeed]) + setCustomFeeds(feeds) + }, [store, store.me.savedFeeds.pinned, customFeeds, setCustomFeeds]) useFocusEffect( React.useCallback(() => { @@ -86,18 +95,17 @@ export const HomeScreen = withAuthRequired( return <FollowingEmptyState /> }, []) - const renderWhatsHotEmptyState = React.useCallback(() => { - return <WhatsHotEmptyState /> + const renderCustomFeedEmptyState = React.useCallback(() => { + return <CustomFeedEmptyState /> }, []) - const initialPage = store.me.followsCount === 0 ? 1 : 0 return ( <Pager + ref={pagerRef} testID="homeScreen" onPageSelected={onPageSelected} renderTabBar={renderTabBar} - tabBarPosition="top" - initialPage={initialPage}> + tabBarPosition="top"> <FeedPage key="1" testID="followingFeedPage" @@ -105,13 +113,17 @@ export const HomeScreen = withAuthRequired( feed={store.me.mainFeed} renderEmptyState={renderFollowingEmptyState} /> - <FeedPage - key="2" - testID="whatshotFeedPage" - isPageFocused={selectedPage === 1} - feed={algoFeed} - renderEmptyState={renderWhatsHotEmptyState} - /> + {customFeeds.map((f, index) => { + return ( + <FeedPage + key={(f.params as GetCustomFeed.QueryParams).feed} + testID="customFeedPage" + isPageFocused={selectedPage === 1 + index} + feed={f} + renderEmptyState={renderCustomFeedEmptyState} + /> + ) + })} </Pager> ) }), @@ -130,7 +142,8 @@ const FeedPage = observer( renderEmptyState?: () => JSX.Element }) => { const store = useStores() - const onMainScroll = useOnMainScroll(store) + const [onMainScroll, isScrolledDown, resetMainScroll] = + useOnMainScroll(store) const {screen, track} = useAnalytics() const scrollElRef = React.useRef<FlatList>(null) const {appState} = useAppState({ @@ -158,12 +171,13 @@ const FeedPage = observer( const scrollToTop = React.useCallback(() => { scrollElRef.current?.scrollToOffset({offset: -HEADER_OFFSET}) - }, [scrollElRef]) + resetMainScroll() + }, [scrollElRef, resetMainScroll]) const onSoftReset = React.useCallback(() => { if (isPageFocused) { - feed.refresh() scrollToTop() + feed.refresh() } }, [isPageFocused, scrollToTop, feed]) @@ -188,7 +202,7 @@ const FeedPage = observer( } }, [store, doPoll, onSoftReset, screen, feed]), ) - // fires when tab is actived/deactivated + // fires when tab is activated/deactivated // - check for latest useTabFocusEffect( 'Home', @@ -224,6 +238,7 @@ const FeedPage = observer( feed.refresh() }, [feed, scrollToTop]) + const hasNew = feed.hasNewLatest && !feed.isRefreshing return ( <View testID={testID} style={s.h100pct}> <Feed @@ -234,11 +249,17 @@ const FeedPage = observer( showPostFollowBtn onPressTryAgain={onPressTryAgain} onScroll={onMainScroll} + scrollEventThrottle={100} renderEmptyState={renderEmptyState} headerOffset={HEADER_OFFSET} /> - {feed.hasNewLatest && !feed.isRefreshing && ( - <LoadLatestBtn onPress={onPressLoadLatest} label="posts" /> + {(isScrolledDown || hasNew) && ( + <LoadLatestBtn + onPress={onPressLoadLatest} + label="Load new posts" + showIndicator={hasNew} + minimalShellMode={store.shell.minimalShellMode} + /> )} <FAB testID="composeFAB" diff --git a/src/view/screens/ModerationMutedAccounts.tsx b/src/view/screens/ModerationMutedAccounts.tsx index ec732f682..22b8c0d33 100644 --- a/src/view/screens/ModerationMutedAccounts.tsx +++ b/src/view/screens/ModerationMutedAccounts.tsx @@ -100,7 +100,7 @@ export const ModerationMutedAccounts = withAuthRequired( <FlatList style={[!isDesktopWeb && styles.flex1]} data={mutedAccounts.mutes} - keyExtractor={(item: ActorDefs.ProfileView) => item.did} + keyExtractor={item => item.did} refreshControl={ <RefreshControl refreshing={mutedAccounts.isRefreshing} diff --git a/src/view/screens/Notifications.tsx b/src/view/screens/Notifications.tsx index 8d6f7c83a..4db1d14ae 100644 --- a/src/view/screens/Notifications.tsx +++ b/src/view/screens/Notifications.tsx @@ -25,7 +25,8 @@ type Props = NativeStackScreenProps< export const NotificationsScreen = withAuthRequired( observer(({}: Props) => { const store = useStores() - const onMainScroll = useOnMainScroll(store) + const [onMainScroll, isScrolledDown, resetMainScroll] = + useOnMainScroll(store) const scrollElRef = React.useRef<FlatList>(null) const {screen} = useAnalytics() @@ -37,7 +38,8 @@ export const NotificationsScreen = withAuthRequired( const scrollToTop = React.useCallback(() => { scrollElRef.current?.scrollToOffset({offset: 0}) - }, [scrollElRef]) + resetMainScroll() + }, [scrollElRef, resetMainScroll]) const onPressLoadLatest = React.useCallback(() => { scrollToTop() @@ -86,6 +88,9 @@ export const NotificationsScreen = withAuthRequired( ), ) + const hasNew = + store.me.notifications.hasNewLatest && + !store.me.notifications.isRefreshing return ( <View testID="notificationsScreen" style={s.hContentRegion}> <ViewHeader title="Notifications" canGoBack={false} /> @@ -96,10 +101,14 @@ export const NotificationsScreen = withAuthRequired( onScroll={onMainScroll} scrollElRef={scrollElRef} /> - {store.me.notifications.hasNewLatest && - !store.me.notifications.isRefreshing && ( - <LoadLatestBtn onPress={onPressLoadLatest} label="notifications" /> - )} + {(isScrolledDown || hasNew) && ( + <LoadLatestBtn + onPress={onPressLoadLatest} + label="Load new notifications" + showIndicator={hasNew} + minimalShellMode={true} + /> + )} </View> ) }), diff --git a/src/view/screens/Profile.tsx b/src/view/screens/Profile.tsx index b6d92e46b..a34ceb32c 100644 --- a/src/view/screens/Profile.tsx +++ b/src/view/screens/Profile.tsx @@ -9,7 +9,7 @@ import {CenteredView} from '../com/util/Views' import {ScreenHider} from 'view/com/util/moderation/ScreenHider' import {ProfileUiModel, Sections} from 'state/models/ui/profile' import {useStores} from 'state/index' -import {PostsFeedSliceModel} from 'state/models/feeds/posts' +import {PostsFeedSliceModel} from 'state/models/feeds/post' import {ProfileHeader} from '../com/profile/ProfileHeader' import {FeedSlice} from '../com/posts/FeedSlice' import {ListCard} from 'view/com/lists/ListCard' @@ -25,6 +25,8 @@ import {FAB} from '../com/util/fab/FAB' import {s, colors} from 'lib/styles' import {useAnalytics} from 'lib/analytics' import {ComposeIcon2} from 'lib/icons' +import {CustomFeed} from 'view/com/feeds/CustomFeed' +import {CustomFeedModel} from 'state/models/feeds/custom-feed' import {useSetTitle} from 'lib/hooks/useSetTitle' import {combinedDisplayName} from 'lib/strings/display-names' @@ -45,6 +47,10 @@ export const ProfileScreen = withAuthRequired( ) useSetTitle(combinedDisplayName(uiState.profile)) + useEffect(() => { + setHasSetup(false) + }, [route.params.name]) + useFocusEffect( React.useCallback(() => { let aborted = false @@ -118,6 +124,7 @@ export const ProfileScreen = withAuthRequired( }, [uiState.showLoadingMoreFooter]) const renderItem = React.useCallback( (item: any) => { + // if section is lists if (uiState.selectedView === Sections.Lists) { if (item === ProfileUiModel.LOADING_ITEM) { return <ProfileCardFeedLoadingPlaceholder /> @@ -142,6 +149,32 @@ export const ProfileScreen = withAuthRequired( } else { return <ListCard testID={`list-${item.name}`} list={item} /> } + // if section is custom algorithms + } else if (uiState.selectedView === Sections.CustomAlgorithms) { + if (item === ProfileUiModel.LOADING_ITEM) { + return <ProfileCardFeedLoadingPlaceholder /> + } else if (item._reactKey === '__error__') { + return ( + <View style={s.p5}> + <ErrorMessage + message={item.error} + onPressTryAgain={onPressTryAgain} + /> + </View> + ) + } else if (item === ProfileUiModel.EMPTY_ITEM) { + return ( + <EmptyState + testID="customAlgorithmsEmpty" + icon="list-ul" + message="No custom algorithms yet!" + style={styles.emptyState} + /> + ) + } else if (item instanceof CustomFeedModel) { + return <CustomFeed item={item} showSaveBtn showLikes /> + } + // if section is posts or posts & replies } else { if (item === ProfileUiModel.END_ITEM) { return <Text style={styles.endItem}>- end of feed -</Text> diff --git a/src/view/screens/ProfileList.tsx b/src/view/screens/ProfileList.tsx index 01f27bae1..7c3ed831c 100644 --- a/src/view/screens/ProfileList.tsx +++ b/src/view/screens/ProfileList.tsx @@ -87,7 +87,7 @@ export const ProfileListScreen = withAuthRequired( return <EmptyState icon="users-slash" message="This list is empty!" /> }, []) - const renderHeaderBtn = React.useCallback(() => { + const renderHeaderBtns = React.useCallback(() => { return ( <View style={styles.headerBtns}> {list?.isOwner && ( @@ -148,7 +148,7 @@ export const ProfileListScreen = withAuthRequired( pal.border, ]} testID="moderationMutelistsScreen"> - <ViewHeader title="" renderButton={renderHeaderBtn} /> + <ViewHeader title="" renderButton={renderHeaderBtns} /> <ListItems list={list} renderEmptyState={renderEmptyState} diff --git a/src/view/screens/SavedFeeds.tsx b/src/view/screens/SavedFeeds.tsx new file mode 100644 index 000000000..103b18c70 --- /dev/null +++ b/src/view/screens/SavedFeeds.tsx @@ -0,0 +1,293 @@ +import React, {useCallback, useMemo} from 'react' +import { + RefreshControl, + StyleSheet, + View, + ActivityIndicator, + Pressable, + TouchableOpacity, +} from 'react-native' +import {useFocusEffect} from '@react-navigation/native' +import {NativeStackScreenProps} from '@react-navigation/native-stack' +import {useAnalytics} from 'lib/analytics' +import {usePalette} from 'lib/hooks/usePalette' +import {CommonNavigatorParams} from 'lib/routes/types' +import {observer} from 'mobx-react-lite' +import {useStores} from 'state/index' +import {withAuthRequired} from 'view/com/auth/withAuthRequired' +import {ViewHeader} from 'view/com/util/ViewHeader' +import {CenteredView} from 'view/com/util/Views' +import {Text} from 'view/com/util/text/Text' +import {isDesktopWeb, isWeb} from 'platform/detection' +import {s, colors} from 'lib/styles' +import DraggableFlatList, { + ShadowDecorator, + ScaleDecorator, +} from 'react-native-draggable-flatlist' +import {CustomFeed} from 'view/com/feeds/CustomFeed' +import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' +import {CustomFeedModel} from 'state/models/feeds/custom-feed' +import * as Toast from 'view/com/util/Toast' +import {Haptics} from 'lib/haptics' +import {Link, TextLink} from 'view/com/util/Link' + +type Props = NativeStackScreenProps<CommonNavigatorParams, 'SavedFeeds'> + +export const SavedFeeds = withAuthRequired( + observer(({}: Props) => { + const pal = usePalette('default') + const store = useStores() + const {screen} = useAnalytics() + + const savedFeeds = useMemo(() => store.me.savedFeeds, [store]) + useFocusEffect( + useCallback(() => { + screen('SavedFeeds') + store.shell.setMinimalShellMode(false) + savedFeeds.refresh() + }, [screen, store, savedFeeds]), + ) + + const renderListEmptyComponent = useCallback(() => { + return ( + <View + style={[ + pal.border, + !isDesktopWeb && s.flex1, + pal.viewLight, + styles.empty, + ]}> + <Text type="lg" style={[pal.text]}> + You don't have any saved feeds. + </Text> + </View> + ) + }, [pal]) + + const renderListFooterComponent = useCallback(() => { + return ( + <> + <View style={[styles.footerLinks, pal.border]}> + <Link style={styles.footerLink} href="/search/feeds"> + <FontAwesomeIcon + icon="search" + size={18} + color={pal.colors.icon} + /> + <Text type="lg-medium" style={pal.textLight}> + Discover new feeds + </Text> + </Link> + </View> + <View style={styles.footerText}> + <Text type="sm" style={pal.textLight}> + Feeds are custom algorithms that users build with a little coding + expertise.{' '} + <TextLink + type="sm" + style={pal.link} + href="https://github.com/bluesky-social/feed-generator" + text="See this guide" + />{' '} + for more information. + </Text> + </View> + {savedFeeds.isLoading && <ActivityIndicator />} + </> + ) + }, [pal, savedFeeds.isLoading]) + + const onRefresh = useCallback(() => savedFeeds.refresh(), [savedFeeds]) + + const onDragEnd = useCallback( + async ({data}) => { + try { + await savedFeeds.reorderPinnedFeeds(data) + } catch (e) { + Toast.show('There was an issue contacting the server') + store.log.error('Failed to save pinned feed order', {e}) + } + }, + [savedFeeds, store], + ) + + return ( + <CenteredView + style={[ + s.hContentRegion, + pal.border, + isDesktopWeb && styles.desktopContainer, + ]}> + <ViewHeader + title="Edit My Feeds" + showOnDesktop + showBorder={!isDesktopWeb} + /> + <DraggableFlatList + containerStyle={[!isDesktopWeb && s.flex1]} + data={savedFeeds.all} + keyExtractor={item => item.data.uri} + refreshing={savedFeeds.isRefreshing} + refreshControl={ + <RefreshControl + refreshing={savedFeeds.isRefreshing} + onRefresh={onRefresh} + tintColor={pal.colors.text} + titleColor={pal.colors.text} + /> + } + renderItem={({item, drag}) => <ListItem item={item} drag={drag} />} + getItemLayout={(data, index) => ({ + length: 77, + offset: 77 * index, + index, + })} + initialNumToRender={10} + ListFooterComponent={renderListFooterComponent} + ListEmptyComponent={renderListEmptyComponent} + extraData={savedFeeds.isLoading} + onDragEnd={onDragEnd} + /> + </CenteredView> + ) + }), +) + +const ListItem = observer( + ({item, drag}: {item: CustomFeedModel; drag: () => void}) => { + const pal = usePalette('default') + const store = useStores() + const savedFeeds = useMemo(() => store.me.savedFeeds, [store]) + const isPinned = savedFeeds.isPinned(item) + + const onTogglePinned = useCallback(() => { + Haptics.default() + savedFeeds.togglePinnedFeed(item).catch(e => { + Toast.show('There was an issue contacting the server') + store.log.error('Failed to toggle pinned feed', {e}) + }) + }, [savedFeeds, item, store]) + const onPressUp = useCallback( + () => + savedFeeds.movePinnedFeed(item, 'up').catch(e => { + Toast.show('There was an issue contacting the server') + store.log.error('Failed to set pinned feed order', {e}) + }), + [store, savedFeeds, item], + ) + const onPressDown = useCallback( + () => + savedFeeds.movePinnedFeed(item, 'down').catch(e => { + Toast.show('There was an issue contacting the server') + store.log.error('Failed to set pinned feed order', {e}) + }), + [store, savedFeeds, item], + ) + + return ( + <ScaleDecorator> + <ShadowDecorator> + <Pressable + accessibilityRole="button" + onLongPress={isPinned ? drag : undefined} + delayLongPress={200} + style={[styles.itemContainer, pal.border]}> + {isPinned && isWeb ? ( + <View style={styles.webArrowButtonsContainer}> + <TouchableOpacity + accessibilityRole="button" + onPress={onPressUp}> + <FontAwesomeIcon + icon="arrow-up" + size={12} + style={[pal.text, styles.webArrowUpButton]} + /> + </TouchableOpacity> + <TouchableOpacity + accessibilityRole="button" + onPress={onPressDown}> + <FontAwesomeIcon + icon="arrow-down" + size={12} + style={[pal.text]} + /> + </TouchableOpacity> + </View> + ) : isPinned ? ( + <FontAwesomeIcon + icon="bars" + size={20} + color={pal.colors.text} + style={s.ml20} + /> + ) : null} + <CustomFeed + key={item.data.uri} + item={item} + showSaveBtn + style={styles.noBorder} + /> + <TouchableOpacity + accessibilityRole="button" + hitSlop={10} + onPress={onTogglePinned}> + <FontAwesomeIcon + icon="thumb-tack" + size={20} + color={isPinned ? colors.blue3 : pal.colors.icon} + /> + </TouchableOpacity> + </Pressable> + </ShadowDecorator> + </ScaleDecorator> + ) + }, +) + +const styles = StyleSheet.create({ + desktopContainer: { + borderLeftWidth: 1, + borderRightWidth: 1, + minHeight: '100vh', + }, + empty: { + paddingHorizontal: 20, + paddingVertical: 20, + borderRadius: 16, + marginHorizontal: 24, + marginTop: 10, + }, + itemContainer: { + flex: 1, + flexDirection: 'row', + alignItems: 'center', + borderBottomWidth: 1, + paddingRight: 16, + }, + webArrowButtonsContainer: { + paddingLeft: 16, + flexDirection: 'column', + justifyContent: 'space-around', + }, + webArrowUpButton: { + marginBottom: 10, + }, + noBorder: { + borderTopWidth: 0, + }, + footerText: { + paddingHorizontal: 26, + paddingTop: 22, + paddingBottom: 100, + }, + footerLinks: { + borderBottomWidth: 1, + borderTopWidth: 0, + }, + footerLink: { + flexDirection: 'row', + paddingHorizontal: 26, + paddingVertical: 18, + gap: 18, + }, +}) diff --git a/src/view/screens/SearchMobile.tsx b/src/view/screens/SearchMobile.tsx index f9b4864b2..c9d09373e 100644 --- a/src/view/screens/SearchMobile.tsx +++ b/src/view/screens/SearchMobile.tsx @@ -35,7 +35,7 @@ export const SearchScreen = withAuthRequired( const store = useStores() const scrollViewRef = React.useRef<ScrollView>(null) const flatListRef = React.useRef<FlatList>(null) - const onMainScroll = useOnMainScroll(store) + const [onMainScroll] = useOnMainScroll(store) const [isInputFocused, setIsInputFocused] = React.useState<boolean>(false) const [query, setQuery] = React.useState<string>('') const autocompleteView = React.useMemo<UserAutocompleteModel>( diff --git a/src/view/screens/Settings.tsx b/src/view/screens/Settings.tsx index b222d7dbd..3f6fa84d3 100644 --- a/src/view/screens/Settings.tsx +++ b/src/view/screens/Settings.tsx @@ -142,6 +142,11 @@ export const SettingsScreen = withAuthRequired( store.shell.openModal({name: 'delete-account'}) }, [store]) + const onPressResetPreferences = React.useCallback(async () => { + await store.preferences.reset() + Toast.show('Preferences reset') + }, [store]) + return ( <View style={[s.hContentRegion]} testID="settingsScreen"> <ViewHeader title="Settings" /> @@ -330,6 +335,22 @@ export const SettingsScreen = withAuthRequired( App passwords </Text> </Link> + <Link + testID="savedFeedsBtn" + style={[styles.linkCard, pal.view, isSwitching && styles.dimmed]} + accessibilityHint="Saved Feeds" + accessibilityLabel="Opens screen with all saved feeds" + href="/settings/saved-feeds"> + <View style={[styles.iconContainer, pal.btn]}> + <FontAwesomeIcon + icon="satellite-dish" + style={pal.text as FontAwesomeIconStyle} + /> + </View> + <Text type="lg" style={pal.text}> + Saved Feeds + </Text> + </Link> <TouchableOpacity testID="contentLanguagesBtn" style={[styles.linkCard, pal.view, isSwitching && styles.dimmed]} @@ -406,8 +427,18 @@ export const SettingsScreen = withAuthRequired( Storybook </Text> </Link> + {__DEV__ ? ( + <Link + style={[pal.view, styles.linkCardNoIcon]} + onPress={onPressResetPreferences} + title="Debug tools"> + <Text type="lg" style={pal.text}> + Reset preferences state + </Text> + </Link> + ) : null} <Text type="sm" style={[styles.buildInfo, pal.textLight]}> - Build version {AppInfo.appVersion} ({AppInfo.buildVersion}) + Build version {AppInfo.appVersion} </Text> <View style={s.footerSpacer} /> </ScrollView> diff --git a/src/view/shell/Drawer.tsx b/src/view/shell/Drawer.tsx index 79c713e2d..cf8639338 100644 --- a/src/view/shell/Drawer.tsx +++ b/src/view/shell/Drawer.tsx @@ -2,6 +2,7 @@ import React, {ComponentProps} from 'react' import { Linking, SafeAreaView, + ScrollView, StyleProp, StyleSheet, TouchableOpacity, @@ -27,6 +28,8 @@ import { MagnifyingGlassIcon2, MagnifyingGlassIcon2Solid, UserIconSolid, + SatelliteDishIcon, + SatelliteDishIconSolid, HandIcon, } from 'lib/icons' import {UserAvatar} from 'view/com/util/UserAvatar' @@ -39,7 +42,7 @@ import {getTabState, TabState} from 'lib/routes/helpers' import {NavigationProp} from 'lib/routes/types' import {useNavigationTabState} from 'lib/hooks/useNavigationTabState' import {isWeb} from 'platform/detection' -import {formatCount} from 'view/com/util/numeric/format' +import {formatCount, formatCountShortOnly} from 'view/com/util/numeric/format' export const DrawerContent = observer(() => { const theme = useTheme() @@ -47,7 +50,7 @@ export const DrawerContent = observer(() => { const store = useStores() const navigation = useNavigation<NavigationProp>() const {track} = useAnalytics() - const {isAtHome, isAtSearch, isAtNotifications, isAtMyProfile} = + const {isAtHome, isAtSearch, isAtFeeds, isAtNotifications, isAtMyProfile} = useNavigationTabState() const {notifications} = store.me @@ -94,6 +97,11 @@ export const DrawerContent = observer(() => { onPressTab('MyProfile') }, [onPressTab]) + const onPressMyFeeds = React.useCallback( + () => onPressTab('Feeds'), + [onPressTab], + ) + const onPressModeration = React.useCallback(() => { track('Menu:ItemClicked', {url: 'Moderation'}) navigation.navigate('Moderation') @@ -140,19 +148,18 @@ export const DrawerContent = observer(() => { type="xl" style={[pal.textLight, styles.profileCardFollowers]}> <Text type="xl-medium" style={pal.text}> - {formatCount(store.me.followersCount ?? 0)} + {formatCountShortOnly(store.me.followersCount ?? 0)} </Text>{' '} {pluralize(store.me.followersCount || 0, 'follower')} ·{' '} <Text type="xl-medium" style={pal.text}> - {formatCount(store.me.followsCount ?? 0)} + {formatCountShortOnly(store.me.followsCount ?? 0)} </Text>{' '} following </Text> </TouchableOpacity> </View> <InviteCodes /> - <View style={s.flex1} /> - <View style={styles.main}> + <ScrollView style={styles.main}> <MenuItem icon={ isAtSearch ? ( @@ -226,12 +233,27 @@ export const DrawerContent = observer(() => { /> <MenuItem icon={ - <HandIcon - strokeWidth={5} - style={pal.text as FontAwesomeIconStyle} - size={24} - /> + isAtFeeds ? ( + <SatelliteDishIconSolid + strokeWidth={1.5} + style={pal.text as FontAwesomeIconStyle} + size={24} + /> + ) : ( + <SatelliteDishIcon + strokeWidth={1.5} + style={pal.text as FontAwesomeIconStyle} + size={24} + /> + ) } + label="My Feeds" + accessibilityLabel="My Feeds" + accessibilityHint="" + onPress={onPressMyFeeds} + /> + <MenuItem + icon={<HandIcon strokeWidth={5} style={pal.text} size={24} />} label="Moderation" accessibilityLabel="Moderation" accessibilityHint="" @@ -271,8 +293,8 @@ export const DrawerContent = observer(() => { accessibilityHint="" onPress={onPressSettings} /> - </View> - <View style={s.flex1} /> + <View style={styles.smallSpacer} /> + </ScrollView> <View style={styles.footer}> <TouchableOpacity accessibilityRole="link" @@ -405,6 +427,10 @@ const styles = StyleSheet.create({ }, main: { paddingLeft: 20, + paddingTop: 20, + }, + smallSpacer: { + height: 20, }, profileCardDisplayName: { diff --git a/src/view/shell/bottom-bar/BottomBar.tsx b/src/view/shell/bottom-bar/BottomBar.tsx index ef9499f9f..e8cba9047 100644 --- a/src/view/shell/bottom-bar/BottomBar.tsx +++ b/src/view/shell/bottom-bar/BottomBar.tsx @@ -18,23 +18,24 @@ import { HomeIconSolid, MagnifyingGlassIcon2, MagnifyingGlassIcon2Solid, + SatelliteDishIcon, + SatelliteDishIconSolid, BellIcon, BellIconSolid, - UserIcon, - UserIconSolid, } from 'lib/icons' import {usePalette} from 'lib/hooks/usePalette' import {getTabState, TabState} from 'lib/routes/helpers' import {styles} from './BottomBarStyles' import {useMinimalShellMode} from 'lib/hooks/useMinimalShellMode' import {useNavigationTabState} from 'lib/hooks/useNavigationTabState' +import {UserAvatar} from 'view/com/util/UserAvatar' export const BottomBar = observer(({navigation}: BottomTabBarProps) => { const store = useStores() const pal = usePalette('default') const safeAreaInsets = useSafeAreaInsets() const {track} = useAnalytics() - const {isAtHome, isAtSearch, isAtNotifications, isAtMyProfile} = + const {isAtHome, isAtSearch, isAtFeeds, isAtNotifications, isAtMyProfile} = useNavigationTabState() const {footerMinimalShellTransform} = useMinimalShellMode() @@ -60,6 +61,10 @@ export const BottomBar = observer(({navigation}: BottomTabBarProps) => { () => onPressTab('Search'), [onPressTab], ) + const onPressFeeds = React.useCallback( + () => onPressTab('Feeds'), + [onPressTab], + ) const onPressNotifications = React.useCallback( () => onPressTab('Notifications'), [onPressTab], @@ -122,6 +127,28 @@ export const BottomBar = observer(({navigation}: BottomTabBarProps) => { accessibilityHint="" /> <Btn + testID="bottomBarFeedsBtn" + icon={ + isAtFeeds ? ( + <SatelliteDishIconSolid + size={25} + style={[styles.ctrlIcon, pal.text, styles.searchIcon]} + strokeWidth={1.8} + /> + ) : ( + <SatelliteDishIcon + size={25} + style={[styles.ctrlIcon, pal.text, styles.searchIcon]} + strokeWidth={1.8} + /> + ) + } + onPress={onPressFeeds} + accessibilityRole="tab" + accessibilityLabel="Feeds" + accessibilityHint="" + /> + <Btn testID="bottomBarNotificationsBtn" icon={ isAtNotifications ? ( @@ -154,17 +181,19 @@ export const BottomBar = observer(({navigation}: BottomTabBarProps) => { icon={ <View style={styles.ctrlIconSizingWrapper}> {isAtMyProfile ? ( - <UserIconSolid - size={28} - strokeWidth={1.5} - style={[styles.ctrlIcon, pal.text, styles.profileIcon]} - /> + <View + style={[ + styles.ctrlIcon, + pal.text, + styles.profileIcon, + styles.onProfile, + ]}> + <UserAvatar avatar={store.me.avatar} size={27} /> + </View> ) : ( - <UserIcon - size={28} - strokeWidth={1.5} - style={[styles.ctrlIcon, pal.text, styles.profileIcon]} - /> + <View style={[styles.ctrlIcon, pal.text, styles.profileIcon]}> + <UserAvatar avatar={store.me.avatar} size={28} /> + </View> )} </View> } diff --git a/src/view/shell/bottom-bar/BottomBarStyles.tsx b/src/view/shell/bottom-bar/BottomBarStyles.tsx index 3d5adbc9e..2414b9911 100644 --- a/src/view/shell/bottom-bar/BottomBarStyles.tsx +++ b/src/view/shell/bottom-bar/BottomBarStyles.tsx @@ -58,4 +58,9 @@ export const styles = StyleSheet.create({ profileIcon: { top: -4, }, + onProfile: { + borderColor: colors.black, + borderWidth: 1, + borderRadius: 100, + }, }) diff --git a/src/view/shell/bottom-bar/BottomBarWeb.tsx b/src/view/shell/bottom-bar/BottomBarWeb.tsx index b7daac5af..cbaafd1fd 100644 --- a/src/view/shell/bottom-bar/BottomBarWeb.tsx +++ b/src/view/shell/bottom-bar/BottomBarWeb.tsx @@ -15,6 +15,8 @@ import { HomeIconSolid, MagnifyingGlassIcon2, MagnifyingGlassIcon2Solid, + SatelliteDishIcon, + SatelliteDishIconSolid, UserIcon, } from 'lib/icons' import {Link} from 'view/com/util/Link' @@ -61,6 +63,18 @@ export const BottomBarWeb = observer(() => { ) }} </NavItem> + <NavItem routeName="Feeds" href="/feeds"> + {({isActive}) => { + const Icon = isActive ? SatelliteDishIconSolid : SatelliteDishIcon + return ( + <Icon + size={25} + style={[styles.ctrlIcon, pal.text, styles.searchIcon]} + strokeWidth={1.8} + /> + ) + }} + </NavItem> <NavItem routeName="Notifications" href="/notifications"> {({isActive}) => { const Icon = isActive ? BellIconSolid : BellIcon diff --git a/src/view/shell/desktop/LeftNav.tsx b/src/view/shell/desktop/LeftNav.tsx index ba48dd2ae..914dfb53a 100644 --- a/src/view/shell/desktop/LeftNav.tsx +++ b/src/view/shell/desktop/LeftNav.tsx @@ -30,6 +30,8 @@ import { CogIconSolid, ComposeIcon2, HandIcon, + SatelliteDishIcon, + SatelliteDishIconSolid, } from 'lib/icons' import {getCurrentRoute, isTab, isStateAtTabRoot} from 'lib/routes/helpers' import {NavigationProp} from 'lib/routes/types' @@ -89,14 +91,17 @@ const NavItem = observer( const pal = usePalette('default') const store = useStores() const [pathName] = React.useMemo(() => router.matchPath(href), [href]) - const currentRouteName = useNavigationState(state => { + const currentRouteInfo = useNavigationState(state => { if (!state) { - return 'Home' + return {name: 'Home'} } - return getCurrentRoute(state).name + return getCurrentRoute(state) }) - - const isCurrent = isTab(currentRouteName, pathName) + let isCurrent = + currentRouteInfo.name === 'Profile' + ? isTab(currentRouteInfo.name, pathName) && + currentRouteInfo.params.name === store.me.handle + : isTab(currentRouteInfo.name, pathName) const {onPress} = useLinkProps({to: href}) const onPressWrapped = React.useCallback( (e: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => { @@ -196,6 +201,24 @@ export const DesktopLeftNav = observer(function DesktopLeftNav() { label="Search" /> <NavItem + href="/feeds" + icon={ + <SatelliteDishIcon + strokeWidth={1.75} + style={pal.text as FontAwesomeIconStyle} + size={24} + /> + } + iconFilled={ + <SatelliteDishIconSolid + strokeWidth={1.75} + style={pal.text as FontAwesomeIconStyle} + size={24} + /> + } + label="My Feeds" + /> + <NavItem href="/notifications" count={store.me.notifications.unreadCountLabel} icon={<BellIcon strokeWidth={2} size={24} style={pal.text} />} diff --git a/src/view/shell/index.web.tsx b/src/view/shell/index.web.tsx index 68ce370ed..5e3875268 100644 --- a/src/view/shell/index.web.tsx +++ b/src/view/shell/index.web.tsx @@ -36,7 +36,7 @@ const ShellInner = observer(() => { <FlatNavigator /> </ErrorBoundary> </View> - {isDesktop && ( + {isDesktop && store.session.hasSession && ( <> <DesktopLeftNav /> <DesktopRightNav /> |