diff --git a/src/state/queries/preferences/index.ts b/src/state/queries/preferences/index.ts index 48bb9b4c13..130a3e2af6 100644 --- a/src/state/queries/preferences/index.ts +++ b/src/state/queries/preferences/index.ts @@ -249,7 +249,11 @@ export function useSaveFeedMutation() { return useMutation({ mutationFn: async ({uri}) => { - await getAgent().addSavedFeed(uri) + await getAgent().addSavedFeedV2({ + type: 'feed', + value: uri, + pinned: false, + }) track('CustomFeed:Save') // triggers a refetch await queryClient.invalidateQueries({ @@ -262,9 +266,9 @@ export function useSaveFeedMutation() { export function useRemoveFeedMutation() { const queryClient = useQueryClient() - return useMutation({ - mutationFn: async ({uri}) => { - await getAgent().removeSavedFeed(uri) + return useMutation>({ + mutationFn: async ({id}) => { + await getAgent().removeSavedFeedV2(id) track('CustomFeed:Unsave') // triggers a refetch await queryClient.invalidateQueries({ @@ -279,7 +283,11 @@ export function usePinFeedMutation() { return useMutation({ mutationFn: async ({uri}) => { - await getAgent().addPinnedFeed(uri) + await getAgent().addSavedFeedV2({ + type: 'feed', + value: uri, + pinned: true, + }) track('CustomFeed:Pin', {uri}) // triggers a refetch await queryClient.invalidateQueries({ @@ -292,10 +300,13 @@ export function usePinFeedMutation() { export function useUnpinFeedMutation() { const queryClient = useQueryClient() - return useMutation({ - mutationFn: async ({uri}) => { - await getAgent().removePinnedFeed(uri) - track('CustomFeed:Unpin', {uri}) + return useMutation({ + mutationFn: async feed => { + await getAgent().updateSavedFeed({ + ...feed, + pinned: false, + }) + track('CustomFeed:Unpin', {uri: feed.value}) // triggers a refetch await queryClient.invalidateQueries({ queryKey: preferencesQueryKey, diff --git a/src/view/com/feeds/FeedSourceCard.tsx b/src/view/com/feeds/FeedSourceCard.tsx index c5cd9ff4c8..e9f1908b2e 100644 --- a/src/view/com/feeds/FeedSourceCard.tsx +++ b/src/view/com/feeds/FeedSourceCard.tsx @@ -5,7 +5,6 @@ import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' -import {useGate} from '#/lib/statsig/statsig' import {logger} from '#/logger' import {FeedSourceInfo, useFeedSourceInfoQuery} from '#/state/queries/feed' import { @@ -24,9 +23,6 @@ import {FeedLoadingPlaceholder} from '#/view/com/util/LoadingPlaceholder' import * as Toast from 'view/com/util/Toast' import {useTheme} from '#/alf' import {atoms as a} from '#/alf' -import {Button, ButtonIcon, ButtonText} from '#/components/Button' -import {Check_Stroke2_Corner0_Rounded as Check} from '#/components/icons/Check' -import {PrimaryAlgoNoticeDialog} from '#/components/PrimaryAlgoNoticeDialog' import * as Prompt from '#/components/Prompt' import {RichText} from '#/components/RichText' import {Text} from '../util/text/Text' @@ -93,8 +89,6 @@ export function FeedSourceCardLoaded({ const {_} = useLingui() const removePromptControl = Prompt.usePromptControl() const navigation = useNavigationDeduped() - const gate = useGate() - const primaryAlgoDialogControl = Prompt.usePromptControl() const {isPending: isSavePending, mutateAsync: saveFeed} = useSaveFeedMutation() @@ -102,7 +96,10 @@ export function FeedSourceCardLoaded({ useRemoveFeedMutation() const {isPending: isPinPending, mutateAsync: pinFeed} = usePinFeedMutation() - const isSaved = Boolean(preferences?.feeds?.saved?.includes(feed?.uri || '')) + const savedFeedConfig = preferences?.savedFeeds?.find( + f => f.value === feed?.uri, + ) + const isSaved = Boolean(savedFeedConfig) const onSave = React.useCallback(async () => { if (!feed) return @@ -121,17 +118,17 @@ export function FeedSourceCardLoaded({ }, [_, feed, pinFeed, pinOnSave, saveFeed]) const onUnsave = React.useCallback(async () => { - if (!feed) return + if (!savedFeedConfig) return try { - await removeFeed({uri: feed.uri}) + await removeFeed(savedFeedConfig) // await item.unsave() Toast.show(_(msg`Removed from my feeds`)) } catch (e) { Toast.show(_(msg`There was an issue contacting your server`)) logger.error('Failed to unsave feed', {message: e}) } - }, [_, feed, removeFeed]) + }, [_, removeFeed, savedFeedConfig]) const onToggleSaved = React.useCallback(async () => { // Only feeds can be un/saved, lists are handled elsewhere @@ -193,10 +190,6 @@ export function FeedSourceCardLoaded({ ) - const primaryAlgo = preferences?.primaryAlgorithm - const isPrimaryAlgo = - primaryAlgo?.enabled && primaryAlgo?.uri && primaryAlgo.uri === feed.uri - return ( <> {showSaveBtn && feed.type === 'feed' && ( - <> - {gate('reduced_onboarding_and_home_algo') && isPrimaryAlgo ? ( - - ) : ( - - - {isSaved ? ( - - ) : ( - - )} - - - )} - + + + {isSaved ? ( + + ) : ( + + )} + + )} @@ -315,8 +288,6 @@ export function FeedSourceCardLoaded({ confirmButtonCta={_(msg`Remove`)} confirmButtonColor="negative" /> - - ) }