Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Muted and Blocked accounts screens (react-query refactor) #1892

Merged
merged 3 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 0 additions & 107 deletions src/state/models/lists/blocked-accounts.ts

This file was deleted.

107 changes: 0 additions & 107 deletions src/state/models/lists/muted-accounts.ts

This file was deleted.

28 changes: 28 additions & 0 deletions src/state/queries/my-blocked-accounts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {AppBskyGraphGetBlocks} from '@atproto/api'
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
import {useSession} from '../session'

export const RQKEY = () => ['my-blocked-accounts']
type RQPageParam = string | undefined

export function useMyBlockedAccountsQuery() {
const {agent} = useSession()
return useInfiniteQuery<
AppBskyGraphGetBlocks.OutputSchema,
Error,
InfiniteData<AppBskyGraphGetBlocks.OutputSchema>,
QueryKey,
RQPageParam
>({
queryKey: RQKEY(),
async queryFn({pageParam}: {pageParam: RQPageParam}) {
const res = await agent.app.bsky.graph.getBlocks({
limit: 30,
cursor: pageParam,
})
return res.data
},
initialPageParam: undefined,
getNextPageParam: lastPage => lastPage.cursor,
})
}
28 changes: 28 additions & 0 deletions src/state/queries/my-muted-accounts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {AppBskyGraphGetMutes} from '@atproto/api'
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
import {useSession} from '../session'

export const RQKEY = () => ['my-muted-accounts']
type RQPageParam = string | undefined

export function useMyMutedAccountsQuery() {
const {agent} = useSession()
return useInfiniteQuery<
AppBskyGraphGetMutes.OutputSchema,
Error,
InfiniteData<AppBskyGraphGetMutes.OutputSchema>,
QueryKey,
RQPageParam
>({
queryKey: RQKEY(),
async queryFn({pageParam}: {pageParam: RQPageParam}) {
const res = await agent.app.bsky.graph.getMutes({
limit: 30,
cursor: pageParam,
})
return res.data
},
initialPageParam: undefined,
getNextPageParam: lastPage => lastPage.cursor,
})
}
8 changes: 8 additions & 0 deletions src/state/queries/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {useSession} from '../session'
import {updateProfileShadow} from '../cache/profile-shadow'
import {uploadBlob} from '#/lib/api'
import {until} from '#/lib/async/until'
import {RQKEY as RQKEY_MY_MUTED} from './my-muted-accounts'
import {RQKEY as RQKEY_MY_BLOCKED} from './my-blocked-accounts'

export const RQKEY = (did: string) => ['profile', did]

Expand Down Expand Up @@ -147,6 +149,7 @@ export function useProfileUnfollowMutation() {

export function useProfileMuteMutation() {
const {agent} = useSession()
const queryClient = useQueryClient()
return useMutation<void, Error, {did: string}>({
mutationFn: async ({did}) => {
await agent.mute(did)
Expand All @@ -157,6 +160,9 @@ export function useProfileMuteMutation() {
muted: true,
})
},
onSuccess() {
queryClient.invalidateQueries({queryKey: RQKEY_MY_MUTED()})
},
onError(error, variables) {
// revert the optimistic update
updateProfileShadow(variables.did, {
Expand Down Expand Up @@ -189,6 +195,7 @@ export function useProfileUnmuteMutation() {

export function useProfileBlockMutation() {
const {agent, currentAccount} = useSession()
const queryClient = useQueryClient()
return useMutation<{uri: string; cid: string}, Error, {did: string}>({
mutationFn: async ({did}) => {
if (!currentAccount) {
Expand All @@ -210,6 +217,7 @@ export function useProfileBlockMutation() {
updateProfileShadow(variables.did, {
blockingUri: data.uri,
})
queryClient.invalidateQueries({queryKey: RQKEY_MY_BLOCKED()})
},
onError(error, variables) {
// revert the optimistic update
Expand Down
3 changes: 3 additions & 0 deletions src/view/com/lists/ListMembers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export function ListMembers({

const {
data,
dataUpdatedAt,
isFetching,
isFetched,
isError,
Expand Down Expand Up @@ -184,6 +185,7 @@ export function ListMembers({
(item as AppBskyGraphDefs.ListItemView).subject.handle
}`}
profile={(item as AppBskyGraphDefs.ListItemView).subject}
dataUpdatedAt={dataUpdatedAt}
renderButton={renderMemberButton}
style={{paddingHorizontal: isMobile ? 8 : 14, paddingVertical: 4}}
/>
Expand All @@ -196,6 +198,7 @@ export function ListMembers({
onPressTryAgain,
onPressRetryLoadMore,
isMobile,
dataUpdatedAt,
],
)

Expand Down
19 changes: 13 additions & 6 deletions src/view/com/profile/ProfileCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ import {
getProfileModerationCauses,
getModerationCauseKey,
} from 'lib/moderation'
import {useModerationOpts} from '#/state/queries/preferences'
import {useProfileShadow} from '#/state/cache/profile-shadow'

export const ProfileCard = observer(function ProfileCardImpl({
export function ProfileCard({
testID,
profile,
profile: profileUnshadowed,
dataUpdatedAt,
noBg,
noBorder,
followers,
Expand All @@ -33,16 +36,20 @@ export const ProfileCard = observer(function ProfileCardImpl({
}: {
testID?: string
profile: AppBskyActorDefs.ProfileViewBasic
dataUpdatedAt: number
noBg?: boolean
noBorder?: boolean
followers?: AppBskyActorDefs.ProfileView[] | undefined
renderButton?: (profile: AppBskyActorDefs.ProfileViewBasic) => React.ReactNode
style?: StyleProp<ViewStyle>
}) {
const store = useStores()
const pal = usePalette('default')

const moderation = moderateProfile(profile, store.preferences.moderationOpts)
const profile = useProfileShadow(profileUnshadowed, dataUpdatedAt)
const moderationOpts = useModerationOpts()
if (!moderationOpts) {
return null
}
const moderation = moderateProfile(profile, moderationOpts)

return (
<Link
Expand Down Expand Up @@ -100,7 +107,7 @@ export const ProfileCard = observer(function ProfileCardImpl({
<FollowersList followers={followers} />
</Link>
)
})
}

function ProfileCardPills({
followedBy,
Expand Down
Loading
Loading