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