Merge branch '2011-default-pin-feed-on-add' of https://github.com/CooperEdmunds/social-app into CooperEdmunds-2011-default-pin-feed-on-add
commit
6e30c339da
|
@ -17,6 +17,7 @@ import {useModalControls} from '#/state/modals'
|
|||
import {msg} from '@lingui/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {
|
||||
usePinFeedMutation,
|
||||
UsePreferencesQueryResponse,
|
||||
usePreferencesQuery,
|
||||
useSaveFeedMutation,
|
||||
|
@ -32,6 +33,7 @@ export function FeedSourceCard({
|
|||
showDescription = false,
|
||||
showLikes = false,
|
||||
LoadingComponent,
|
||||
pinOnSave = false,
|
||||
}: {
|
||||
feedUri: string
|
||||
style?: StyleProp<ViewStyle>
|
||||
|
@ -39,6 +41,7 @@ export function FeedSourceCard({
|
|||
showDescription?: boolean
|
||||
showLikes?: boolean
|
||||
LoadingComponent?: JSX.Element
|
||||
pinOnSave?: boolean
|
||||
}) {
|
||||
const {data: preferences} = usePreferencesQuery()
|
||||
const {data: feed} = useFeedSourceInfoQuery({uri: feedUri})
|
||||
|
@ -59,6 +62,7 @@ export function FeedSourceCard({
|
|||
showSaveBtn={showSaveBtn}
|
||||
showDescription={showDescription}
|
||||
showLikes={showLikes}
|
||||
pinOnSave={pinOnSave}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
@ -70,6 +74,7 @@ export function FeedSourceCardLoaded({
|
|||
showSaveBtn = false,
|
||||
showDescription = false,
|
||||
showLikes = false,
|
||||
pinOnSave = false,
|
||||
}: {
|
||||
feed: FeedSourceInfo
|
||||
preferences: UsePreferencesQueryResponse
|
||||
|
@ -77,6 +82,7 @@ export function FeedSourceCardLoaded({
|
|||
showSaveBtn?: boolean
|
||||
showDescription?: boolean
|
||||
showLikes?: boolean
|
||||
pinOnSave?: boolean
|
||||
}) {
|
||||
const pal = usePalette('default')
|
||||
const {_} = useLingui()
|
||||
|
@ -87,6 +93,7 @@ export function FeedSourceCardLoaded({
|
|||
useSaveFeedMutation()
|
||||
const {isPending: isRemovePending, mutateAsync: removeFeed} =
|
||||
useRemoveFeedMutation()
|
||||
const {isPending: isPinPending, mutateAsync: pinFeed} = usePinFeedMutation()
|
||||
|
||||
const isSaved = Boolean(preferences?.feeds?.saved?.includes(feed.uri))
|
||||
|
||||
|
@ -112,14 +119,18 @@ export function FeedSourceCardLoaded({
|
|||
})
|
||||
} else {
|
||||
try {
|
||||
await saveFeed({uri: feed.uri})
|
||||
if (pinOnSave) {
|
||||
await pinFeed({uri: feed.uri})
|
||||
} else {
|
||||
await saveFeed({uri: feed.uri})
|
||||
}
|
||||
Toast.show('Added to my feeds')
|
||||
} catch (e) {
|
||||
Toast.show('There was an issue contacting your server')
|
||||
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
|
||||
|
||||
|
@ -159,7 +170,7 @@ export function FeedSourceCardLoaded({
|
|||
{showSaveBtn && feed.type === 'feed' && (
|
||||
<View>
|
||||
<Pressable
|
||||
disabled={isSavePending || isRemovePending}
|
||||
disabled={isSavePending || isPinPending || isRemovePending}
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={
|
||||
isSaved ? 'Remove from my feeds' : 'Add to my feeds'
|
||||
|
|
|
@ -437,6 +437,7 @@ export function FeedsScreen(_props: Props) {
|
|||
showSaveBtn={hasSession}
|
||||
showDescription
|
||||
showLikes
|
||||
pinOnSave
|
||||
/>
|
||||
)
|
||||
} else if (item.type === 'popularFeedsNoResults') {
|
||||
|
|
Loading…
Reference in New Issue