Hide normal mute if muted by list, and invalidate profile query upon list mute (#2048)

* Hide normal mute if muted by list, and invalidate profile query upon list mute

* Prevent profile flashing
zio/stable
Eric Bailey 2023-11-30 15:40:01 -06:00 committed by GitHub
parent 46b63accb8
commit 47b0d36b73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 19 deletions

View File

@ -7,6 +7,7 @@ import {
} from 'react-native' } from 'react-native'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
import {useNavigation} from '@react-navigation/native' import {useNavigation} from '@react-navigation/native'
import {useQueryClient} from '@tanstack/react-query'
import { import {
AppBskyActorDefs, AppBskyActorDefs,
ProfileModeration, ProfileModeration,
@ -32,6 +33,7 @@ import {ProfileHeaderSuggestedFollows} from './ProfileHeaderSuggestedFollows'
import {useModalControls} from '#/state/modals' import {useModalControls} from '#/state/modals'
import {useLightboxControls, ProfileImageLightbox} from '#/state/lightbox' import {useLightboxControls, ProfileImageLightbox} from '#/state/lightbox'
import { import {
RQKEY as profileQueryKey,
useProfileMuteMutationQueue, useProfileMuteMutationQueue,
useProfileBlockMutationQueue, useProfileBlockMutationQueue,
useProfileFollowMutationQueue, useProfileFollowMutationQueue,
@ -134,6 +136,13 @@ let ProfileHeaderLoaded = ({
const [queueFollow, queueUnfollow] = useProfileFollowMutationQueue(profile) const [queueFollow, queueUnfollow] = useProfileFollowMutationQueue(profile)
const [queueMute, queueUnmute] = useProfileMuteMutationQueue(profile) const [queueMute, queueUnmute] = useProfileMuteMutationQueue(profile)
const [queueBlock, queueUnblock] = useProfileBlockMutationQueue(profile) const [queueBlock, queueUnblock] = useProfileBlockMutationQueue(profile)
const queryClient = useQueryClient()
const invalidateProfileQuery = React.useCallback(() => {
queryClient.invalidateQueries({
queryKey: profileQueryKey(profile.did),
})
}, [queryClient, profile.did])
const onPressBack = React.useCallback(() => { const onPressBack = React.useCallback(() => {
if (navigation.canGoBack()) { if (navigation.canGoBack()) {
@ -209,8 +218,10 @@ let ProfileHeaderLoaded = ({
name: 'user-add-remove-lists', name: 'user-add-remove-lists',
subject: profile.did, subject: profile.did,
displayName: profile.displayName || profile.handle, displayName: profile.displayName || profile.handle,
onAdd: invalidateProfileQuery,
onRemove: invalidateProfileQuery,
}) })
}, [track, profile, openModal]) }, [track, profile, openModal, invalidateProfileQuery])
const onPressMuteAccount = React.useCallback(async () => { const onPressMuteAccount = React.useCallback(async () => {
track('ProfileHeader:MuteAccountButtonClicked') track('ProfileHeader:MuteAccountButtonClicked')
@ -325,6 +336,7 @@ let ProfileHeaderLoaded = ({
}) })
if (!isMe) { if (!isMe) {
if (!profile.viewer?.blocking) { if (!profile.viewer?.blocking) {
if (!profile.viewer?.mutedByList) {
items.push({ items.push({
testID: 'profileHeaderDropdownMuteBtn', testID: 'profileHeaderDropdownMuteBtn',
label: profile.viewer?.muted label: profile.viewer?.muted
@ -342,6 +354,7 @@ let ProfileHeaderLoaded = ({
}, },
}) })
} }
}
if (!profile.viewer?.blockingByList) { if (!profile.viewer?.blockingByList) {
items.push({ items.push({
testID: 'profileHeaderDropdownBlockBtn', testID: 'profileHeaderDropdownBlockBtn',
@ -379,6 +392,7 @@ let ProfileHeaderLoaded = ({
isMe, isMe,
hasSession, hasSession,
profile.viewer?.muted, profile.viewer?.muted,
profile.viewer?.mutedByList,
profile.viewer?.blocking, profile.viewer?.blocking,
profile.viewer?.blockingByList, profile.viewer?.blockingByList,
onPressShare, onPressShare,

View File

@ -50,13 +50,13 @@ export function ProfileScreen({route}: Props) {
data: resolvedDid, data: resolvedDid,
error: resolveError, error: resolveError,
refetch: refetchDid, refetch: refetchDid,
isFetching: isFetchingDid, isInitialLoading: isInitialLoadingDid,
} = useResolveDidQuery(name) } = useResolveDidQuery(name)
const { const {
data: profile, data: profile,
error: profileError, error: profileError,
refetch: refetchProfile, refetch: refetchProfile,
isFetching: isFetchingProfile, isInitialLoading: isInitialLoadingProfile,
} = useProfileQuery({ } = useProfileQuery({
did: resolvedDid, did: resolvedDid,
}) })
@ -69,7 +69,7 @@ export function ProfileScreen({route}: Props) {
} }
}, [resolveError, refetchDid, refetchProfile]) }, [resolveError, refetchDid, refetchProfile])
if (isFetchingDid || isFetchingProfile || !moderationOpts) { if (isInitialLoadingDid || isInitialLoadingProfile || !moderationOpts) {
return ( return (
<CenteredView> <CenteredView>
<ProfileHeader <ProfileHeader