Add pinOnSave and use it in discover feeds list

zio/stable
Cooper Edmunds 2023-11-29 09:05:26 -05:00
parent 60886b76c8
commit ca357ecbcf
2 changed files with 15 additions and 3 deletions

View File

@ -17,6 +17,7 @@ import {useModalControls} from '#/state/modals'
import {msg} from '@lingui/macro' import {msg} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import { import {
usePinFeedMutation,
UsePreferencesQueryResponse, UsePreferencesQueryResponse,
usePreferencesQuery, usePreferencesQuery,
useSaveFeedMutation, useSaveFeedMutation,
@ -30,12 +31,14 @@ export function FeedSourceCard({
showSaveBtn = false, showSaveBtn = false,
showDescription = false, showDescription = false,
showLikes = false, showLikes = false,
pinOnSave = false,
}: { }: {
feedUri: string feedUri: string
style?: StyleProp<ViewStyle> style?: StyleProp<ViewStyle>
showSaveBtn?: boolean showSaveBtn?: boolean
showDescription?: boolean showDescription?: boolean
showLikes?: boolean showLikes?: boolean
pinOnSave?: boolean
}) { }) {
const {data: preferences} = usePreferencesQuery() const {data: preferences} = usePreferencesQuery()
const {data: feed} = useFeedSourceInfoQuery({uri: feedUri}) const {data: feed} = useFeedSourceInfoQuery({uri: feedUri})
@ -50,6 +53,7 @@ export function FeedSourceCard({
showSaveBtn={showSaveBtn} showSaveBtn={showSaveBtn}
showDescription={showDescription} showDescription={showDescription}
showLikes={showLikes} showLikes={showLikes}
pinOnSave={pinOnSave}
/> />
) )
} }
@ -61,6 +65,7 @@ export function FeedSourceCardLoaded({
showSaveBtn = false, showSaveBtn = false,
showDescription = false, showDescription = false,
showLikes = false, showLikes = false,
pinOnSave = false,
}: { }: {
feed: FeedSourceInfo feed: FeedSourceInfo
preferences: UsePreferencesQueryResponse preferences: UsePreferencesQueryResponse
@ -68,6 +73,7 @@ export function FeedSourceCardLoaded({
showSaveBtn?: boolean showSaveBtn?: boolean
showDescription?: boolean showDescription?: boolean
showLikes?: boolean showLikes?: boolean
pinOnSave?: boolean
}) { }) {
const pal = usePalette('default') const pal = usePalette('default')
const {_} = useLingui() const {_} = useLingui()
@ -78,6 +84,7 @@ export function FeedSourceCardLoaded({
useSaveFeedMutation() useSaveFeedMutation()
const {isPending: isRemovePending, mutateAsync: removeFeed} = const {isPending: isRemovePending, mutateAsync: removeFeed} =
useRemoveFeedMutation() useRemoveFeedMutation()
const {isPending: isPinPending, mutateAsync: pinFeed} = usePinFeedMutation()
const isSaved = Boolean(preferences?.feeds?.saved?.includes(feed.uri)) const isSaved = Boolean(preferences?.feeds?.saved?.includes(feed.uri))
@ -103,14 +110,18 @@ export function FeedSourceCardLoaded({
}) })
} else { } else {
try { try {
if (pinOnSave) {
await pinFeed({uri: feed.uri})
} else {
await saveFeed({uri: feed.uri}) await saveFeed({uri: feed.uri})
}
Toast.show('Added to my feeds') Toast.show('Added to my feeds')
} catch (e) { } catch (e) {
Toast.show('There was an issue contacting your server') Toast.show('There was an issue contacting your server')
logger.error('Failed to save feed', {error: e}) logger.error('Failed to save feed', {error: e})
} }
} }
}, [isSaved, openModal, feed, removeFeed, saveFeed, _]) }, [isSaved, openModal, feed, removeFeed, saveFeed, _, pinOnSave, pinFeed])
if (!feed || !preferences) return null if (!feed || !preferences) return null
@ -150,7 +161,7 @@ export function FeedSourceCardLoaded({
{showSaveBtn && feed.type === 'feed' && ( {showSaveBtn && feed.type === 'feed' && (
<View> <View>
<Pressable <Pressable
disabled={isSavePending || isRemovePending} disabled={isSavePending || isPinPending || isRemovePending}
accessibilityRole="button" accessibilityRole="button"
accessibilityLabel={ accessibilityLabel={
isSaved ? 'Remove from my feeds' : 'Add to my feeds' isSaved ? 'Remove from my feeds' : 'Add to my feeds'

View File

@ -437,6 +437,7 @@ export function FeedsScreen(_props: Props) {
showSaveBtn={hasSession} showSaveBtn={hasSession}
showDescription showDescription
showLikes showLikes
pinOnSave
/> />
) )
} else if (item.type === 'popularFeedsNoResults') { } else if (item.type === 'popularFeedsNoResults') {