Migrate ProfileList

This commit is contained in:
Eric Bailey
2024-04-22 18:20:46 -05:00
parent fe9ad6b820
commit 24543a2c4b
+34 -28
View File
@@ -23,10 +23,9 @@ import {
import {FeedDescriptor} from '#/state/queries/post-feed'
import {RQKEY as FEED_RQKEY} from '#/state/queries/post-feed'
import {
usePinFeedMutation,
useAddSavedFeedMutation,
usePreferencesQuery,
useSetSaveFeedsMutation,
useUnpinFeedMutation,
useRemoveFeedMutation,
} from '#/state/queries/preferences'
import {useResolveUriQuery} from '#/state/queries/resolve-uri'
import {truncateAndInvalidate} from '#/state/queries/util'
@@ -248,36 +247,47 @@ function Header({rkey, list}: {rkey: string; list: AppBskyGraphDefs.ListView}) {
const isBlocking = !!list.viewer?.blocked
const isMuting = !!list.viewer?.muted
const isOwner = list.creator.did === currentAccount?.did
const {isPending: isPinPending, mutateAsync: pinFeed} = usePinFeedMutation()
const {isPending: isUnpinPending, mutateAsync: unpinFeed} =
useUnpinFeedMutation()
const isPending = isPinPending || isUnpinPending
const {data: preferences} = usePreferencesQuery()
const {mutate: setSavedFeeds} = useSetSaveFeedsMutation()
const {track} = useAnalytics()
const playHaptic = useHaptics()
const {mutateAsync: addSavedFeed, isPending: isAddSavedFeedPending} =
useAddSavedFeedMutation()
const {mutateAsync: removeSavedFeed, isPending: isRemovePending} =
useRemoveFeedMutation()
const isPending = isAddSavedFeedPending || isRemovePending
const deleteListPromptControl = useDialogControl()
const subscribeMutePromptControl = useDialogControl()
const subscribeBlockPromptControl = useDialogControl()
const isPinned = preferences?.feeds?.pinned?.includes(list.uri)
const isSaved = preferences?.feeds?.saved?.includes(list.uri)
const savedFeedConfig = preferences?.savedFeeds?.find(
f => f.value === list.uri,
)
const isPinned = Boolean(savedFeedConfig?.pinned)
const onTogglePinned = React.useCallback(async () => {
playHaptic()
try {
if (isPinned) {
await unpinFeed({uri: list.uri})
if (savedFeedConfig) {
// only allow removal of non-pinned feeds from this view
await removeSavedFeed(savedFeedConfig)
Toast.show(_(msg`Removed from your feeds`))
} else {
await pinFeed({uri: list.uri})
await addSavedFeed({
type: 'list',
value: list.uri,
pinned: true,
})
Toast.show(_(msg`Saved to your feeds`))
}
} catch (e) {
Toast.show(_(msg`There was an issue contacting the server`))
logger.error('Failed to toggle pinned feed', {message: e})
}
}, [playHaptic, isPinned, unpinFeed, list.uri, pinFeed, _])
}, [playHaptic, addSavedFeed, removeSavedFeed, list.uri, _, savedFeedConfig])
const onSubscribeMute = useCallback(async () => {
try {
@@ -345,13 +355,8 @@ function Header({rkey, list}: {rkey: string; list: AppBskyGraphDefs.ListView}) {
const onPressDelete = useCallback(async () => {
await listDeleteMutation.mutateAsync({uri: list.uri})
if (isSaved || isPinned) {
const {saved, pinned} = preferences!.feeds
setSavedFeeds({
saved: isSaved ? saved.filter(uri => uri !== list.uri) : saved,
pinned: isPinned ? pinned.filter(uri => uri !== list.uri) : pinned,
})
if (savedFeedConfig) {
await removeSavedFeed(savedFeedConfig)
}
Toast.show(_(msg`List deleted`))
@@ -367,10 +372,8 @@ function Header({rkey, list}: {rkey: string; list: AppBskyGraphDefs.ListView}) {
navigation,
track,
_,
preferences,
isPinned,
isSaved,
setSavedFeeds,
removeSavedFeed,
savedFeedConfig,
])
const onPressReport = useCallback(() => {
@@ -444,7 +447,10 @@ function Header({rkey, list}: {rkey: string; list: AppBskyGraphDefs.ListView}) {
items.push({
testID: 'listHeaderDropdownUnpinBtn',
label: _(msg`Unpin moderation list`),
onPress: isPending ? undefined : () => unpinFeed({uri: list.uri}),
onPress:
isPending || !savedFeedConfig
? undefined
: () => removeSavedFeed(savedFeedConfig),
icon: {
ios: {
name: 'pin',
@@ -503,14 +509,14 @@ function Header({rkey, list}: {rkey: string; list: AppBskyGraphDefs.ListView}) {
deleteListPromptControl.open,
onPressReport,
isPending,
unpinFeed,
list.uri,
isBlocking,
isMuting,
onUnsubscribeMute,
subscribeMutePromptControl.open,
onUnsubscribeBlock,
subscribeBlockPromptControl.open,
removeSavedFeed,
savedFeedConfig,
])
const subscribeDropdownItems: DropdownItem[] = useMemo(() => {