Move the current agent to a global and reset RQ queries on agent change (#1946)
parent
3043b32468
commit
357c752a21
|
@ -3,14 +3,13 @@ import {AppBskyActorDefs} from '@atproto/api'
|
||||||
import {useQuery, useQueryClient} from '@tanstack/react-query'
|
import {useQuery, useQueryClient} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
import {useSession} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
import {useMyFollowsQuery} from '#/state/queries/my-follows'
|
import {useMyFollowsQuery} from '#/state/queries/my-follows'
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
|
||||||
export const RQKEY = (prefix: string) => ['actor-autocomplete', prefix]
|
export const RQKEY = (prefix: string) => ['actor-autocomplete', prefix]
|
||||||
|
|
||||||
export function useActorAutocompleteQuery(prefix: string) {
|
export function useActorAutocompleteQuery(prefix: string) {
|
||||||
const {agent} = useSession()
|
|
||||||
const {data: follows, isFetching} = useMyFollowsQuery()
|
const {data: follows, isFetching} = useMyFollowsQuery()
|
||||||
|
|
||||||
return useQuery<AppBskyActorDefs.ProfileViewBasic[]>({
|
return useQuery<AppBskyActorDefs.ProfileViewBasic[]>({
|
||||||
|
@ -18,7 +17,7 @@ export function useActorAutocompleteQuery(prefix: string) {
|
||||||
queryKey: RQKEY(prefix || ''),
|
queryKey: RQKEY(prefix || ''),
|
||||||
async queryFn() {
|
async queryFn() {
|
||||||
const res = prefix
|
const res = prefix
|
||||||
? await agent.searchActorsTypeahead({
|
? await getAgent().searchActorsTypeahead({
|
||||||
term: prefix,
|
term: prefix,
|
||||||
limit: 8,
|
limit: 8,
|
||||||
})
|
})
|
||||||
|
@ -32,7 +31,6 @@ export function useActorAutocompleteQuery(prefix: string) {
|
||||||
export type ActorAutocompleteFn = ReturnType<typeof useActorAutocompleteFn>
|
export type ActorAutocompleteFn = ReturnType<typeof useActorAutocompleteFn>
|
||||||
export function useActorAutocompleteFn() {
|
export function useActorAutocompleteFn() {
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const {agent} = useSession()
|
|
||||||
const {data: follows} = useMyFollowsQuery()
|
const {data: follows} = useMyFollowsQuery()
|
||||||
|
|
||||||
return React.useCallback(
|
return React.useCallback(
|
||||||
|
@ -44,7 +42,7 @@ export function useActorAutocompleteFn() {
|
||||||
staleTime: STALE.MINUTES.ONE,
|
staleTime: STALE.MINUTES.ONE,
|
||||||
queryKey: RQKEY(query || ''),
|
queryKey: RQKEY(query || ''),
|
||||||
queryFn: () =>
|
queryFn: () =>
|
||||||
agent.searchActorsTypeahead({
|
getAgent().searchActorsTypeahead({
|
||||||
term: query,
|
term: query,
|
||||||
limit,
|
limit,
|
||||||
}),
|
}),
|
||||||
|
@ -58,7 +56,7 @@ export function useActorAutocompleteFn() {
|
||||||
|
|
||||||
return computeSuggestions(query, follows, res?.data.actors)
|
return computeSuggestions(query, follows, res?.data.actors)
|
||||||
},
|
},
|
||||||
[agent, follows, queryClient],
|
[follows, queryClient],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,25 +1,23 @@
|
||||||
import {ComAtprotoServerCreateAppPassword} from '@atproto/api'
|
import {ComAtprotoServerCreateAppPassword} from '@atproto/api'
|
||||||
import {useQuery, useQueryClient, useMutation} from '@tanstack/react-query'
|
import {useQuery, useQueryClient, useMutation} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {useSession} from '#/state/session'
|
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
import {getAgent} from '../session'
|
||||||
|
|
||||||
export const RQKEY = () => ['app-passwords']
|
export const RQKEY = () => ['app-passwords']
|
||||||
|
|
||||||
export function useAppPasswordsQuery() {
|
export function useAppPasswordsQuery() {
|
||||||
const {agent} = useSession()
|
|
||||||
return useQuery({
|
return useQuery({
|
||||||
staleTime: STALE.MINUTES.ONE,
|
staleTime: STALE.MINUTES.ONE,
|
||||||
queryKey: RQKEY(),
|
queryKey: RQKEY(),
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const res = await agent.com.atproto.server.listAppPasswords({})
|
const res = await getAgent().com.atproto.server.listAppPasswords({})
|
||||||
return res.data.passwords
|
return res.data.passwords
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useAppPasswordCreateMutation() {
|
export function useAppPasswordCreateMutation() {
|
||||||
const {agent} = useSession()
|
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
return useMutation<
|
return useMutation<
|
||||||
ComAtprotoServerCreateAppPassword.OutputSchema,
|
ComAtprotoServerCreateAppPassword.OutputSchema,
|
||||||
|
@ -28,7 +26,7 @@ export function useAppPasswordCreateMutation() {
|
||||||
>({
|
>({
|
||||||
mutationFn: async ({name}) => {
|
mutationFn: async ({name}) => {
|
||||||
return (
|
return (
|
||||||
await agent.com.atproto.server.createAppPassword({
|
await getAgent().com.atproto.server.createAppPassword({
|
||||||
name,
|
name,
|
||||||
})
|
})
|
||||||
).data
|
).data
|
||||||
|
@ -42,11 +40,10 @@ export function useAppPasswordCreateMutation() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useAppPasswordDeleteMutation() {
|
export function useAppPasswordDeleteMutation() {
|
||||||
const {agent} = useSession()
|
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
return useMutation<void, Error, {name: string}>({
|
return useMutation<void, Error, {name: string}>({
|
||||||
mutationFn: async ({name}) => {
|
mutationFn: async ({name}) => {
|
||||||
await agent.com.atproto.server.revokeAppPassword({
|
await getAgent().com.atproto.server.revokeAppPassword({
|
||||||
name,
|
name,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
|
@ -18,7 +18,7 @@ import {
|
||||||
import {router} from '#/routes'
|
import {router} from '#/routes'
|
||||||
import {sanitizeDisplayName} from '#/lib/strings/display-names'
|
import {sanitizeDisplayName} from '#/lib/strings/display-names'
|
||||||
import {sanitizeHandle} from '#/lib/strings/handles'
|
import {sanitizeHandle} from '#/lib/strings/handles'
|
||||||
import {useSession} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
import {usePreferencesQuery} from '#/state/queries/preferences'
|
import {usePreferencesQuery} from '#/state/queries/preferences'
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
|
||||||
|
@ -136,7 +136,6 @@ export function getFeedTypeFromUri(uri: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useFeedSourceInfoQuery({uri}: {uri: string}) {
|
export function useFeedSourceInfoQuery({uri}: {uri: string}) {
|
||||||
const {agent} = useSession()
|
|
||||||
const type = getFeedTypeFromUri(uri)
|
const type = getFeedTypeFromUri(uri)
|
||||||
|
|
||||||
return useQuery({
|
return useQuery({
|
||||||
|
@ -146,10 +145,10 @@ export function useFeedSourceInfoQuery({uri}: {uri: string}) {
|
||||||
let view: FeedSourceInfo
|
let view: FeedSourceInfo
|
||||||
|
|
||||||
if (type === 'feed') {
|
if (type === 'feed') {
|
||||||
const res = await agent.app.bsky.feed.getFeedGenerator({feed: uri})
|
const res = await getAgent().app.bsky.feed.getFeedGenerator({feed: uri})
|
||||||
view = hydrateFeedGenerator(res.data.view)
|
view = hydrateFeedGenerator(res.data.view)
|
||||||
} else {
|
} else {
|
||||||
const res = await agent.app.bsky.graph.getList({
|
const res = await getAgent().app.bsky.graph.getList({
|
||||||
list: uri,
|
list: uri,
|
||||||
limit: 1,
|
limit: 1,
|
||||||
})
|
})
|
||||||
|
@ -164,8 +163,6 @@ export function useFeedSourceInfoQuery({uri}: {uri: string}) {
|
||||||
export const useGetPopularFeedsQueryKey = ['getPopularFeeds']
|
export const useGetPopularFeedsQueryKey = ['getPopularFeeds']
|
||||||
|
|
||||||
export function useGetPopularFeedsQuery() {
|
export function useGetPopularFeedsQuery() {
|
||||||
const {agent} = useSession()
|
|
||||||
|
|
||||||
return useInfiniteQuery<
|
return useInfiniteQuery<
|
||||||
AppBskyUnspeccedGetPopularFeedGenerators.OutputSchema,
|
AppBskyUnspeccedGetPopularFeedGenerators.OutputSchema,
|
||||||
Error,
|
Error,
|
||||||
|
@ -175,7 +172,7 @@ export function useGetPopularFeedsQuery() {
|
||||||
>({
|
>({
|
||||||
queryKey: useGetPopularFeedsQueryKey,
|
queryKey: useGetPopularFeedsQueryKey,
|
||||||
queryFn: async ({pageParam}) => {
|
queryFn: async ({pageParam}) => {
|
||||||
const res = await agent.app.bsky.unspecced.getPopularFeedGenerators({
|
const res = await getAgent().app.bsky.unspecced.getPopularFeedGenerators({
|
||||||
limit: 10,
|
limit: 10,
|
||||||
cursor: pageParam,
|
cursor: pageParam,
|
||||||
})
|
})
|
||||||
|
@ -187,11 +184,9 @@ export function useGetPopularFeedsQuery() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useSearchPopularFeedsMutation() {
|
export function useSearchPopularFeedsMutation() {
|
||||||
const {agent} = useSession()
|
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: async (query: string) => {
|
mutationFn: async (query: string) => {
|
||||||
const res = await agent.app.bsky.unspecced.getPopularFeedGenerators({
|
const res = await getAgent().app.bsky.unspecced.getPopularFeedGenerators({
|
||||||
limit: 10,
|
limit: 10,
|
||||||
query: query,
|
query: query,
|
||||||
})
|
})
|
||||||
|
@ -220,7 +215,6 @@ const FOLLOWING_FEED_STUB: FeedSourceInfo = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function usePinnedFeedsInfos(): FeedSourceInfo[] {
|
export function usePinnedFeedsInfos(): FeedSourceInfo[] {
|
||||||
const {agent} = useSession()
|
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const [tabs, setTabs] = React.useState<FeedSourceInfo[]>([
|
const [tabs, setTabs] = React.useState<FeedSourceInfo[]>([
|
||||||
FOLLOWING_FEED_STUB,
|
FOLLOWING_FEED_STUB,
|
||||||
|
@ -250,12 +244,12 @@ export function usePinnedFeedsInfos(): FeedSourceInfo[] {
|
||||||
const type = getFeedTypeFromUri(uri)
|
const type = getFeedTypeFromUri(uri)
|
||||||
|
|
||||||
if (type === 'feed') {
|
if (type === 'feed') {
|
||||||
const res = await agent.app.bsky.feed.getFeedGenerator({
|
const res = await getAgent().app.bsky.feed.getFeedGenerator({
|
||||||
feed: uri,
|
feed: uri,
|
||||||
})
|
})
|
||||||
return hydrateFeedGenerator(res.data.view)
|
return hydrateFeedGenerator(res.data.view)
|
||||||
} else {
|
} else {
|
||||||
const res = await agent.app.bsky.graph.getList({
|
const res = await getAgent().app.bsky.graph.getList({
|
||||||
list: uri,
|
list: uri,
|
||||||
limit: 1,
|
limit: 1,
|
||||||
})
|
})
|
||||||
|
@ -274,7 +268,6 @@ export function usePinnedFeedsInfos(): FeedSourceInfo[] {
|
||||||
|
|
||||||
fetchFeedInfo()
|
fetchFeedInfo()
|
||||||
}, [
|
}, [
|
||||||
agent,
|
|
||||||
queryClient,
|
queryClient,
|
||||||
setTabs,
|
setTabs,
|
||||||
preferences?.feeds?.pinned,
|
preferences?.feeds?.pinned,
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {useQueryClient, useMutation} from '@tanstack/react-query'
|
import {useQueryClient, useMutation} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {useSession} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
|
||||||
const fetchHandleQueryKey = (handleOrDid: string) => ['handle', handleOrDid]
|
const fetchHandleQueryKey = (handleOrDid: string) => ['handle', handleOrDid]
|
||||||
const fetchDidQueryKey = (handleOrDid: string) => ['did', handleOrDid]
|
const fetchDidQueryKey = (handleOrDid: string) => ['did', handleOrDid]
|
||||||
|
|
||||||
export function useFetchHandle() {
|
export function useFetchHandle() {
|
||||||
const {agent} = useSession()
|
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
return React.useCallback(
|
return React.useCallback(
|
||||||
|
@ -17,23 +16,22 @@ export function useFetchHandle() {
|
||||||
const res = await queryClient.fetchQuery({
|
const res = await queryClient.fetchQuery({
|
||||||
staleTime: STALE.MINUTES.FIVE,
|
staleTime: STALE.MINUTES.FIVE,
|
||||||
queryKey: fetchHandleQueryKey(handleOrDid),
|
queryKey: fetchHandleQueryKey(handleOrDid),
|
||||||
queryFn: () => agent.getProfile({actor: handleOrDid}),
|
queryFn: () => getAgent().getProfile({actor: handleOrDid}),
|
||||||
})
|
})
|
||||||
return res.data.handle
|
return res.data.handle
|
||||||
}
|
}
|
||||||
return handleOrDid
|
return handleOrDid
|
||||||
},
|
},
|
||||||
[agent, queryClient],
|
[queryClient],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useUpdateHandleMutation() {
|
export function useUpdateHandleMutation() {
|
||||||
const {agent} = useSession()
|
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: async ({handle}: {handle: string}) => {
|
mutationFn: async ({handle}: {handle: string}) => {
|
||||||
await agent.updateHandle({handle})
|
await getAgent().updateHandle({handle})
|
||||||
},
|
},
|
||||||
onSuccess(_data, variables) {
|
onSuccess(_data, variables) {
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
|
@ -44,7 +42,6 @@ export function useUpdateHandleMutation() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useFetchDid() {
|
export function useFetchDid() {
|
||||||
const {agent} = useSession()
|
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
return React.useCallback(
|
return React.useCallback(
|
||||||
|
@ -55,13 +52,13 @@ export function useFetchDid() {
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
let identifier = handleOrDid
|
let identifier = handleOrDid
|
||||||
if (!identifier.startsWith('did:')) {
|
if (!identifier.startsWith('did:')) {
|
||||||
const res = await agent.resolveHandle({handle: identifier})
|
const res = await getAgent().resolveHandle({handle: identifier})
|
||||||
identifier = res.data.did
|
identifier = res.data.did
|
||||||
}
|
}
|
||||||
return identifier
|
return identifier
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
[agent, queryClient],
|
[queryClient],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import {ComAtprotoServerDefs} from '@atproto/api'
|
import {ComAtprotoServerDefs} from '@atproto/api'
|
||||||
import {useQuery} from '@tanstack/react-query'
|
import {useQuery} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {useSession} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
|
||||||
function isInviteAvailable(invite: ComAtprotoServerDefs.InviteCode): boolean {
|
function isInviteAvailable(invite: ComAtprotoServerDefs.InviteCode): boolean {
|
||||||
|
@ -13,13 +13,11 @@ export type InviteCodesQueryResponse = Exclude<
|
||||||
undefined
|
undefined
|
||||||
>
|
>
|
||||||
export function useInviteCodesQuery() {
|
export function useInviteCodesQuery() {
|
||||||
const {agent} = useSession()
|
|
||||||
|
|
||||||
return useQuery({
|
return useQuery({
|
||||||
staleTime: STALE.HOURS.ONE,
|
staleTime: STALE.HOURS.ONE,
|
||||||
queryKey: ['inviteCodes'],
|
queryKey: ['inviteCodes'],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const res = await agent.com.atproto.server.getAccountInviteCodes({})
|
const res = await getAgent().com.atproto.server.getAccountInviteCodes({})
|
||||||
|
|
||||||
if (!res.data?.codes) {
|
if (!res.data?.codes) {
|
||||||
throw new Error(`useInviteCodesQuery: no codes returned`)
|
throw new Error(`useInviteCodesQuery: no codes returned`)
|
||||||
|
|
|
@ -1,24 +1,20 @@
|
||||||
import {useMutation} from '@tanstack/react-query'
|
import {useMutation} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {useSession} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
|
|
||||||
export function useLikeMutation() {
|
export function useLikeMutation() {
|
||||||
const {agent} = useSession()
|
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: async ({uri, cid}: {uri: string; cid: string}) => {
|
mutationFn: async ({uri, cid}: {uri: string; cid: string}) => {
|
||||||
const res = await agent.like(uri, cid)
|
const res = await getAgent().like(uri, cid)
|
||||||
return {uri: res.uri}
|
return {uri: res.uri}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useUnlikeMutation() {
|
export function useUnlikeMutation() {
|
||||||
const {agent} = useSession()
|
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: async ({uri}: {uri: string}) => {
|
mutationFn: async ({uri}: {uri: string}) => {
|
||||||
await agent.deleteLike(uri)
|
await getAgent().deleteLike(uri)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import {AppBskyGraphGetList} from '@atproto/api'
|
import {AppBskyGraphGetList} from '@atproto/api'
|
||||||
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {useSession} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
|
||||||
const PAGE_SIZE = 30
|
const PAGE_SIZE = 30
|
||||||
|
@ -10,7 +10,6 @@ type RQPageParam = string | undefined
|
||||||
export const RQKEY = (uri: string) => ['list-members', uri]
|
export const RQKEY = (uri: string) => ['list-members', uri]
|
||||||
|
|
||||||
export function useListMembersQuery(uri: string) {
|
export function useListMembersQuery(uri: string) {
|
||||||
const {agent} = useSession()
|
|
||||||
return useInfiniteQuery<
|
return useInfiniteQuery<
|
||||||
AppBskyGraphGetList.OutputSchema,
|
AppBskyGraphGetList.OutputSchema,
|
||||||
Error,
|
Error,
|
||||||
|
@ -21,7 +20,7 @@ export function useListMembersQuery(uri: string) {
|
||||||
staleTime: STALE.MINUTES.ONE,
|
staleTime: STALE.MINUTES.ONE,
|
||||||
queryKey: RQKEY(uri),
|
queryKey: RQKEY(uri),
|
||||||
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
||||||
const res = await agent.app.bsky.graph.getList({
|
const res = await getAgent().app.bsky.graph.getList({
|
||||||
list: uri,
|
list: uri,
|
||||||
limit: PAGE_SIZE,
|
limit: PAGE_SIZE,
|
||||||
cursor: pageParam,
|
cursor: pageParam,
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
import {AtUri} from '@atproto/api'
|
import {AtUri} from '@atproto/api'
|
||||||
import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'
|
import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {useSession} from '#/state/session'
|
import {useSession, getAgent} from '#/state/session'
|
||||||
import {RQKEY as LIST_MEMBERS_RQKEY} from '#/state/queries/list-members'
|
import {RQKEY as LIST_MEMBERS_RQKEY} from '#/state/queries/list-members'
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ export interface ListMembersip {
|
||||||
* This API is dangerous! Read the note above!
|
* This API is dangerous! Read the note above!
|
||||||
*/
|
*/
|
||||||
export function useDangerousListMembershipsQuery() {
|
export function useDangerousListMembershipsQuery() {
|
||||||
const {agent, currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
return useQuery<ListMembersip[]>({
|
return useQuery<ListMembersip[]>({
|
||||||
staleTime: STALE.MINUTES.FIVE,
|
staleTime: STALE.MINUTES.FIVE,
|
||||||
queryKey: RQKEY(),
|
queryKey: RQKEY(),
|
||||||
|
@ -49,7 +49,7 @@ export function useDangerousListMembershipsQuery() {
|
||||||
let cursor
|
let cursor
|
||||||
let arr: ListMembersip[] = []
|
let arr: ListMembersip[] = []
|
||||||
for (let i = 0; i < SANITY_PAGE_LIMIT; i++) {
|
for (let i = 0; i < SANITY_PAGE_LIMIT; i++) {
|
||||||
const res = await agent.app.bsky.graph.listitem.list({
|
const res = await getAgent().app.bsky.graph.listitem.list({
|
||||||
repo: currentAccount.did,
|
repo: currentAccount.did,
|
||||||
limit: PAGE_SIZE,
|
limit: PAGE_SIZE,
|
||||||
cursor,
|
cursor,
|
||||||
|
@ -89,7 +89,7 @@ export function getMembership(
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useListMembershipAddMutation() {
|
export function useListMembershipAddMutation() {
|
||||||
const {agent, currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
return useMutation<
|
return useMutation<
|
||||||
{uri: string; cid: string},
|
{uri: string; cid: string},
|
||||||
|
@ -100,7 +100,7 @@ export function useListMembershipAddMutation() {
|
||||||
if (!currentAccount) {
|
if (!currentAccount) {
|
||||||
throw new Error('Not logged in')
|
throw new Error('Not logged in')
|
||||||
}
|
}
|
||||||
const res = await agent.app.bsky.graph.listitem.create(
|
const res = await getAgent().app.bsky.graph.listitem.create(
|
||||||
{repo: currentAccount.did},
|
{repo: currentAccount.did},
|
||||||
{
|
{
|
||||||
subject: actorDid,
|
subject: actorDid,
|
||||||
|
@ -147,7 +147,7 @@ export function useListMembershipAddMutation() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useListMembershipRemoveMutation() {
|
export function useListMembershipRemoveMutation() {
|
||||||
const {agent, currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
return useMutation<
|
return useMutation<
|
||||||
void,
|
void,
|
||||||
|
@ -159,7 +159,7 @@ export function useListMembershipRemoveMutation() {
|
||||||
throw new Error('Not logged in')
|
throw new Error('Not logged in')
|
||||||
}
|
}
|
||||||
const membershipUrip = new AtUri(membershipUri)
|
const membershipUrip = new AtUri(membershipUri)
|
||||||
await agent.app.bsky.graph.listitem.delete({
|
await getAgent().app.bsky.graph.listitem.delete({
|
||||||
repo: currentAccount.did,
|
repo: currentAccount.did,
|
||||||
rkey: membershipUrip.rkey,
|
rkey: membershipUrip.rkey,
|
||||||
})
|
})
|
||||||
|
|
|
@ -8,7 +8,7 @@ import {
|
||||||
import {Image as RNImage} from 'react-native-image-crop-picker'
|
import {Image as RNImage} from 'react-native-image-crop-picker'
|
||||||
import {useQuery, useMutation, useQueryClient} from '@tanstack/react-query'
|
import {useQuery, useMutation, useQueryClient} from '@tanstack/react-query'
|
||||||
import chunk from 'lodash.chunk'
|
import chunk from 'lodash.chunk'
|
||||||
import {useSession} from '../session'
|
import {useSession, getAgent} from '../session'
|
||||||
import {invalidate as invalidateMyLists} from './my-lists'
|
import {invalidate as invalidateMyLists} from './my-lists'
|
||||||
import {RQKEY as PROFILE_LISTS_RQKEY} from './profile-lists'
|
import {RQKEY as PROFILE_LISTS_RQKEY} from './profile-lists'
|
||||||
import {uploadBlob} from '#/lib/api'
|
import {uploadBlob} from '#/lib/api'
|
||||||
|
@ -18,7 +18,6 @@ import {STALE} from '#/state/queries'
|
||||||
export const RQKEY = (uri: string) => ['list', uri]
|
export const RQKEY = (uri: string) => ['list', uri]
|
||||||
|
|
||||||
export function useListQuery(uri?: string) {
|
export function useListQuery(uri?: string) {
|
||||||
const {agent} = useSession()
|
|
||||||
return useQuery<AppBskyGraphDefs.ListView, Error>({
|
return useQuery<AppBskyGraphDefs.ListView, Error>({
|
||||||
staleTime: STALE.MINUTES.ONE,
|
staleTime: STALE.MINUTES.ONE,
|
||||||
queryKey: RQKEY(uri || ''),
|
queryKey: RQKEY(uri || ''),
|
||||||
|
@ -26,7 +25,7 @@ export function useListQuery(uri?: string) {
|
||||||
if (!uri) {
|
if (!uri) {
|
||||||
throw new Error('URI not provided')
|
throw new Error('URI not provided')
|
||||||
}
|
}
|
||||||
const res = await agent.app.bsky.graph.getList({
|
const res = await getAgent().app.bsky.graph.getList({
|
||||||
list: uri,
|
list: uri,
|
||||||
limit: 1,
|
limit: 1,
|
||||||
})
|
})
|
||||||
|
@ -43,7 +42,7 @@ export interface ListCreateMutateParams {
|
||||||
avatar: RNImage | null | undefined
|
avatar: RNImage | null | undefined
|
||||||
}
|
}
|
||||||
export function useListCreateMutation() {
|
export function useListCreateMutation() {
|
||||||
const {agent, currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
return useMutation<{uri: string; cid: string}, Error, ListCreateMutateParams>(
|
return useMutation<{uri: string; cid: string}, Error, ListCreateMutateParams>(
|
||||||
{
|
{
|
||||||
|
@ -65,10 +64,10 @@ export function useListCreateMutation() {
|
||||||
createdAt: new Date().toISOString(),
|
createdAt: new Date().toISOString(),
|
||||||
}
|
}
|
||||||
if (avatar) {
|
if (avatar) {
|
||||||
const blobRes = await uploadBlob(agent, avatar.path, avatar.mime)
|
const blobRes = await uploadBlob(getAgent(), avatar.path, avatar.mime)
|
||||||
record.avatar = blobRes.data.blob
|
record.avatar = blobRes.data.blob
|
||||||
}
|
}
|
||||||
const res = await agent.app.bsky.graph.list.create(
|
const res = await getAgent().app.bsky.graph.list.create(
|
||||||
{
|
{
|
||||||
repo: currentAccount.did,
|
repo: currentAccount.did,
|
||||||
},
|
},
|
||||||
|
@ -77,7 +76,7 @@ export function useListCreateMutation() {
|
||||||
|
|
||||||
// wait for the appview to update
|
// wait for the appview to update
|
||||||
await whenAppViewReady(
|
await whenAppViewReady(
|
||||||
agent,
|
getAgent(),
|
||||||
res.uri,
|
res.uri,
|
||||||
(v: AppBskyGraphGetList.Response) => {
|
(v: AppBskyGraphGetList.Response) => {
|
||||||
return typeof v?.data?.list.uri === 'string'
|
return typeof v?.data?.list.uri === 'string'
|
||||||
|
@ -102,7 +101,7 @@ export interface ListMetadataMutateParams {
|
||||||
avatar: RNImage | null | undefined
|
avatar: RNImage | null | undefined
|
||||||
}
|
}
|
||||||
export function useListMetadataMutation() {
|
export function useListMetadataMutation() {
|
||||||
const {agent, currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
return useMutation<
|
return useMutation<
|
||||||
{uri: string; cid: string},
|
{uri: string; cid: string},
|
||||||
|
@ -119,7 +118,7 @@ export function useListMetadataMutation() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the current record
|
// get the current record
|
||||||
const {value: record} = await agent.app.bsky.graph.list.get({
|
const {value: record} = await getAgent().app.bsky.graph.list.get({
|
||||||
repo: currentAccount.did,
|
repo: currentAccount.did,
|
||||||
rkey,
|
rkey,
|
||||||
})
|
})
|
||||||
|
@ -128,13 +127,13 @@ export function useListMetadataMutation() {
|
||||||
record.name = name
|
record.name = name
|
||||||
record.description = description
|
record.description = description
|
||||||
if (avatar) {
|
if (avatar) {
|
||||||
const blobRes = await uploadBlob(agent, avatar.path, avatar.mime)
|
const blobRes = await uploadBlob(getAgent(), avatar.path, avatar.mime)
|
||||||
record.avatar = blobRes.data.blob
|
record.avatar = blobRes.data.blob
|
||||||
} else if (avatar === null) {
|
} else if (avatar === null) {
|
||||||
record.avatar = undefined
|
record.avatar = undefined
|
||||||
}
|
}
|
||||||
const res = (
|
const res = (
|
||||||
await agent.com.atproto.repo.putRecord({
|
await getAgent().com.atproto.repo.putRecord({
|
||||||
repo: currentAccount.did,
|
repo: currentAccount.did,
|
||||||
collection: 'app.bsky.graph.list',
|
collection: 'app.bsky.graph.list',
|
||||||
rkey,
|
rkey,
|
||||||
|
@ -144,7 +143,7 @@ export function useListMetadataMutation() {
|
||||||
|
|
||||||
// wait for the appview to update
|
// wait for the appview to update
|
||||||
await whenAppViewReady(
|
await whenAppViewReady(
|
||||||
agent,
|
getAgent(),
|
||||||
res.uri,
|
res.uri,
|
||||||
(v: AppBskyGraphGetList.Response) => {
|
(v: AppBskyGraphGetList.Response) => {
|
||||||
const list = v.data.list
|
const list = v.data.list
|
||||||
|
@ -168,7 +167,7 @@ export function useListMetadataMutation() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useListDeleteMutation() {
|
export function useListDeleteMutation() {
|
||||||
const {agent, currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
return useMutation<void, Error, {uri: string}>({
|
return useMutation<void, Error, {uri: string}>({
|
||||||
mutationFn: async ({uri}) => {
|
mutationFn: async ({uri}) => {
|
||||||
|
@ -179,7 +178,7 @@ export function useListDeleteMutation() {
|
||||||
let cursor
|
let cursor
|
||||||
let listitemRecordUris: string[] = []
|
let listitemRecordUris: string[] = []
|
||||||
for (let i = 0; i < 100; i++) {
|
for (let i = 0; i < 100; i++) {
|
||||||
const res = await agent.app.bsky.graph.listitem.list({
|
const res = await getAgent().app.bsky.graph.listitem.list({
|
||||||
repo: currentAccount.did,
|
repo: currentAccount.did,
|
||||||
cursor,
|
cursor,
|
||||||
limit: 100,
|
limit: 100,
|
||||||
|
@ -210,16 +209,20 @@ export function useListDeleteMutation() {
|
||||||
|
|
||||||
// apply in chunks
|
// apply in chunks
|
||||||
for (const writesChunk of chunk(writes, 10)) {
|
for (const writesChunk of chunk(writes, 10)) {
|
||||||
await agent.com.atproto.repo.applyWrites({
|
await getAgent().com.atproto.repo.applyWrites({
|
||||||
repo: currentAccount.did,
|
repo: currentAccount.did,
|
||||||
writes: writesChunk,
|
writes: writesChunk,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait for the appview to update
|
// wait for the appview to update
|
||||||
await whenAppViewReady(agent, uri, (v: AppBskyGraphGetList.Response) => {
|
await whenAppViewReady(
|
||||||
return !v?.success
|
getAgent(),
|
||||||
})
|
uri,
|
||||||
|
(v: AppBskyGraphGetList.Response) => {
|
||||||
|
return !v?.success
|
||||||
|
},
|
||||||
|
)
|
||||||
},
|
},
|
||||||
onSuccess() {
|
onSuccess() {
|
||||||
invalidateMyLists(queryClient)
|
invalidateMyLists(queryClient)
|
||||||
|
@ -232,14 +235,13 @@ export function useListDeleteMutation() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useListMuteMutation() {
|
export function useListMuteMutation() {
|
||||||
const {agent} = useSession()
|
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
return useMutation<void, Error, {uri: string; mute: boolean}>({
|
return useMutation<void, Error, {uri: string; mute: boolean}>({
|
||||||
mutationFn: async ({uri, mute}) => {
|
mutationFn: async ({uri, mute}) => {
|
||||||
if (mute) {
|
if (mute) {
|
||||||
await agent.muteModList(uri)
|
await getAgent().muteModList(uri)
|
||||||
} else {
|
} else {
|
||||||
await agent.unmuteModList(uri)
|
await getAgent().unmuteModList(uri)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSuccess(data, variables) {
|
onSuccess(data, variables) {
|
||||||
|
@ -251,14 +253,13 @@ export function useListMuteMutation() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useListBlockMutation() {
|
export function useListBlockMutation() {
|
||||||
const {agent} = useSession()
|
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
return useMutation<void, Error, {uri: string; block: boolean}>({
|
return useMutation<void, Error, {uri: string; block: boolean}>({
|
||||||
mutationFn: async ({uri, block}) => {
|
mutationFn: async ({uri, block}) => {
|
||||||
if (block) {
|
if (block) {
|
||||||
await agent.blockModList(uri)
|
await getAgent().blockModList(uri)
|
||||||
} else {
|
} else {
|
||||||
await agent.unblockModList(uri)
|
await getAgent().unblockModList(uri)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSuccess(data, variables) {
|
onSuccess(data, variables) {
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
import {AppBskyGraphGetBlocks} from '@atproto/api'
|
import {AppBskyGraphGetBlocks} from '@atproto/api'
|
||||||
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {useSession} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
|
||||||
export const RQKEY = () => ['my-blocked-accounts']
|
export const RQKEY = () => ['my-blocked-accounts']
|
||||||
type RQPageParam = string | undefined
|
type RQPageParam = string | undefined
|
||||||
|
|
||||||
export function useMyBlockedAccountsQuery() {
|
export function useMyBlockedAccountsQuery() {
|
||||||
const {agent} = useSession()
|
|
||||||
return useInfiniteQuery<
|
return useInfiniteQuery<
|
||||||
AppBskyGraphGetBlocks.OutputSchema,
|
AppBskyGraphGetBlocks.OutputSchema,
|
||||||
Error,
|
Error,
|
||||||
|
@ -19,7 +18,7 @@ export function useMyBlockedAccountsQuery() {
|
||||||
staleTime: STALE.MINUTES.ONE,
|
staleTime: STALE.MINUTES.ONE,
|
||||||
queryKey: RQKEY(),
|
queryKey: RQKEY(),
|
||||||
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
||||||
const res = await agent.app.bsky.graph.getBlocks({
|
const res = await getAgent().app.bsky.graph.getBlocks({
|
||||||
limit: 30,
|
limit: 30,
|
||||||
cursor: pageParam,
|
cursor: pageParam,
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import {AppBskyActorDefs} from '@atproto/api'
|
import {AppBskyActorDefs} from '@atproto/api'
|
||||||
import {useQuery} from '@tanstack/react-query'
|
import {useQuery} from '@tanstack/react-query'
|
||||||
import {useSession} from '../session'
|
import {useSession, getAgent} from '../session'
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
|
||||||
// sanity limit is SANITY_PAGE_LIMIT*PAGE_SIZE total records
|
// sanity limit is SANITY_PAGE_LIMIT*PAGE_SIZE total records
|
||||||
|
@ -11,7 +11,7 @@ const PAGE_SIZE = 100
|
||||||
export const RQKEY = () => ['my-follows']
|
export const RQKEY = () => ['my-follows']
|
||||||
|
|
||||||
export function useMyFollowsQuery() {
|
export function useMyFollowsQuery() {
|
||||||
const {agent, currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
return useQuery<AppBskyActorDefs.ProfileViewBasic[]>({
|
return useQuery<AppBskyActorDefs.ProfileViewBasic[]>({
|
||||||
staleTime: STALE.MINUTES.ONE,
|
staleTime: STALE.MINUTES.ONE,
|
||||||
queryKey: RQKEY(),
|
queryKey: RQKEY(),
|
||||||
|
@ -22,7 +22,7 @@ export function useMyFollowsQuery() {
|
||||||
let cursor
|
let cursor
|
||||||
let arr: AppBskyActorDefs.ProfileViewBasic[] = []
|
let arr: AppBskyActorDefs.ProfileViewBasic[] = []
|
||||||
for (let i = 0; i < SANITY_PAGE_LIMIT; i++) {
|
for (let i = 0; i < SANITY_PAGE_LIMIT; i++) {
|
||||||
const res = await agent.getFollows({
|
const res = await getAgent().getFollows({
|
||||||
actor: currentAccount.did,
|
actor: currentAccount.did,
|
||||||
cursor,
|
cursor,
|
||||||
limit: PAGE_SIZE,
|
limit: PAGE_SIZE,
|
||||||
|
|
|
@ -2,14 +2,14 @@ import {AppBskyGraphDefs} from '@atproto/api'
|
||||||
import {useQuery, QueryClient} from '@tanstack/react-query'
|
import {useQuery, QueryClient} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {accumulate} from '#/lib/async/accumulate'
|
import {accumulate} from '#/lib/async/accumulate'
|
||||||
import {useSession} from '#/state/session'
|
import {useSession, getAgent} from '#/state/session'
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
|
||||||
export type MyListsFilter = 'all' | 'curate' | 'mod'
|
export type MyListsFilter = 'all' | 'curate' | 'mod'
|
||||||
export const RQKEY = (filter: MyListsFilter) => ['my-lists', filter]
|
export const RQKEY = (filter: MyListsFilter) => ['my-lists', filter]
|
||||||
|
|
||||||
export function useMyListsQuery(filter: MyListsFilter) {
|
export function useMyListsQuery(filter: MyListsFilter) {
|
||||||
const {agent, currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
return useQuery<AppBskyGraphDefs.ListView[]>({
|
return useQuery<AppBskyGraphDefs.ListView[]>({
|
||||||
staleTime: STALE.MINUTES.ONE,
|
staleTime: STALE.MINUTES.ONE,
|
||||||
queryKey: RQKEY(filter),
|
queryKey: RQKEY(filter),
|
||||||
|
@ -17,8 +17,8 @@ export function useMyListsQuery(filter: MyListsFilter) {
|
||||||
let lists: AppBskyGraphDefs.ListView[] = []
|
let lists: AppBskyGraphDefs.ListView[] = []
|
||||||
const promises = [
|
const promises = [
|
||||||
accumulate(cursor =>
|
accumulate(cursor =>
|
||||||
agent.app.bsky.graph
|
getAgent()
|
||||||
.getLists({
|
.app.bsky.graph.getLists({
|
||||||
actor: currentAccount!.did,
|
actor: currentAccount!.did,
|
||||||
cursor,
|
cursor,
|
||||||
limit: 50,
|
limit: 50,
|
||||||
|
@ -32,8 +32,8 @@ export function useMyListsQuery(filter: MyListsFilter) {
|
||||||
if (filter === 'all' || filter === 'mod') {
|
if (filter === 'all' || filter === 'mod') {
|
||||||
promises.push(
|
promises.push(
|
||||||
accumulate(cursor =>
|
accumulate(cursor =>
|
||||||
agent.app.bsky.graph
|
getAgent()
|
||||||
.getListMutes({
|
.app.bsky.graph.getListMutes({
|
||||||
cursor,
|
cursor,
|
||||||
limit: 50,
|
limit: 50,
|
||||||
})
|
})
|
||||||
|
@ -45,8 +45,8 @@ export function useMyListsQuery(filter: MyListsFilter) {
|
||||||
)
|
)
|
||||||
promises.push(
|
promises.push(
|
||||||
accumulate(cursor =>
|
accumulate(cursor =>
|
||||||
agent.app.bsky.graph
|
getAgent()
|
||||||
.getListBlocks({
|
.app.bsky.graph.getListBlocks({
|
||||||
cursor,
|
cursor,
|
||||||
limit: 50,
|
limit: 50,
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
import {AppBskyGraphGetMutes} from '@atproto/api'
|
import {AppBskyGraphGetMutes} from '@atproto/api'
|
||||||
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {useSession} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
|
||||||
export const RQKEY = () => ['my-muted-accounts']
|
export const RQKEY = () => ['my-muted-accounts']
|
||||||
type RQPageParam = string | undefined
|
type RQPageParam = string | undefined
|
||||||
|
|
||||||
export function useMyMutedAccountsQuery() {
|
export function useMyMutedAccountsQuery() {
|
||||||
const {agent} = useSession()
|
|
||||||
return useInfiniteQuery<
|
return useInfiniteQuery<
|
||||||
AppBskyGraphGetMutes.OutputSchema,
|
AppBskyGraphGetMutes.OutputSchema,
|
||||||
Error,
|
Error,
|
||||||
|
@ -19,7 +18,7 @@ export function useMyMutedAccountsQuery() {
|
||||||
staleTime: STALE.MINUTES.ONE,
|
staleTime: STALE.MINUTES.ONE,
|
||||||
queryKey: RQKEY(),
|
queryKey: RQKEY(),
|
||||||
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
||||||
const res = await agent.app.bsky.graph.getMutes({
|
const res = await getAgent().app.bsky.graph.getMutes({
|
||||||
limit: 30,
|
limit: 30,
|
||||||
cursor: pageParam,
|
cursor: pageParam,
|
||||||
})
|
})
|
||||||
|
|
|
@ -8,7 +8,7 @@ import {
|
||||||
} from '@atproto/api'
|
} from '@atproto/api'
|
||||||
import chunk from 'lodash.chunk'
|
import chunk from 'lodash.chunk'
|
||||||
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
||||||
import {useSession} from '../../session'
|
import {getAgent} from '../../session'
|
||||||
import {useModerationOpts} from '../preferences'
|
import {useModerationOpts} from '../preferences'
|
||||||
import {shouldFilterNotif} from './util'
|
import {shouldFilterNotif} from './util'
|
||||||
import {useMutedThreads} from '#/state/muted-threads'
|
import {useMutedThreads} from '#/state/muted-threads'
|
||||||
|
@ -49,7 +49,6 @@ export interface FeedPage {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useNotificationFeedQuery(opts?: {enabled?: boolean}) {
|
export function useNotificationFeedQuery(opts?: {enabled?: boolean}) {
|
||||||
const {agent} = useSession()
|
|
||||||
const moderationOpts = useModerationOpts()
|
const moderationOpts = useModerationOpts()
|
||||||
const threadMutes = useMutedThreads()
|
const threadMutes = useMutedThreads()
|
||||||
const enabled = opts?.enabled !== false
|
const enabled = opts?.enabled !== false
|
||||||
|
@ -64,7 +63,7 @@ export function useNotificationFeedQuery(opts?: {enabled?: boolean}) {
|
||||||
staleTime: STALE.INFINITY,
|
staleTime: STALE.INFINITY,
|
||||||
queryKey: RQKEY(),
|
queryKey: RQKEY(),
|
||||||
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
||||||
const res = await agent.listNotifications({
|
const res = await getAgent().listNotifications({
|
||||||
limit: PAGE_SIZE,
|
limit: PAGE_SIZE,
|
||||||
cursor: pageParam,
|
cursor: pageParam,
|
||||||
})
|
})
|
||||||
|
@ -79,7 +78,7 @@ export function useNotificationFeedQuery(opts?: {enabled?: boolean}) {
|
||||||
|
|
||||||
// we fetch subjects of notifications (usually posts) now instead of lazily
|
// we fetch subjects of notifications (usually posts) now instead of lazily
|
||||||
// in the UI to avoid relayouts
|
// in the UI to avoid relayouts
|
||||||
const subjects = await fetchSubjects(agent, notifsGrouped)
|
const subjects = await fetchSubjects(getAgent(), notifsGrouped)
|
||||||
for (const notif of notifsGrouped) {
|
for (const notif of notifsGrouped) {
|
||||||
if (notif.subjectUri) {
|
if (notif.subjectUri) {
|
||||||
notif.subject = subjects.get(notif.subjectUri)
|
notif.subject = subjects.get(notif.subjectUri)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import * as Notifications from 'expo-notifications'
|
import * as Notifications from 'expo-notifications'
|
||||||
import BroadcastChannel from '#/lib/broadcast'
|
import BroadcastChannel from '#/lib/broadcast'
|
||||||
import {useSession} from '#/state/session'
|
import {useSession, getAgent} from '#/state/session'
|
||||||
import {useModerationOpts} from '../preferences'
|
import {useModerationOpts} from '../preferences'
|
||||||
import {shouldFilterNotif} from './util'
|
import {shouldFilterNotif} from './util'
|
||||||
import {isNative} from '#/platform/detection'
|
import {isNative} from '#/platform/detection'
|
||||||
|
@ -25,7 +25,7 @@ const apiContext = React.createContext<ApiContext>({
|
||||||
})
|
})
|
||||||
|
|
||||||
export function Provider({children}: React.PropsWithChildren<{}>) {
|
export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||||
const {hasSession, agent} = useSession()
|
const {hasSession} = useSession()
|
||||||
const moderationOpts = useModerationOpts()
|
const moderationOpts = useModerationOpts()
|
||||||
|
|
||||||
const [numUnread, setNumUnread] = React.useState('')
|
const [numUnread, setNumUnread] = React.useState('')
|
||||||
|
@ -60,7 +60,9 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||||
return {
|
return {
|
||||||
async markAllRead() {
|
async markAllRead() {
|
||||||
// update server
|
// update server
|
||||||
await agent.updateSeenNotifications(lastSyncRef.current.toISOString())
|
await getAgent().updateSeenNotifications(
|
||||||
|
lastSyncRef.current.toISOString(),
|
||||||
|
)
|
||||||
|
|
||||||
// update & broadcast
|
// update & broadcast
|
||||||
setNumUnread('')
|
setNumUnread('')
|
||||||
|
@ -69,7 +71,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||||
|
|
||||||
async checkUnread() {
|
async checkUnread() {
|
||||||
// count
|
// count
|
||||||
const res = await agent.listNotifications({limit: 40})
|
const res = await getAgent().listNotifications({limit: 40})
|
||||||
const filtered = res.data.notifications.filter(
|
const filtered = res.data.notifications.filter(
|
||||||
notif => !notif.isRead && !shouldFilterNotif(notif, moderationOpts),
|
notif => !notif.isRead && !shouldFilterNotif(notif, moderationOpts),
|
||||||
)
|
)
|
||||||
|
@ -94,7 +96,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||||
broadcast.postMessage({event: num})
|
broadcast.postMessage({event: num})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}, [setNumUnread, agent, moderationOpts])
|
}, [setNumUnread, moderationOpts])
|
||||||
checkUnreadRef.current = api.checkUnread
|
checkUnreadRef.current = api.checkUnread
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import {useCallback, useMemo} from 'react'
|
import {useCallback, useMemo} from 'react'
|
||||||
import {AppBskyFeedDefs, AppBskyFeedPost, moderatePost} from '@atproto/api'
|
import {AppBskyFeedDefs, AppBskyFeedPost, moderatePost} from '@atproto/api'
|
||||||
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
||||||
import {useSession} from '../session'
|
import {getAgent} from '../session'
|
||||||
import {useFeedTuners} from '../preferences/feed-tuners'
|
import {useFeedTuners} from '../preferences/feed-tuners'
|
||||||
import {FeedTuner, NoopFeedTuner} from 'lib/api/feed-manip'
|
import {FeedTuner, NoopFeedTuner} from 'lib/api/feed-manip'
|
||||||
import {FeedAPI, ReasonFeedSource} from 'lib/api/feed/types'
|
import {FeedAPI, ReasonFeedSource} from 'lib/api/feed/types'
|
||||||
|
@ -66,10 +66,10 @@ export function usePostFeedQuery(
|
||||||
params?: FeedParams,
|
params?: FeedParams,
|
||||||
opts?: {enabled?: boolean},
|
opts?: {enabled?: boolean},
|
||||||
) {
|
) {
|
||||||
const {agent} = useSession()
|
|
||||||
const feedTuners = useFeedTuners(feedDesc)
|
const feedTuners = useFeedTuners(feedDesc)
|
||||||
const enabled = opts?.enabled !== false
|
const enabled = opts?.enabled !== false
|
||||||
const moderationOpts = useModerationOpts()
|
const moderationOpts = useModerationOpts()
|
||||||
|
const agent = getAgent()
|
||||||
|
|
||||||
const api: FeedAPI = useMemo(() => {
|
const api: FeedAPI = useMemo(() => {
|
||||||
if (feedDesc === 'home') {
|
if (feedDesc === 'home') {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import {AppBskyFeedGetLikes} from '@atproto/api'
|
import {AppBskyFeedGetLikes} from '@atproto/api'
|
||||||
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {useSession} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
|
||||||
const PAGE_SIZE = 30
|
const PAGE_SIZE = 30
|
||||||
|
@ -11,7 +11,6 @@ type RQPageParam = string | undefined
|
||||||
export const RQKEY = (resolvedUri: string) => ['post-liked-by', resolvedUri]
|
export const RQKEY = (resolvedUri: string) => ['post-liked-by', resolvedUri]
|
||||||
|
|
||||||
export function usePostLikedByQuery(resolvedUri: string | undefined) {
|
export function usePostLikedByQuery(resolvedUri: string | undefined) {
|
||||||
const {agent} = useSession()
|
|
||||||
return useInfiniteQuery<
|
return useInfiniteQuery<
|
||||||
AppBskyFeedGetLikes.OutputSchema,
|
AppBskyFeedGetLikes.OutputSchema,
|
||||||
Error,
|
Error,
|
||||||
|
@ -22,7 +21,7 @@ export function usePostLikedByQuery(resolvedUri: string | undefined) {
|
||||||
staleTime: STALE.MINUTES.ONE,
|
staleTime: STALE.MINUTES.ONE,
|
||||||
queryKey: RQKEY(resolvedUri || ''),
|
queryKey: RQKEY(resolvedUri || ''),
|
||||||
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
||||||
const res = await agent.getLikes({
|
const res = await getAgent().getLikes({
|
||||||
uri: resolvedUri || '',
|
uri: resolvedUri || '',
|
||||||
limit: PAGE_SIZE,
|
limit: PAGE_SIZE,
|
||||||
cursor: pageParam,
|
cursor: pageParam,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import {AppBskyFeedGetRepostedBy} from '@atproto/api'
|
import {AppBskyFeedGetRepostedBy} from '@atproto/api'
|
||||||
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {useSession} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
|
||||||
const PAGE_SIZE = 30
|
const PAGE_SIZE = 30
|
||||||
|
@ -11,7 +11,6 @@ type RQPageParam = string | undefined
|
||||||
export const RQKEY = (resolvedUri: string) => ['post-reposted-by', resolvedUri]
|
export const RQKEY = (resolvedUri: string) => ['post-reposted-by', resolvedUri]
|
||||||
|
|
||||||
export function usePostRepostedByQuery(resolvedUri: string | undefined) {
|
export function usePostRepostedByQuery(resolvedUri: string | undefined) {
|
||||||
const {agent} = useSession()
|
|
||||||
return useInfiniteQuery<
|
return useInfiniteQuery<
|
||||||
AppBskyFeedGetRepostedBy.OutputSchema,
|
AppBskyFeedGetRepostedBy.OutputSchema,
|
||||||
Error,
|
Error,
|
||||||
|
@ -22,7 +21,7 @@ export function usePostRepostedByQuery(resolvedUri: string | undefined) {
|
||||||
staleTime: STALE.MINUTES.ONE,
|
staleTime: STALE.MINUTES.ONE,
|
||||||
queryKey: RQKEY(resolvedUri || ''),
|
queryKey: RQKEY(resolvedUri || ''),
|
||||||
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
||||||
const res = await agent.getRepostedBy({
|
const res = await getAgent().getRepostedBy({
|
||||||
uri: resolvedUri || '',
|
uri: resolvedUri || '',
|
||||||
limit: PAGE_SIZE,
|
limit: PAGE_SIZE,
|
||||||
cursor: pageParam,
|
cursor: pageParam,
|
||||||
|
|
|
@ -5,7 +5,7 @@ import {
|
||||||
} from '@atproto/api'
|
} from '@atproto/api'
|
||||||
import {useQuery} from '@tanstack/react-query'
|
import {useQuery} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {useSession} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
import {UsePreferencesQueryResponse} from '#/state/queries/preferences/types'
|
import {UsePreferencesQueryResponse} from '#/state/queries/preferences/types'
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
|
||||||
|
@ -58,12 +58,11 @@ export type ThreadNode =
|
||||||
| ThreadUnknown
|
| ThreadUnknown
|
||||||
|
|
||||||
export function usePostThreadQuery(uri: string | undefined) {
|
export function usePostThreadQuery(uri: string | undefined) {
|
||||||
const {agent} = useSession()
|
|
||||||
return useQuery<ThreadNode, Error>({
|
return useQuery<ThreadNode, Error>({
|
||||||
staleTime: STALE.MINUTES.ONE,
|
staleTime: STALE.MINUTES.ONE,
|
||||||
queryKey: RQKEY(uri || ''),
|
queryKey: RQKEY(uri || ''),
|
||||||
async queryFn() {
|
async queryFn() {
|
||||||
const res = await agent.getPostThread({uri: uri!})
|
const res = await getAgent().getPostThread({uri: uri!})
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
return responseToThreadNodes(res.data.thread)
|
return responseToThreadNodes(res.data.thread)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,19 +2,18 @@ import React from 'react'
|
||||||
import {AppBskyFeedDefs, AtUri} from '@atproto/api'
|
import {AppBskyFeedDefs, AtUri} from '@atproto/api'
|
||||||
import {useQuery, useMutation, useQueryClient} from '@tanstack/react-query'
|
import {useQuery, useMutation, useQueryClient} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {useSession} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
import {updatePostShadow} from '#/state/cache/post-shadow'
|
import {updatePostShadow} from '#/state/cache/post-shadow'
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
|
||||||
export const RQKEY = (postUri: string) => ['post', postUri]
|
export const RQKEY = (postUri: string) => ['post', postUri]
|
||||||
|
|
||||||
export function usePostQuery(uri: string | undefined) {
|
export function usePostQuery(uri: string | undefined) {
|
||||||
const {agent} = useSession()
|
|
||||||
return useQuery<AppBskyFeedDefs.PostView>({
|
return useQuery<AppBskyFeedDefs.PostView>({
|
||||||
staleTime: STALE.MINUTES.ONE,
|
staleTime: STALE.MINUTES.ONE,
|
||||||
queryKey: RQKEY(uri || ''),
|
queryKey: RQKEY(uri || ''),
|
||||||
async queryFn() {
|
async queryFn() {
|
||||||
const res = await agent.getPosts({uris: [uri!]})
|
const res = await getAgent().getPosts({uris: [uri!]})
|
||||||
if (res.success && res.data.posts[0]) {
|
if (res.success && res.data.posts[0]) {
|
||||||
return res.data.posts[0]
|
return res.data.posts[0]
|
||||||
}
|
}
|
||||||
|
@ -27,7 +26,6 @@ export function usePostQuery(uri: string | undefined) {
|
||||||
|
|
||||||
export function useGetPost() {
|
export function useGetPost() {
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const {agent} = useSession()
|
|
||||||
return React.useCallback(
|
return React.useCallback(
|
||||||
async ({uri}: {uri: string}) => {
|
async ({uri}: {uri: string}) => {
|
||||||
return queryClient.fetchQuery({
|
return queryClient.fetchQuery({
|
||||||
|
@ -37,13 +35,13 @@ export function useGetPost() {
|
||||||
const urip = new AtUri(uri)
|
const urip = new AtUri(uri)
|
||||||
|
|
||||||
if (!urip.host.startsWith('did:')) {
|
if (!urip.host.startsWith('did:')) {
|
||||||
const res = await agent.resolveHandle({
|
const res = await getAgent().resolveHandle({
|
||||||
handle: urip.host,
|
handle: urip.host,
|
||||||
})
|
})
|
||||||
urip.host = res.data.did
|
urip.host = res.data.did
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await agent.getPosts({
|
const res = await getAgent().getPosts({
|
||||||
uris: [urip.toString()!],
|
uris: [urip.toString()!],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -55,18 +53,17 @@ export function useGetPost() {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
[agent, queryClient],
|
[queryClient],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function usePostLikeMutation() {
|
export function usePostLikeMutation() {
|
||||||
const {agent} = useSession()
|
|
||||||
return useMutation<
|
return useMutation<
|
||||||
{uri: string}, // responds with the uri of the like
|
{uri: string}, // responds with the uri of the like
|
||||||
Error,
|
Error,
|
||||||
{uri: string; cid: string; likeCount: number} // the post's uri, cid, and likes
|
{uri: string; cid: string; likeCount: number} // the post's uri, cid, and likes
|
||||||
>({
|
>({
|
||||||
mutationFn: post => agent.like(post.uri, post.cid),
|
mutationFn: post => getAgent().like(post.uri, post.cid),
|
||||||
onMutate(variables) {
|
onMutate(variables) {
|
||||||
// optimistically update the post-shadow
|
// optimistically update the post-shadow
|
||||||
updatePostShadow(variables.uri, {
|
updatePostShadow(variables.uri, {
|
||||||
|
@ -91,14 +88,13 @@ export function usePostLikeMutation() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function usePostUnlikeMutation() {
|
export function usePostUnlikeMutation() {
|
||||||
const {agent} = useSession()
|
|
||||||
return useMutation<
|
return useMutation<
|
||||||
void,
|
void,
|
||||||
Error,
|
Error,
|
||||||
{postUri: string; likeUri: string; likeCount: number}
|
{postUri: string; likeUri: string; likeCount: number}
|
||||||
>({
|
>({
|
||||||
mutationFn: async ({likeUri}) => {
|
mutationFn: async ({likeUri}) => {
|
||||||
await agent.deleteLike(likeUri)
|
await getAgent().deleteLike(likeUri)
|
||||||
},
|
},
|
||||||
onMutate(variables) {
|
onMutate(variables) {
|
||||||
// optimistically update the post-shadow
|
// optimistically update the post-shadow
|
||||||
|
@ -118,13 +114,12 @@ export function usePostUnlikeMutation() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function usePostRepostMutation() {
|
export function usePostRepostMutation() {
|
||||||
const {agent} = useSession()
|
|
||||||
return useMutation<
|
return useMutation<
|
||||||
{uri: string}, // responds with the uri of the repost
|
{uri: string}, // responds with the uri of the repost
|
||||||
Error,
|
Error,
|
||||||
{uri: string; cid: string; repostCount: number} // the post's uri, cid, and reposts
|
{uri: string; cid: string; repostCount: number} // the post's uri, cid, and reposts
|
||||||
>({
|
>({
|
||||||
mutationFn: post => agent.repost(post.uri, post.cid),
|
mutationFn: post => getAgent().repost(post.uri, post.cid),
|
||||||
onMutate(variables) {
|
onMutate(variables) {
|
||||||
// optimistically update the post-shadow
|
// optimistically update the post-shadow
|
||||||
updatePostShadow(variables.uri, {
|
updatePostShadow(variables.uri, {
|
||||||
|
@ -149,14 +144,13 @@ export function usePostRepostMutation() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function usePostUnrepostMutation() {
|
export function usePostUnrepostMutation() {
|
||||||
const {agent} = useSession()
|
|
||||||
return useMutation<
|
return useMutation<
|
||||||
void,
|
void,
|
||||||
Error,
|
Error,
|
||||||
{postUri: string; repostUri: string; repostCount: number}
|
{postUri: string; repostUri: string; repostCount: number}
|
||||||
>({
|
>({
|
||||||
mutationFn: async ({repostUri}) => {
|
mutationFn: async ({repostUri}) => {
|
||||||
await agent.deleteRepost(repostUri)
|
await getAgent().deleteRepost(repostUri)
|
||||||
},
|
},
|
||||||
onMutate(variables) {
|
onMutate(variables) {
|
||||||
// optimistically update the post-shadow
|
// optimistically update the post-shadow
|
||||||
|
@ -176,10 +170,9 @@ export function usePostUnrepostMutation() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function usePostDeleteMutation() {
|
export function usePostDeleteMutation() {
|
||||||
const {agent} = useSession()
|
|
||||||
return useMutation<void, Error, {uri: string}>({
|
return useMutation<void, Error, {uri: string}>({
|
||||||
mutationFn: async ({uri}) => {
|
mutationFn: async ({uri}) => {
|
||||||
await agent.deletePost(uri)
|
await getAgent().deletePost(uri)
|
||||||
},
|
},
|
||||||
onSuccess(data, variables) {
|
onSuccess(data, variables) {
|
||||||
updatePostShadow(variables.uri, {isDeleted: true})
|
updatePostShadow(variables.uri, {isDeleted: true})
|
||||||
|
|
|
@ -9,7 +9,7 @@ import isEqual from 'lodash.isequal'
|
||||||
|
|
||||||
import {track} from '#/lib/analytics/analytics'
|
import {track} from '#/lib/analytics/analytics'
|
||||||
import {getAge} from '#/lib/strings/time'
|
import {getAge} from '#/lib/strings/time'
|
||||||
import {useSession} from '#/state/session'
|
import {useSession, getAgent} from '#/state/session'
|
||||||
import {DEFAULT_LABEL_PREFERENCES} from '#/state/queries/preferences/moderation'
|
import {DEFAULT_LABEL_PREFERENCES} from '#/state/queries/preferences/moderation'
|
||||||
import {
|
import {
|
||||||
ConfigurableLabelGroup,
|
ConfigurableLabelGroup,
|
||||||
|
@ -31,13 +31,13 @@ export * from '#/state/queries/preferences/const'
|
||||||
export const usePreferencesQueryKey = ['getPreferences']
|
export const usePreferencesQueryKey = ['getPreferences']
|
||||||
|
|
||||||
export function usePreferencesQuery() {
|
export function usePreferencesQuery() {
|
||||||
const {agent, hasSession} = useSession()
|
const {hasSession} = useSession()
|
||||||
return useQuery({
|
return useQuery({
|
||||||
enabled: hasSession,
|
enabled: hasSession,
|
||||||
staleTime: STALE.MINUTES.ONE,
|
staleTime: STALE.MINUTES.ONE,
|
||||||
queryKey: usePreferencesQueryKey,
|
queryKey: usePreferencesQueryKey,
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const res = await agent.getPreferences()
|
const res = await getAgent().getPreferences()
|
||||||
const preferences: UsePreferencesQueryResponse = {
|
const preferences: UsePreferencesQueryResponse = {
|
||||||
...res,
|
...res,
|
||||||
feeds: {
|
feeds: {
|
||||||
|
@ -110,12 +110,11 @@ export function useModerationOpts() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useClearPreferencesMutation() {
|
export function useClearPreferencesMutation() {
|
||||||
const {agent} = useSession()
|
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
await agent.app.bsky.actor.putPreferences({preferences: []})
|
await getAgent().app.bsky.actor.putPreferences({preferences: []})
|
||||||
// triggers a refetch
|
// triggers a refetch
|
||||||
await queryClient.invalidateQueries({
|
await queryClient.invalidateQueries({
|
||||||
queryKey: usePreferencesQueryKey,
|
queryKey: usePreferencesQueryKey,
|
||||||
|
@ -125,7 +124,6 @@ export function useClearPreferencesMutation() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function usePreferencesSetContentLabelMutation() {
|
export function usePreferencesSetContentLabelMutation() {
|
||||||
const {agent} = useSession()
|
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
return useMutation<
|
return useMutation<
|
||||||
|
@ -134,7 +132,7 @@ export function usePreferencesSetContentLabelMutation() {
|
||||||
{labelGroup: ConfigurableLabelGroup; visibility: LabelPreference}
|
{labelGroup: ConfigurableLabelGroup; visibility: LabelPreference}
|
||||||
>({
|
>({
|
||||||
mutationFn: async ({labelGroup, visibility}) => {
|
mutationFn: async ({labelGroup, visibility}) => {
|
||||||
await agent.setContentLabelPref(labelGroup, visibility)
|
await getAgent().setContentLabelPref(labelGroup, visibility)
|
||||||
// triggers a refetch
|
// triggers a refetch
|
||||||
await queryClient.invalidateQueries({
|
await queryClient.invalidateQueries({
|
||||||
queryKey: usePreferencesQueryKey,
|
queryKey: usePreferencesQueryKey,
|
||||||
|
@ -144,12 +142,11 @@ export function usePreferencesSetContentLabelMutation() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function usePreferencesSetAdultContentMutation() {
|
export function usePreferencesSetAdultContentMutation() {
|
||||||
const {agent} = useSession()
|
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
return useMutation<void, unknown, {enabled: boolean}>({
|
return useMutation<void, unknown, {enabled: boolean}>({
|
||||||
mutationFn: async ({enabled}) => {
|
mutationFn: async ({enabled}) => {
|
||||||
await agent.setAdultContentEnabled(enabled)
|
await getAgent().setAdultContentEnabled(enabled)
|
||||||
// triggers a refetch
|
// triggers a refetch
|
||||||
await queryClient.invalidateQueries({
|
await queryClient.invalidateQueries({
|
||||||
queryKey: usePreferencesQueryKey,
|
queryKey: usePreferencesQueryKey,
|
||||||
|
@ -159,12 +156,11 @@ export function usePreferencesSetAdultContentMutation() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function usePreferencesSetBirthDateMutation() {
|
export function usePreferencesSetBirthDateMutation() {
|
||||||
const {agent} = useSession()
|
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
return useMutation<void, unknown, {birthDate: Date}>({
|
return useMutation<void, unknown, {birthDate: Date}>({
|
||||||
mutationFn: async ({birthDate}: {birthDate: Date}) => {
|
mutationFn: async ({birthDate}: {birthDate: Date}) => {
|
||||||
await agent.setPersonalDetails({birthDate})
|
await getAgent().setPersonalDetails({birthDate})
|
||||||
// triggers a refetch
|
// triggers a refetch
|
||||||
await queryClient.invalidateQueries({
|
await queryClient.invalidateQueries({
|
||||||
queryKey: usePreferencesQueryKey,
|
queryKey: usePreferencesQueryKey,
|
||||||
|
@ -174,12 +170,11 @@ export function usePreferencesSetBirthDateMutation() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useSetFeedViewPreferencesMutation() {
|
export function useSetFeedViewPreferencesMutation() {
|
||||||
const {agent} = useSession()
|
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
return useMutation<void, unknown, Partial<BskyFeedViewPreference>>({
|
return useMutation<void, unknown, Partial<BskyFeedViewPreference>>({
|
||||||
mutationFn: async prefs => {
|
mutationFn: async prefs => {
|
||||||
await agent.setFeedViewPrefs('home', prefs)
|
await getAgent().setFeedViewPrefs('home', prefs)
|
||||||
// triggers a refetch
|
// triggers a refetch
|
||||||
await queryClient.invalidateQueries({
|
await queryClient.invalidateQueries({
|
||||||
queryKey: usePreferencesQueryKey,
|
queryKey: usePreferencesQueryKey,
|
||||||
|
@ -189,12 +184,11 @@ export function useSetFeedViewPreferencesMutation() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useSetThreadViewPreferencesMutation() {
|
export function useSetThreadViewPreferencesMutation() {
|
||||||
const {agent} = useSession()
|
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
return useMutation<void, unknown, Partial<ThreadViewPreferences>>({
|
return useMutation<void, unknown, Partial<ThreadViewPreferences>>({
|
||||||
mutationFn: async prefs => {
|
mutationFn: async prefs => {
|
||||||
await agent.setThreadViewPrefs(prefs)
|
await getAgent().setThreadViewPrefs(prefs)
|
||||||
// triggers a refetch
|
// triggers a refetch
|
||||||
await queryClient.invalidateQueries({
|
await queryClient.invalidateQueries({
|
||||||
queryKey: usePreferencesQueryKey,
|
queryKey: usePreferencesQueryKey,
|
||||||
|
@ -204,7 +198,6 @@ export function useSetThreadViewPreferencesMutation() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useSetSaveFeedsMutation() {
|
export function useSetSaveFeedsMutation() {
|
||||||
const {agent} = useSession()
|
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
return useMutation<
|
return useMutation<
|
||||||
|
@ -213,7 +206,7 @@ export function useSetSaveFeedsMutation() {
|
||||||
Pick<UsePreferencesQueryResponse['feeds'], 'saved' | 'pinned'>
|
Pick<UsePreferencesQueryResponse['feeds'], 'saved' | 'pinned'>
|
||||||
>({
|
>({
|
||||||
mutationFn: async ({saved, pinned}) => {
|
mutationFn: async ({saved, pinned}) => {
|
||||||
await agent.setSavedFeeds(saved, pinned)
|
await getAgent().setSavedFeeds(saved, pinned)
|
||||||
// triggers a refetch
|
// triggers a refetch
|
||||||
await queryClient.invalidateQueries({
|
await queryClient.invalidateQueries({
|
||||||
queryKey: usePreferencesQueryKey,
|
queryKey: usePreferencesQueryKey,
|
||||||
|
@ -223,12 +216,11 @@ export function useSetSaveFeedsMutation() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useSaveFeedMutation() {
|
export function useSaveFeedMutation() {
|
||||||
const {agent} = useSession()
|
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
return useMutation<void, unknown, {uri: string}>({
|
return useMutation<void, unknown, {uri: string}>({
|
||||||
mutationFn: async ({uri}) => {
|
mutationFn: async ({uri}) => {
|
||||||
await agent.addSavedFeed(uri)
|
await getAgent().addSavedFeed(uri)
|
||||||
track('CustomFeed:Save')
|
track('CustomFeed:Save')
|
||||||
// triggers a refetch
|
// triggers a refetch
|
||||||
await queryClient.invalidateQueries({
|
await queryClient.invalidateQueries({
|
||||||
|
@ -239,12 +231,11 @@ export function useSaveFeedMutation() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useRemoveFeedMutation() {
|
export function useRemoveFeedMutation() {
|
||||||
const {agent} = useSession()
|
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
return useMutation<void, unknown, {uri: string}>({
|
return useMutation<void, unknown, {uri: string}>({
|
||||||
mutationFn: async ({uri}) => {
|
mutationFn: async ({uri}) => {
|
||||||
await agent.removeSavedFeed(uri)
|
await getAgent().removeSavedFeed(uri)
|
||||||
track('CustomFeed:Unsave')
|
track('CustomFeed:Unsave')
|
||||||
// triggers a refetch
|
// triggers a refetch
|
||||||
await queryClient.invalidateQueries({
|
await queryClient.invalidateQueries({
|
||||||
|
@ -255,12 +246,11 @@ export function useRemoveFeedMutation() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function usePinFeedMutation() {
|
export function usePinFeedMutation() {
|
||||||
const {agent} = useSession()
|
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
return useMutation<void, unknown, {uri: string}>({
|
return useMutation<void, unknown, {uri: string}>({
|
||||||
mutationFn: async ({uri}) => {
|
mutationFn: async ({uri}) => {
|
||||||
await agent.addPinnedFeed(uri)
|
await getAgent().addPinnedFeed(uri)
|
||||||
track('CustomFeed:Pin', {uri})
|
track('CustomFeed:Pin', {uri})
|
||||||
// triggers a refetch
|
// triggers a refetch
|
||||||
await queryClient.invalidateQueries({
|
await queryClient.invalidateQueries({
|
||||||
|
@ -271,12 +261,11 @@ export function usePinFeedMutation() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useUnpinFeedMutation() {
|
export function useUnpinFeedMutation() {
|
||||||
const {agent} = useSession()
|
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
return useMutation<void, unknown, {uri: string}>({
|
return useMutation<void, unknown, {uri: string}>({
|
||||||
mutationFn: async ({uri}) => {
|
mutationFn: async ({uri}) => {
|
||||||
await agent.removePinnedFeed(uri)
|
await getAgent().removePinnedFeed(uri)
|
||||||
track('CustomFeed:Unpin', {uri})
|
track('CustomFeed:Unpin', {uri})
|
||||||
// triggers a refetch
|
// triggers a refetch
|
||||||
await queryClient.invalidateQueries({
|
await queryClient.invalidateQueries({
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import {useQuery} from '@tanstack/react-query'
|
import {useQuery} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {useSession} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
|
||||||
// TODO refactor invalidate on mutate?
|
// TODO refactor invalidate on mutate?
|
||||||
|
@ -11,17 +11,16 @@ export const RQKEY = (did: string) => ['profile-extra-info', did]
|
||||||
* is not available in the API's ProfileView
|
* is not available in the API's ProfileView
|
||||||
*/
|
*/
|
||||||
export function useProfileExtraInfoQuery(did: string) {
|
export function useProfileExtraInfoQuery(did: string) {
|
||||||
const {agent} = useSession()
|
|
||||||
return useQuery({
|
return useQuery({
|
||||||
staleTime: STALE.MINUTES.ONE,
|
staleTime: STALE.MINUTES.ONE,
|
||||||
queryKey: RQKEY(did),
|
queryKey: RQKEY(did),
|
||||||
async queryFn() {
|
async queryFn() {
|
||||||
const [listsRes, feedsRes] = await Promise.all([
|
const [listsRes, feedsRes] = await Promise.all([
|
||||||
agent.app.bsky.graph.getLists({
|
getAgent().app.bsky.graph.getLists({
|
||||||
actor: did,
|
actor: did,
|
||||||
limit: 1,
|
limit: 1,
|
||||||
}),
|
}),
|
||||||
agent.app.bsky.feed.getActorFeeds({
|
getAgent().app.bsky.feed.getActorFeeds({
|
||||||
actor: did,
|
actor: did,
|
||||||
limit: 1,
|
limit: 1,
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import {AppBskyFeedGetActorFeeds} from '@atproto/api'
|
import {AppBskyFeedGetActorFeeds} from '@atproto/api'
|
||||||
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {useSession} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
|
||||||
const PAGE_SIZE = 30
|
const PAGE_SIZE = 30
|
||||||
|
@ -14,7 +14,6 @@ export function useProfileFeedgensQuery(
|
||||||
did: string,
|
did: string,
|
||||||
opts?: {enabled?: boolean},
|
opts?: {enabled?: boolean},
|
||||||
) {
|
) {
|
||||||
const {agent} = useSession()
|
|
||||||
const enabled = opts?.enabled !== false
|
const enabled = opts?.enabled !== false
|
||||||
return useInfiniteQuery<
|
return useInfiniteQuery<
|
||||||
AppBskyFeedGetActorFeeds.OutputSchema,
|
AppBskyFeedGetActorFeeds.OutputSchema,
|
||||||
|
@ -26,7 +25,7 @@ export function useProfileFeedgensQuery(
|
||||||
staleTime: STALE.MINUTES.ONE,
|
staleTime: STALE.MINUTES.ONE,
|
||||||
queryKey: RQKEY(did),
|
queryKey: RQKEY(did),
|
||||||
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
||||||
const res = await agent.app.bsky.feed.getActorFeeds({
|
const res = await getAgent().app.bsky.feed.getActorFeeds({
|
||||||
actor: did,
|
actor: did,
|
||||||
limit: PAGE_SIZE,
|
limit: PAGE_SIZE,
|
||||||
cursor: pageParam,
|
cursor: pageParam,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import {AppBskyGraphGetFollowers} from '@atproto/api'
|
import {AppBskyGraphGetFollowers} from '@atproto/api'
|
||||||
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {useSession} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
|
||||||
const PAGE_SIZE = 30
|
const PAGE_SIZE = 30
|
||||||
|
@ -10,7 +10,6 @@ type RQPageParam = string | undefined
|
||||||
export const RQKEY = (did: string) => ['profile-followers', did]
|
export const RQKEY = (did: string) => ['profile-followers', did]
|
||||||
|
|
||||||
export function useProfileFollowersQuery(did: string | undefined) {
|
export function useProfileFollowersQuery(did: string | undefined) {
|
||||||
const {agent} = useSession()
|
|
||||||
return useInfiniteQuery<
|
return useInfiniteQuery<
|
||||||
AppBskyGraphGetFollowers.OutputSchema,
|
AppBskyGraphGetFollowers.OutputSchema,
|
||||||
Error,
|
Error,
|
||||||
|
@ -21,7 +20,7 @@ export function useProfileFollowersQuery(did: string | undefined) {
|
||||||
staleTime: STALE.MINUTES.FIVE,
|
staleTime: STALE.MINUTES.FIVE,
|
||||||
queryKey: RQKEY(did || ''),
|
queryKey: RQKEY(did || ''),
|
||||||
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
||||||
const res = await agent.app.bsky.graph.getFollowers({
|
const res = await getAgent().app.bsky.graph.getFollowers({
|
||||||
actor: did || '',
|
actor: did || '',
|
||||||
limit: PAGE_SIZE,
|
limit: PAGE_SIZE,
|
||||||
cursor: pageParam,
|
cursor: pageParam,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import {AppBskyGraphGetFollows} from '@atproto/api'
|
import {AppBskyGraphGetFollows} from '@atproto/api'
|
||||||
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {useSession} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
|
||||||
const PAGE_SIZE = 30
|
const PAGE_SIZE = 30
|
||||||
|
@ -11,7 +11,6 @@ type RQPageParam = string | undefined
|
||||||
export const RQKEY = (did: string) => ['profile-follows', did]
|
export const RQKEY = (did: string) => ['profile-follows', did]
|
||||||
|
|
||||||
export function useProfileFollowsQuery(did: string | undefined) {
|
export function useProfileFollowsQuery(did: string | undefined) {
|
||||||
const {agent} = useSession()
|
|
||||||
return useInfiniteQuery<
|
return useInfiniteQuery<
|
||||||
AppBskyGraphGetFollows.OutputSchema,
|
AppBskyGraphGetFollows.OutputSchema,
|
||||||
Error,
|
Error,
|
||||||
|
@ -22,7 +21,7 @@ export function useProfileFollowsQuery(did: string | undefined) {
|
||||||
staleTime: STALE.MINUTES.ONE,
|
staleTime: STALE.MINUTES.ONE,
|
||||||
queryKey: RQKEY(did || ''),
|
queryKey: RQKEY(did || ''),
|
||||||
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
||||||
const res = await agent.app.bsky.graph.getFollows({
|
const res = await getAgent().app.bsky.graph.getFollows({
|
||||||
actor: did || '',
|
actor: did || '',
|
||||||
limit: PAGE_SIZE,
|
limit: PAGE_SIZE,
|
||||||
cursor: pageParam,
|
cursor: pageParam,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import {AppBskyGraphGetLists} from '@atproto/api'
|
import {AppBskyGraphGetLists} from '@atproto/api'
|
||||||
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {useSession} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
|
||||||
const PAGE_SIZE = 30
|
const PAGE_SIZE = 30
|
||||||
|
@ -10,7 +10,6 @@ type RQPageParam = string | undefined
|
||||||
export const RQKEY = (did: string) => ['profile-lists', did]
|
export const RQKEY = (did: string) => ['profile-lists', did]
|
||||||
|
|
||||||
export function useProfileListsQuery(did: string, opts?: {enabled?: boolean}) {
|
export function useProfileListsQuery(did: string, opts?: {enabled?: boolean}) {
|
||||||
const {agent} = useSession()
|
|
||||||
const enabled = opts?.enabled !== false
|
const enabled = opts?.enabled !== false
|
||||||
return useInfiniteQuery<
|
return useInfiniteQuery<
|
||||||
AppBskyGraphGetLists.OutputSchema,
|
AppBskyGraphGetLists.OutputSchema,
|
||||||
|
@ -22,7 +21,7 @@ export function useProfileListsQuery(did: string, opts?: {enabled?: boolean}) {
|
||||||
staleTime: STALE.MINUTES.ONE,
|
staleTime: STALE.MINUTES.ONE,
|
||||||
queryKey: RQKEY(did),
|
queryKey: RQKEY(did),
|
||||||
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
||||||
const res = await agent.app.bsky.graph.getLists({
|
const res = await getAgent().app.bsky.graph.getLists({
|
||||||
actor: did,
|
actor: did,
|
||||||
limit: PAGE_SIZE,
|
limit: PAGE_SIZE,
|
||||||
cursor: pageParam,
|
cursor: pageParam,
|
||||||
|
|
|
@ -8,7 +8,7 @@ import {
|
||||||
} from '@atproto/api'
|
} from '@atproto/api'
|
||||||
import {useQuery, useQueryClient, useMutation} from '@tanstack/react-query'
|
import {useQuery, useQueryClient, useMutation} from '@tanstack/react-query'
|
||||||
import {Image as RNImage} from 'react-native-image-crop-picker'
|
import {Image as RNImage} from 'react-native-image-crop-picker'
|
||||||
import {useSession} from '../session'
|
import {useSession, getAgent} from '../session'
|
||||||
import {updateProfileShadow} from '../cache/profile-shadow'
|
import {updateProfileShadow} from '../cache/profile-shadow'
|
||||||
import {uploadBlob} from '#/lib/api'
|
import {uploadBlob} from '#/lib/api'
|
||||||
import {until} from '#/lib/async/until'
|
import {until} from '#/lib/async/until'
|
||||||
|
@ -21,12 +21,11 @@ import {STALE} from '#/state/queries'
|
||||||
export const RQKEY = (did: string) => ['profile', did]
|
export const RQKEY = (did: string) => ['profile', did]
|
||||||
|
|
||||||
export function useProfileQuery({did}: {did: string | undefined}) {
|
export function useProfileQuery({did}: {did: string | undefined}) {
|
||||||
const {agent} = useSession()
|
|
||||||
return useQuery({
|
return useQuery({
|
||||||
staleTime: STALE.MINUTES.FIVE,
|
staleTime: STALE.MINUTES.FIVE,
|
||||||
queryKey: RQKEY(did || ''),
|
queryKey: RQKEY(did || ''),
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const res = await agent.getProfile({actor: did || ''})
|
const res = await getAgent().getProfile({actor: did || ''})
|
||||||
return res.data
|
return res.data
|
||||||
},
|
},
|
||||||
enabled: !!did,
|
enabled: !!did,
|
||||||
|
@ -40,17 +39,16 @@ interface ProfileUpdateParams {
|
||||||
newUserBanner: RNImage | undefined | null
|
newUserBanner: RNImage | undefined | null
|
||||||
}
|
}
|
||||||
export function useProfileUpdateMutation() {
|
export function useProfileUpdateMutation() {
|
||||||
const {agent} = useSession()
|
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
return useMutation<void, Error, ProfileUpdateParams>({
|
return useMutation<void, Error, ProfileUpdateParams>({
|
||||||
mutationFn: async ({profile, updates, newUserAvatar, newUserBanner}) => {
|
mutationFn: async ({profile, updates, newUserAvatar, newUserBanner}) => {
|
||||||
await agent.upsertProfile(async existing => {
|
await getAgent().upsertProfile(async existing => {
|
||||||
existing = existing || {}
|
existing = existing || {}
|
||||||
existing.displayName = updates.displayName
|
existing.displayName = updates.displayName
|
||||||
existing.description = updates.description
|
existing.description = updates.description
|
||||||
if (newUserAvatar) {
|
if (newUserAvatar) {
|
||||||
const res = await uploadBlob(
|
const res = await uploadBlob(
|
||||||
agent,
|
getAgent(),
|
||||||
newUserAvatar.path,
|
newUserAvatar.path,
|
||||||
newUserAvatar.mime,
|
newUserAvatar.mime,
|
||||||
)
|
)
|
||||||
|
@ -60,7 +58,7 @@ export function useProfileUpdateMutation() {
|
||||||
}
|
}
|
||||||
if (newUserBanner) {
|
if (newUserBanner) {
|
||||||
const res = await uploadBlob(
|
const res = await uploadBlob(
|
||||||
agent,
|
getAgent(),
|
||||||
newUserBanner.path,
|
newUserBanner.path,
|
||||||
newUserBanner.mime,
|
newUserBanner.mime,
|
||||||
)
|
)
|
||||||
|
@ -70,7 +68,7 @@ export function useProfileUpdateMutation() {
|
||||||
}
|
}
|
||||||
return existing
|
return existing
|
||||||
})
|
})
|
||||||
await whenAppViewReady(agent, profile.did, res => {
|
await whenAppViewReady(getAgent(), profile.did, res => {
|
||||||
if (typeof newUserAvatar !== 'undefined') {
|
if (typeof newUserAvatar !== 'undefined') {
|
||||||
if (newUserAvatar === null && res.data.avatar) {
|
if (newUserAvatar === null && res.data.avatar) {
|
||||||
// url hasnt cleared yet
|
// url hasnt cleared yet
|
||||||
|
@ -160,14 +158,13 @@ export function useProfileFollowMutationQueue(
|
||||||
}
|
}
|
||||||
|
|
||||||
function useProfileFollowMutation() {
|
function useProfileFollowMutation() {
|
||||||
const {agent} = useSession()
|
|
||||||
return useMutation<
|
return useMutation<
|
||||||
{uri: string; cid: string},
|
{uri: string; cid: string},
|
||||||
Error,
|
Error,
|
||||||
{did: string; skipOptimistic?: boolean}
|
{did: string; skipOptimistic?: boolean}
|
||||||
>({
|
>({
|
||||||
mutationFn: async ({did}) => {
|
mutationFn: async ({did}) => {
|
||||||
return await agent.follow(did)
|
return await getAgent().follow(did)
|
||||||
},
|
},
|
||||||
onMutate(variables) {
|
onMutate(variables) {
|
||||||
if (!variables.skipOptimistic) {
|
if (!variables.skipOptimistic) {
|
||||||
|
@ -197,14 +194,13 @@ function useProfileFollowMutation() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function useProfileUnfollowMutation() {
|
function useProfileUnfollowMutation() {
|
||||||
const {agent} = useSession()
|
|
||||||
return useMutation<
|
return useMutation<
|
||||||
void,
|
void,
|
||||||
Error,
|
Error,
|
||||||
{did: string; followUri: string; skipOptimistic?: boolean}
|
{did: string; followUri: string; skipOptimistic?: boolean}
|
||||||
>({
|
>({
|
||||||
mutationFn: async ({followUri}) => {
|
mutationFn: async ({followUri}) => {
|
||||||
return await agent.deleteFollow(followUri)
|
return await getAgent().deleteFollow(followUri)
|
||||||
},
|
},
|
||||||
onMutate(variables) {
|
onMutate(variables) {
|
||||||
if (!variables.skipOptimistic) {
|
if (!variables.skipOptimistic) {
|
||||||
|
@ -276,11 +272,10 @@ export function useProfileMuteMutationQueue(
|
||||||
}
|
}
|
||||||
|
|
||||||
function useProfileMuteMutation() {
|
function useProfileMuteMutation() {
|
||||||
const {agent} = useSession()
|
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
return useMutation<void, Error, {did: string; skipOptimistic?: boolean}>({
|
return useMutation<void, Error, {did: string; skipOptimistic?: boolean}>({
|
||||||
mutationFn: async ({did}) => {
|
mutationFn: async ({did}) => {
|
||||||
await agent.mute(did)
|
await getAgent().mute(did)
|
||||||
},
|
},
|
||||||
onMutate(variables) {
|
onMutate(variables) {
|
||||||
if (!variables.skipOptimistic) {
|
if (!variables.skipOptimistic) {
|
||||||
|
@ -305,11 +300,10 @@ function useProfileMuteMutation() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function useProfileUnmuteMutation() {
|
function useProfileUnmuteMutation() {
|
||||||
const {agent} = useSession()
|
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
return useMutation<void, Error, {did: string; skipOptimistic?: boolean}>({
|
return useMutation<void, Error, {did: string; skipOptimistic?: boolean}>({
|
||||||
mutationFn: async ({did}) => {
|
mutationFn: async ({did}) => {
|
||||||
await agent.unmute(did)
|
await getAgent().unmute(did)
|
||||||
},
|
},
|
||||||
onMutate(variables) {
|
onMutate(variables) {
|
||||||
if (!variables.skipOptimistic) {
|
if (!variables.skipOptimistic) {
|
||||||
|
@ -389,7 +383,7 @@ export function useProfileBlockMutationQueue(
|
||||||
}
|
}
|
||||||
|
|
||||||
function useProfileBlockMutation() {
|
function useProfileBlockMutation() {
|
||||||
const {agent, currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
return useMutation<
|
return useMutation<
|
||||||
{uri: string; cid: string},
|
{uri: string; cid: string},
|
||||||
|
@ -400,7 +394,7 @@ function useProfileBlockMutation() {
|
||||||
if (!currentAccount) {
|
if (!currentAccount) {
|
||||||
throw new Error('Not signed in')
|
throw new Error('Not signed in')
|
||||||
}
|
}
|
||||||
return await agent.app.bsky.graph.block.create(
|
return await getAgent().app.bsky.graph.block.create(
|
||||||
{repo: currentAccount.did},
|
{repo: currentAccount.did},
|
||||||
{subject: did, createdAt: new Date().toISOString()},
|
{subject: did, createdAt: new Date().toISOString()},
|
||||||
)
|
)
|
||||||
|
@ -434,7 +428,7 @@ function useProfileBlockMutation() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function useProfileUnblockMutation() {
|
function useProfileUnblockMutation() {
|
||||||
const {agent, currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
return useMutation<
|
return useMutation<
|
||||||
void,
|
void,
|
||||||
Error,
|
Error,
|
||||||
|
@ -445,7 +439,7 @@ function useProfileUnblockMutation() {
|
||||||
throw new Error('Not signed in')
|
throw new Error('Not signed in')
|
||||||
}
|
}
|
||||||
const {rkey} = new AtUri(blockUri)
|
const {rkey} = new AtUri(blockUri)
|
||||||
await agent.app.bsky.graph.block.delete({
|
await getAgent().app.bsky.graph.block.delete({
|
||||||
repo: currentAccount.did,
|
repo: currentAccount.did,
|
||||||
rkey,
|
rkey,
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,20 +1,19 @@
|
||||||
import {useQuery} from '@tanstack/react-query'
|
import {useQuery} from '@tanstack/react-query'
|
||||||
import {AtUri} from '@atproto/api'
|
import {AtUri} from '@atproto/api'
|
||||||
|
|
||||||
import {useSession} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
|
||||||
export const RQKEY = (uri: string) => ['resolved-uri', uri]
|
export const RQKEY = (uri: string) => ['resolved-uri', uri]
|
||||||
|
|
||||||
export function useResolveUriQuery(uri: string | undefined) {
|
export function useResolveUriQuery(uri: string | undefined) {
|
||||||
const {agent} = useSession()
|
|
||||||
return useQuery<{uri: string; did: string}, Error>({
|
return useQuery<{uri: string; did: string}, Error>({
|
||||||
staleTime: STALE.INFINITY,
|
staleTime: STALE.INFINITY,
|
||||||
queryKey: RQKEY(uri || ''),
|
queryKey: RQKEY(uri || ''),
|
||||||
async queryFn() {
|
async queryFn() {
|
||||||
const urip = new AtUri(uri || '')
|
const urip = new AtUri(uri || '')
|
||||||
if (!urip.host.startsWith('did:')) {
|
if (!urip.host.startsWith('did:')) {
|
||||||
const res = await agent.resolveHandle({handle: urip.host})
|
const res = await getAgent().resolveHandle({handle: urip.host})
|
||||||
urip.host = res.data.did
|
urip.host = res.data.did
|
||||||
}
|
}
|
||||||
return {did: urip.host, uri: urip.toString()}
|
return {did: urip.host, uri: urip.toString()}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import {AppBskyFeedSearchPosts} from '@atproto/api'
|
import {AppBskyFeedSearchPosts} from '@atproto/api'
|
||||||
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {useSession} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
|
|
||||||
const searchPostsQueryKey = ({query}: {query: string}) => [
|
const searchPostsQueryKey = ({query}: {query: string}) => [
|
||||||
'search-posts',
|
'search-posts',
|
||||||
|
@ -9,8 +9,6 @@ const searchPostsQueryKey = ({query}: {query: string}) => [
|
||||||
]
|
]
|
||||||
|
|
||||||
export function useSearchPostsQuery({query}: {query: string}) {
|
export function useSearchPostsQuery({query}: {query: string}) {
|
||||||
const {agent} = useSession()
|
|
||||||
|
|
||||||
return useInfiniteQuery<
|
return useInfiniteQuery<
|
||||||
AppBskyFeedSearchPosts.OutputSchema,
|
AppBskyFeedSearchPosts.OutputSchema,
|
||||||
Error,
|
Error,
|
||||||
|
@ -20,7 +18,7 @@ export function useSearchPostsQuery({query}: {query: string}) {
|
||||||
>({
|
>({
|
||||||
queryKey: searchPostsQueryKey({query}),
|
queryKey: searchPostsQueryKey({query}),
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const res = await agent.app.bsky.feed.searchPosts({
|
const res = await getAgent().app.bsky.feed.searchPosts({
|
||||||
q: query,
|
q: query,
|
||||||
limit: 25,
|
limit: 25,
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
||||||
import {AppBskyFeedGetSuggestedFeeds} from '@atproto/api'
|
import {AppBskyFeedGetSuggestedFeeds} from '@atproto/api'
|
||||||
|
|
||||||
import {useSession} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
|
||||||
export const suggestedFeedsQueryKey = ['suggestedFeeds']
|
export const suggestedFeedsQueryKey = ['suggestedFeeds']
|
||||||
|
|
||||||
export function useSuggestedFeedsQuery() {
|
export function useSuggestedFeedsQuery() {
|
||||||
const {agent} = useSession()
|
|
||||||
|
|
||||||
return useInfiniteQuery<
|
return useInfiniteQuery<
|
||||||
AppBskyFeedGetSuggestedFeeds.OutputSchema,
|
AppBskyFeedGetSuggestedFeeds.OutputSchema,
|
||||||
Error,
|
Error,
|
||||||
|
@ -19,7 +17,7 @@ export function useSuggestedFeedsQuery() {
|
||||||
staleTime: STALE.HOURS.ONE,
|
staleTime: STALE.HOURS.ONE,
|
||||||
queryKey: suggestedFeedsQueryKey,
|
queryKey: suggestedFeedsQueryKey,
|
||||||
queryFn: async ({pageParam}) => {
|
queryFn: async ({pageParam}) => {
|
||||||
const res = await agent.app.bsky.feed.getSuggestedFeeds({
|
const res = await getAgent().app.bsky.feed.getSuggestedFeeds({
|
||||||
limit: 10,
|
limit: 10,
|
||||||
cursor: pageParam,
|
cursor: pageParam,
|
||||||
})
|
})
|
||||||
|
|
|
@ -12,7 +12,7 @@ import {
|
||||||
QueryKey,
|
QueryKey,
|
||||||
} from '@tanstack/react-query'
|
} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {useSession} from '#/state/session'
|
import {useSession, getAgent} from '#/state/session'
|
||||||
import {useModerationOpts} from '#/state/queries/preferences'
|
import {useModerationOpts} from '#/state/queries/preferences'
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ const suggestedFollowsByActorQueryKey = (did: string) => [
|
||||||
]
|
]
|
||||||
|
|
||||||
export function useSuggestedFollowsQuery() {
|
export function useSuggestedFollowsQuery() {
|
||||||
const {agent, currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
const moderationOpts = useModerationOpts()
|
const moderationOpts = useModerationOpts()
|
||||||
|
|
||||||
return useInfiniteQuery<
|
return useInfiniteQuery<
|
||||||
|
@ -37,7 +37,7 @@ export function useSuggestedFollowsQuery() {
|
||||||
staleTime: STALE.HOURS.ONE,
|
staleTime: STALE.HOURS.ONE,
|
||||||
queryKey: suggestedFollowsQueryKey,
|
queryKey: suggestedFollowsQueryKey,
|
||||||
queryFn: async ({pageParam}) => {
|
queryFn: async ({pageParam}) => {
|
||||||
const res = await agent.app.bsky.actor.getSuggestions({
|
const res = await getAgent().app.bsky.actor.getSuggestions({
|
||||||
limit: 25,
|
limit: 25,
|
||||||
cursor: pageParam,
|
cursor: pageParam,
|
||||||
})
|
})
|
||||||
|
@ -73,12 +73,10 @@ export function useSuggestedFollowsQuery() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useSuggestedFollowsByActorQuery({did}: {did: string}) {
|
export function useSuggestedFollowsByActorQuery({did}: {did: string}) {
|
||||||
const {agent} = useSession()
|
|
||||||
|
|
||||||
return useQuery<AppBskyGraphGetSuggestedFollowsByActor.OutputSchema, Error>({
|
return useQuery<AppBskyGraphGetSuggestedFollowsByActor.OutputSchema, Error>({
|
||||||
queryKey: suggestedFollowsByActorQueryKey(did),
|
queryKey: suggestedFollowsByActorQueryKey(did),
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const res = await agent.app.bsky.graph.getSuggestedFollowsByActor({
|
const res = await getAgent().app.bsky.graph.getSuggestedFollowsByActor({
|
||||||
actor: did,
|
actor: did,
|
||||||
})
|
})
|
||||||
return res.data
|
return res.data
|
||||||
|
@ -87,7 +85,6 @@ export function useSuggestedFollowsByActorQuery({did}: {did: string}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useGetSuggestedFollowersByActor() {
|
export function useGetSuggestedFollowersByActor() {
|
||||||
const {agent} = useSession()
|
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
return React.useCallback(
|
return React.useCallback(
|
||||||
|
@ -96,15 +93,16 @@ export function useGetSuggestedFollowersByActor() {
|
||||||
staleTime: 60 * 1000,
|
staleTime: 60 * 1000,
|
||||||
queryKey: suggestedFollowsByActorQueryKey(actor),
|
queryKey: suggestedFollowsByActorQueryKey(actor),
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const res = await agent.app.bsky.graph.getSuggestedFollowsByActor({
|
const res =
|
||||||
actor: actor,
|
await getAgent().app.bsky.graph.getSuggestedFollowsByActor({
|
||||||
})
|
actor: actor,
|
||||||
|
})
|
||||||
return res.data
|
return res.data
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
return res
|
return res
|
||||||
},
|
},
|
||||||
[agent, queryClient],
|
[queryClient],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {BskyAgent, AtpPersistSessionHandler} from '@atproto/api'
|
import {BskyAgent, AtpPersistSessionHandler} from '@atproto/api'
|
||||||
|
import {useQueryClient} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {networkRetry} from '#/lib/async/retry'
|
import {networkRetry} from '#/lib/async/retry'
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
|
@ -8,10 +9,15 @@ import {PUBLIC_BSKY_AGENT} from '#/state/queries'
|
||||||
import {IS_PROD} from '#/lib/constants'
|
import {IS_PROD} from '#/lib/constants'
|
||||||
import {emitSessionLoaded, emitSessionDropped} from '../events'
|
import {emitSessionLoaded, emitSessionDropped} from '../events'
|
||||||
|
|
||||||
|
let __globalAgent: BskyAgent = PUBLIC_BSKY_AGENT
|
||||||
|
|
||||||
|
export function getAgent() {
|
||||||
|
return __globalAgent
|
||||||
|
}
|
||||||
|
|
||||||
export type SessionAccount = persisted.PersistedAccount
|
export type SessionAccount = persisted.PersistedAccount
|
||||||
|
|
||||||
export type SessionState = {
|
export type SessionState = {
|
||||||
agent: BskyAgent
|
|
||||||
isInitialLoad: boolean
|
isInitialLoad: boolean
|
||||||
isSwitchingAccounts: boolean
|
isSwitchingAccounts: boolean
|
||||||
accounts: SessionAccount[]
|
accounts: SessionAccount[]
|
||||||
|
@ -48,7 +54,6 @@ export type ApiContext = {
|
||||||
}
|
}
|
||||||
|
|
||||||
const StateContext = React.createContext<StateContext>({
|
const StateContext = React.createContext<StateContext>({
|
||||||
agent: PUBLIC_BSKY_AGENT,
|
|
||||||
isInitialLoad: true,
|
isInitialLoad: true,
|
||||||
isSwitchingAccounts: false,
|
isSwitchingAccounts: false,
|
||||||
accounts: [],
|
accounts: [],
|
||||||
|
@ -110,9 +115,9 @@ function createPersistSessionHandler(
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Provider({children}: React.PropsWithChildren<{}>) {
|
export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||||
|
const queryClient = useQueryClient()
|
||||||
const isDirty = React.useRef(false)
|
const isDirty = React.useRef(false)
|
||||||
const [state, setState] = React.useState<SessionState>({
|
const [state, setState] = React.useState<SessionState>({
|
||||||
agent: PUBLIC_BSKY_AGENT,
|
|
||||||
isInitialLoad: true, // try to resume the session first
|
isInitialLoad: true, // try to resume the session first
|
||||||
isSwitchingAccounts: false,
|
isSwitchingAccounts: false,
|
||||||
accounts: persisted.get('session').accounts,
|
accounts: persisted.get('session').accounts,
|
||||||
|
@ -180,7 +185,8 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
setState(s => ({...s, agent}))
|
__globalAgent = agent
|
||||||
|
queryClient.clear()
|
||||||
upsertAccount(account)
|
upsertAccount(account)
|
||||||
emitSessionLoaded(account, agent)
|
emitSessionLoaded(account, agent)
|
||||||
|
|
||||||
|
@ -193,7 +199,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||||
logger.DebugContext.session,
|
logger.DebugContext.session,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
[upsertAccount],
|
[upsertAccount, queryClient],
|
||||||
)
|
)
|
||||||
|
|
||||||
const login = React.useCallback<ApiContext['login']>(
|
const login = React.useCallback<ApiContext['login']>(
|
||||||
|
@ -231,7 +237,8 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
setState(s => ({...s, agent}))
|
__globalAgent = agent
|
||||||
|
queryClient.clear()
|
||||||
upsertAccount(account)
|
upsertAccount(account)
|
||||||
emitSessionLoaded(account, agent)
|
emitSessionLoaded(account, agent)
|
||||||
|
|
||||||
|
@ -244,7 +251,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||||
logger.DebugContext.session,
|
logger.DebugContext.session,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
[upsertAccount],
|
[upsertAccount, queryClient],
|
||||||
)
|
)
|
||||||
|
|
||||||
const logout = React.useCallback<ApiContext['logout']>(async () => {
|
const logout = React.useCallback<ApiContext['logout']>(async () => {
|
||||||
|
@ -308,11 +315,12 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||||
accessJwt: agent.session.accessJwt,
|
accessJwt: agent.session.accessJwt,
|
||||||
}
|
}
|
||||||
|
|
||||||
setState(s => ({...s, agent}))
|
__globalAgent = agent
|
||||||
|
queryClient.clear()
|
||||||
upsertAccount(freshAccount)
|
upsertAccount(freshAccount)
|
||||||
emitSessionLoaded(freshAccount, agent)
|
emitSessionLoaded(freshAccount, agent)
|
||||||
},
|
},
|
||||||
[upsertAccount],
|
[upsertAccount, queryClient],
|
||||||
)
|
)
|
||||||
|
|
||||||
const resumeSession = React.useCallback<ApiContext['resumeSession']>(
|
const resumeSession = React.useCallback<ApiContext['resumeSession']>(
|
||||||
|
@ -399,12 +407,13 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||||
* back to the sign-in page.
|
* back to the sign-in page.
|
||||||
*/
|
*/
|
||||||
const clearCurrentAccount = React.useCallback(() => {
|
const clearCurrentAccount = React.useCallback(() => {
|
||||||
|
__globalAgent = PUBLIC_BSKY_AGENT
|
||||||
|
queryClient.clear()
|
||||||
setStateAndPersist(s => ({
|
setStateAndPersist(s => ({
|
||||||
...s,
|
...s,
|
||||||
agent: PUBLIC_BSKY_AGENT,
|
|
||||||
currentAccount: undefined,
|
currentAccount: undefined,
|
||||||
}))
|
}))
|
||||||
}, [setStateAndPersist])
|
}, [setStateAndPersist, queryClient])
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (isDirty.current) {
|
if (isDirty.current) {
|
||||||
|
|
|
@ -56,7 +56,7 @@ import {
|
||||||
useLanguagePrefsApi,
|
useLanguagePrefsApi,
|
||||||
toPostLanguages,
|
toPostLanguages,
|
||||||
} from '#/state/preferences/languages'
|
} from '#/state/preferences/languages'
|
||||||
import {useSession} from '#/state/session'
|
import {useSession, getAgent} from '#/state/session'
|
||||||
import {useProfileQuery} from '#/state/queries/profile'
|
import {useProfileQuery} from '#/state/queries/profile'
|
||||||
import {useComposerControls} from '#/state/shell/composer'
|
import {useComposerControls} from '#/state/shell/composer'
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ export const ComposePost = observer(function ComposePost({
|
||||||
quote: initQuote,
|
quote: initQuote,
|
||||||
mention: initMention,
|
mention: initMention,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const {agent, currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
const {data: currentProfile} = useProfileQuery({did: currentAccount!.did})
|
const {data: currentProfile} = useProfileQuery({did: currentAccount!.did})
|
||||||
const {activeModals} = useModals()
|
const {activeModals} = useModals()
|
||||||
const {openModal, closeModal} = useModalControls()
|
const {openModal, closeModal} = useModalControls()
|
||||||
|
@ -209,7 +209,7 @@ export const ComposePost = observer(function ComposePost({
|
||||||
setIsProcessing(true)
|
setIsProcessing(true)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await apilib.post(agent, {
|
await apilib.post(getAgent(), {
|
||||||
rawText: richtext.text,
|
rawText: richtext.text,
|
||||||
replyTo: replyTo?.uri,
|
replyTo: replyTo?.uri,
|
||||||
images: gallery.images,
|
images: gallery.images,
|
||||||
|
|
|
@ -16,7 +16,7 @@ import {
|
||||||
import {ComposerOpts} from 'state/shell/composer'
|
import {ComposerOpts} from 'state/shell/composer'
|
||||||
import {POST_IMG_MAX} from 'lib/constants'
|
import {POST_IMG_MAX} from 'lib/constants'
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
import {useSession} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
import {useGetPost} from '#/state/queries/post'
|
import {useGetPost} from '#/state/queries/post'
|
||||||
|
|
||||||
export function useExternalLinkFetch({
|
export function useExternalLinkFetch({
|
||||||
|
@ -24,7 +24,6 @@ export function useExternalLinkFetch({
|
||||||
}: {
|
}: {
|
||||||
setQuote: (opts: ComposerOpts['quote']) => void
|
setQuote: (opts: ComposerOpts['quote']) => void
|
||||||
}) {
|
}) {
|
||||||
const {agent} = useSession()
|
|
||||||
const [extLink, setExtLink] = useState<apilib.ExternalEmbedDraft | undefined>(
|
const [extLink, setExtLink] = useState<apilib.ExternalEmbedDraft | undefined>(
|
||||||
undefined,
|
undefined,
|
||||||
)
|
)
|
||||||
|
@ -56,7 +55,7 @@ export function useExternalLinkFetch({
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
} else if (isBskyCustomFeedUrl(extLink.uri)) {
|
} else if (isBskyCustomFeedUrl(extLink.uri)) {
|
||||||
getFeedAsEmbed(agent, extLink.uri).then(
|
getFeedAsEmbed(getAgent(), extLink.uri).then(
|
||||||
({embed, meta}) => {
|
({embed, meta}) => {
|
||||||
if (aborted) {
|
if (aborted) {
|
||||||
return
|
return
|
||||||
|
@ -74,7 +73,7 @@ export function useExternalLinkFetch({
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
} else if (isBskyListUrl(extLink.uri)) {
|
} else if (isBskyListUrl(extLink.uri)) {
|
||||||
getListAsEmbed(agent, extLink.uri).then(
|
getListAsEmbed(getAgent(), extLink.uri).then(
|
||||||
({embed, meta}) => {
|
({embed, meta}) => {
|
||||||
if (aborted) {
|
if (aborted) {
|
||||||
return
|
return
|
||||||
|
@ -92,7 +91,7 @@ export function useExternalLinkFetch({
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
getLinkMeta(agent, extLink.uri).then(meta => {
|
getLinkMeta(getAgent(), extLink.uri).then(meta => {
|
||||||
if (aborted) {
|
if (aborted) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -134,7 +133,7 @@ export function useExternalLinkFetch({
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return cleanup
|
return cleanup
|
||||||
}, [agent, extLink, setQuote, getPost])
|
}, [extLink, setQuote, getPost])
|
||||||
|
|
||||||
return {extLink, setExtLink}
|
return {extLink, setExtLink}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import {cleanError} from 'lib/strings/errors'
|
||||||
import {Trans, msg} from '@lingui/macro'
|
import {Trans, msg} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
import {useModalControls} from '#/state/modals'
|
import {useModalControls} from '#/state/modals'
|
||||||
import {useSession, useSessionApi} from '#/state/session'
|
import {useSession, useSessionApi, getAgent} from '#/state/session'
|
||||||
|
|
||||||
enum Stages {
|
enum Stages {
|
||||||
InputEmail,
|
InputEmail,
|
||||||
|
@ -25,7 +25,7 @@ export const snapPoints = ['90%']
|
||||||
|
|
||||||
export function Component() {
|
export function Component() {
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
const {agent, currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
const {updateCurrentAccount} = useSessionApi()
|
const {updateCurrentAccount} = useSessionApi()
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const [stage, setStage] = useState<Stages>(Stages.InputEmail)
|
const [stage, setStage] = useState<Stages>(Stages.InputEmail)
|
||||||
|
@ -44,11 +44,11 @@ export function Component() {
|
||||||
setError('')
|
setError('')
|
||||||
setIsProcessing(true)
|
setIsProcessing(true)
|
||||||
try {
|
try {
|
||||||
const res = await agent.com.atproto.server.requestEmailUpdate()
|
const res = await getAgent().com.atproto.server.requestEmailUpdate()
|
||||||
if (res.data.tokenRequired) {
|
if (res.data.tokenRequired) {
|
||||||
setStage(Stages.ConfirmCode)
|
setStage(Stages.ConfirmCode)
|
||||||
} else {
|
} else {
|
||||||
await agent.com.atproto.server.updateEmail({email: email.trim()})
|
await getAgent().com.atproto.server.updateEmail({email: email.trim()})
|
||||||
updateCurrentAccount({
|
updateCurrentAccount({
|
||||||
email: email.trim(),
|
email: email.trim(),
|
||||||
emailConfirmed: false,
|
emailConfirmed: false,
|
||||||
|
@ -77,7 +77,7 @@ export function Component() {
|
||||||
setError('')
|
setError('')
|
||||||
setIsProcessing(true)
|
setIsProcessing(true)
|
||||||
try {
|
try {
|
||||||
await agent.com.atproto.server.updateEmail({
|
await getAgent().com.atproto.server.updateEmail({
|
||||||
email: email.trim(),
|
email: email.trim(),
|
||||||
token: confirmationCode.trim(),
|
token: confirmationCode.trim(),
|
||||||
})
|
})
|
||||||
|
|
|
@ -26,19 +26,24 @@ import {useLingui} from '@lingui/react'
|
||||||
import {useModalControls} from '#/state/modals'
|
import {useModalControls} from '#/state/modals'
|
||||||
import {useServiceQuery} from '#/state/queries/service'
|
import {useServiceQuery} from '#/state/queries/service'
|
||||||
import {useUpdateHandleMutation, useFetchDid} from '#/state/queries/handle'
|
import {useUpdateHandleMutation, useFetchDid} from '#/state/queries/handle'
|
||||||
import {useSession, useSessionApi, SessionAccount} from '#/state/session'
|
import {
|
||||||
|
useSession,
|
||||||
|
useSessionApi,
|
||||||
|
SessionAccount,
|
||||||
|
getAgent,
|
||||||
|
} from '#/state/session'
|
||||||
|
|
||||||
export const snapPoints = ['100%']
|
export const snapPoints = ['100%']
|
||||||
|
|
||||||
export type Props = {onChanged: () => void}
|
export type Props = {onChanged: () => void}
|
||||||
|
|
||||||
export function Component(props: Props) {
|
export function Component(props: Props) {
|
||||||
const {agent, currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
const {
|
const {
|
||||||
isLoading,
|
isLoading,
|
||||||
data: serviceInfo,
|
data: serviceInfo,
|
||||||
error: serviceInfoError,
|
error: serviceInfoError,
|
||||||
} = useServiceQuery(agent.service.toString())
|
} = useServiceQuery(getAgent().service.toString())
|
||||||
|
|
||||||
return isLoading || !currentAccount ? (
|
return isLoading || !currentAccount ? (
|
||||||
<View style={{padding: 18}}>
|
<View style={{padding: 18}}>
|
||||||
|
|
|
@ -19,14 +19,14 @@ import {resetToTab} from '../../../Navigation'
|
||||||
import {Trans, msg} from '@lingui/macro'
|
import {Trans, msg} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
import {useModalControls} from '#/state/modals'
|
import {useModalControls} from '#/state/modals'
|
||||||
import {useSession, useSessionApi} from '#/state/session'
|
import {useSession, useSessionApi, getAgent} from '#/state/session'
|
||||||
|
|
||||||
export const snapPoints = ['60%']
|
export const snapPoints = ['60%']
|
||||||
|
|
||||||
export function Component({}: {}) {
|
export function Component({}: {}) {
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
const theme = useTheme()
|
const theme = useTheme()
|
||||||
const {agent, currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
const {clearCurrentAccount, removeAccount} = useSessionApi()
|
const {clearCurrentAccount, removeAccount} = useSessionApi()
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const {closeModal} = useModalControls()
|
const {closeModal} = useModalControls()
|
||||||
|
@ -40,7 +40,7 @@ export function Component({}: {}) {
|
||||||
setError('')
|
setError('')
|
||||||
setIsProcessing(true)
|
setIsProcessing(true)
|
||||||
try {
|
try {
|
||||||
await agent.com.atproto.server.requestAccountDelete()
|
await getAgent().com.atproto.server.requestAccountDelete()
|
||||||
setIsEmailSent(true)
|
setIsEmailSent(true)
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
setError(cleanError(e))
|
setError(cleanError(e))
|
||||||
|
@ -57,7 +57,7 @@ export function Component({}: {}) {
|
||||||
const token = confirmCode.replace(/\s/g, '')
|
const token = confirmCode.replace(/\s/g, '')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await agent.com.atproto.server.deleteAccount({
|
await getAgent().com.atproto.server.deleteAccount({
|
||||||
did: currentAccount.did,
|
did: currentAccount.did,
|
||||||
password,
|
password,
|
||||||
token,
|
token,
|
||||||
|
|
|
@ -21,7 +21,7 @@ import {cleanError} from 'lib/strings/errors'
|
||||||
import {Trans, msg} from '@lingui/macro'
|
import {Trans, msg} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
import {useModalControls} from '#/state/modals'
|
import {useModalControls} from '#/state/modals'
|
||||||
import {useSession, useSessionApi} from '#/state/session'
|
import {useSession, useSessionApi, getAgent} from '#/state/session'
|
||||||
|
|
||||||
export const snapPoints = ['90%']
|
export const snapPoints = ['90%']
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ enum Stages {
|
||||||
|
|
||||||
export function Component({showReminder}: {showReminder?: boolean}) {
|
export function Component({showReminder}: {showReminder?: boolean}) {
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
const {agent, currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
const {updateCurrentAccount} = useSessionApi()
|
const {updateCurrentAccount} = useSessionApi()
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const [stage, setStage] = useState<Stages>(
|
const [stage, setStage] = useState<Stages>(
|
||||||
|
@ -49,7 +49,7 @@ export function Component({showReminder}: {showReminder?: boolean}) {
|
||||||
setError('')
|
setError('')
|
||||||
setIsProcessing(true)
|
setIsProcessing(true)
|
||||||
try {
|
try {
|
||||||
await agent.com.atproto.server.requestEmailConfirmation()
|
await getAgent().com.atproto.server.requestEmailConfirmation()
|
||||||
setStage(Stages.ConfirmCode)
|
setStage(Stages.ConfirmCode)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setError(cleanError(String(e)))
|
setError(cleanError(String(e)))
|
||||||
|
@ -62,7 +62,7 @@ export function Component({showReminder}: {showReminder?: boolean}) {
|
||||||
setError('')
|
setError('')
|
||||||
setIsProcessing(true)
|
setIsProcessing(true)
|
||||||
try {
|
try {
|
||||||
await agent.com.atproto.server.confirmEmail({
|
await getAgent().com.atproto.server.confirmEmail({
|
||||||
email: (currentAccount?.email || '').trim(),
|
email: (currentAccount?.email || '').trim(),
|
||||||
token: confirmationCode.trim(),
|
token: confirmationCode.trim(),
|
||||||
})
|
})
|
||||||
|
|
|
@ -16,7 +16,7 @@ import {CollectionId} from './types'
|
||||||
import {Trans, msg} from '@lingui/macro'
|
import {Trans, msg} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
import {useModalControls} from '#/state/modals'
|
import {useModalControls} from '#/state/modals'
|
||||||
import {useSession} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
|
|
||||||
const DMCA_LINK = 'https://blueskyweb.xyz/support/copyright'
|
const DMCA_LINK = 'https://blueskyweb.xyz/support/copyright'
|
||||||
|
|
||||||
|
@ -39,7 +39,6 @@ type ReportComponentProps =
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Component(content: ReportComponentProps) {
|
export function Component(content: ReportComponentProps) {
|
||||||
const {agent} = useSession()
|
|
||||||
const {closeModal} = useModalControls()
|
const {closeModal} = useModalControls()
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
const {isMobile} = useWebMediaQueries()
|
const {isMobile} = useWebMediaQueries()
|
||||||
|
@ -70,7 +69,7 @@ export function Component(content: ReportComponentProps) {
|
||||||
const $type = !isAccountReport
|
const $type = !isAccountReport
|
||||||
? 'com.atproto.repo.strongRef'
|
? 'com.atproto.repo.strongRef'
|
||||||
: 'com.atproto.admin.defs#repoRef'
|
: 'com.atproto.admin.defs#repoRef'
|
||||||
await agent.createModerationReport({
|
await getAgent().createModerationReport({
|
||||||
reasonType: issue,
|
reasonType: issue,
|
||||||
subject: {
|
subject: {
|
||||||
$type,
|
$type,
|
||||||
|
|
|
@ -55,7 +55,12 @@ import {
|
||||||
useRequireAltTextEnabled,
|
useRequireAltTextEnabled,
|
||||||
useSetRequireAltTextEnabled,
|
useSetRequireAltTextEnabled,
|
||||||
} from '#/state/preferences'
|
} from '#/state/preferences'
|
||||||
import {useSession, useSessionApi, SessionAccount} from '#/state/session'
|
import {
|
||||||
|
useSession,
|
||||||
|
useSessionApi,
|
||||||
|
SessionAccount,
|
||||||
|
getAgent,
|
||||||
|
} from '#/state/session'
|
||||||
import {useProfileQuery} from '#/state/queries/profile'
|
import {useProfileQuery} from '#/state/queries/profile'
|
||||||
import {useClearPreferencesMutation} from '#/state/queries/preferences'
|
import {useClearPreferencesMutation} from '#/state/queries/preferences'
|
||||||
import {useInviteCodesQuery} from '#/state/queries/invites'
|
import {useInviteCodesQuery} from '#/state/queries/invites'
|
||||||
|
@ -148,9 +153,11 @@ export const SettingsScreen = withAuthRequired(function Settings({}: Props) {
|
||||||
const {isMobile} = useWebMediaQueries()
|
const {isMobile} = useWebMediaQueries()
|
||||||
const {screen, track} = useAnalytics()
|
const {screen, track} = useAnalytics()
|
||||||
const {openModal} = useModalControls()
|
const {openModal} = useModalControls()
|
||||||
const {isSwitchingAccounts, accounts, currentAccount, agent} = useSession()
|
const {isSwitchingAccounts, accounts, currentAccount} = useSession()
|
||||||
const {clearCurrentAccount} = useSessionApi()
|
const {clearCurrentAccount} = useSessionApi()
|
||||||
const [debugHeaderEnabled, toggleDebugHeader] = useDebugHeaderSetting(agent)
|
const [debugHeaderEnabled, toggleDebugHeader] = useDebugHeaderSetting(
|
||||||
|
getAgent(),
|
||||||
|
)
|
||||||
const {mutate: clearPreferences} = useClearPreferencesMutation()
|
const {mutate: clearPreferences} = useClearPreferencesMutation()
|
||||||
const {data: invites} = useInviteCodesQuery()
|
const {data: invites} = useInviteCodesQuery()
|
||||||
const invitesAvailable = invites?.available?.length ?? 0
|
const invitesAvailable = invites?.available?.length ?? 0
|
||||||
|
|
Loading…
Reference in New Issue