Extract query key roots to constants (#3404)
* Extract query key roots to constants * Dedupe labelers-detailed-info * Align namingzio/stable
parent
b26abf212e
commit
b783745b2e
|
@ -11,7 +11,8 @@ import {
|
||||||
import {isNative} from '#/platform/detection'
|
import {isNative} from '#/platform/detection'
|
||||||
|
|
||||||
// any query keys in this array will be persisted to AsyncStorage
|
// any query keys in this array will be persisted to AsyncStorage
|
||||||
const STORED_CACHE_QUERY_KEYS = ['labelers-detailed-info']
|
export const labelersDetailedInfoQueryKeyRoot = 'labelers-detailed-info'
|
||||||
|
const STORED_CACHE_QUERY_KEY_ROOTS = [labelersDetailedInfoQueryKeyRoot]
|
||||||
|
|
||||||
focusManager.setEventListener(onFocus => {
|
focusManager.setEventListener(onFocus => {
|
||||||
if (isNative) {
|
if (isNative) {
|
||||||
|
@ -65,7 +66,7 @@ const dehydrateOptions: PersistQueryClientProviderProps['persistOptions']['dehyd
|
||||||
{
|
{
|
||||||
shouldDehydrateMutation: (_: any) => false,
|
shouldDehydrateMutation: (_: any) => false,
|
||||||
shouldDehydrateQuery: query => {
|
shouldDehydrateQuery: query => {
|
||||||
return STORED_CACHE_QUERY_KEYS.includes(String(query.queryKey[0]))
|
return STORED_CACHE_QUERY_KEY_ROOTS.includes(String(query.queryKey[0]))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,21 +1,22 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {AppBskyActorDefs, ModerationOpts, moderateProfile} from '@atproto/api'
|
import {AppBskyActorDefs, moderateProfile, ModerationOpts} from '@atproto/api'
|
||||||
import {useQuery, useQueryClient} from '@tanstack/react-query'
|
import {useQuery, useQueryClient} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {logger} from '#/logger'
|
|
||||||
import {getAgent} from '#/state/session'
|
|
||||||
import {useMyFollowsQuery} from '#/state/queries/my-follows'
|
|
||||||
import {STALE} from '#/state/queries'
|
|
||||||
import {DEFAULT_LOGGED_OUT_PREFERENCES, useModerationOpts} from './preferences'
|
|
||||||
import {isInvalidHandle} from '#/lib/strings/handles'
|
|
||||||
import {isJustAMute} from '#/lib/moderation'
|
import {isJustAMute} from '#/lib/moderation'
|
||||||
|
import {isInvalidHandle} from '#/lib/strings/handles'
|
||||||
|
import {logger} from '#/logger'
|
||||||
|
import {STALE} from '#/state/queries'
|
||||||
|
import {useMyFollowsQuery} from '#/state/queries/my-follows'
|
||||||
|
import {getAgent} from '#/state/session'
|
||||||
|
import {DEFAULT_LOGGED_OUT_PREFERENCES, useModerationOpts} from './preferences'
|
||||||
|
|
||||||
const DEFAULT_MOD_OPTS = {
|
const DEFAULT_MOD_OPTS = {
|
||||||
userDid: undefined,
|
userDid: undefined,
|
||||||
prefs: DEFAULT_LOGGED_OUT_PREFERENCES.moderationPrefs,
|
prefs: DEFAULT_LOGGED_OUT_PREFERENCES.moderationPrefs,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const RQKEY = (prefix: string) => ['actor-autocomplete', prefix]
|
const RQKEY_ROOT = 'actor-autocomplete'
|
||||||
|
export const RQKEY = (prefix: string) => [RQKEY_ROOT, prefix]
|
||||||
|
|
||||||
export function useActorAutocompleteQuery(prefix: string) {
|
export function useActorAutocompleteQuery(prefix: string) {
|
||||||
const {data: follows, isFetching} = useMyFollowsQuery()
|
const {data: follows, isFetching} = useMyFollowsQuery()
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import {AppBskyActorDefs} from '@atproto/api'
|
import {AppBskyActorDefs} from '@atproto/api'
|
||||||
import {QueryClient, useQuery} from '@tanstack/react-query'
|
import {QueryClient, useQuery} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {getAgent} from '#/state/session'
|
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
import {getAgent} from '#/state/session'
|
||||||
|
|
||||||
export const RQKEY = (prefix: string) => ['actor-search', prefix]
|
const RQKEY_ROOT = 'actor-search'
|
||||||
|
export const RQKEY = (prefix: string) => [RQKEY_ROOT, prefix]
|
||||||
|
|
||||||
export function useActorSearch(prefix: string) {
|
export function useActorSearch(prefix: string) {
|
||||||
return useQuery<AppBskyActorDefs.ProfileView[]>({
|
return useQuery<AppBskyActorDefs.ProfileView[]>({
|
||||||
|
@ -26,7 +27,7 @@ export function* findAllProfilesInQueryData(
|
||||||
) {
|
) {
|
||||||
const queryDatas = queryClient.getQueriesData<AppBskyActorDefs.ProfileView[]>(
|
const queryDatas = queryClient.getQueriesData<AppBskyActorDefs.ProfileView[]>(
|
||||||
{
|
{
|
||||||
queryKey: ['actor-search'],
|
queryKey: [RQKEY_ROOT],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
for (const [_queryKey, queryData] of queryDatas) {
|
for (const [_queryKey, queryData] of queryDatas) {
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import {ComAtprotoServerCreateAppPassword} from '@atproto/api'
|
import {ComAtprotoServerCreateAppPassword} from '@atproto/api'
|
||||||
import {useQuery, useQueryClient, useMutation} from '@tanstack/react-query'
|
import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
import {getAgent} from '../session'
|
import {getAgent} from '../session'
|
||||||
|
|
||||||
export const RQKEY = () => ['app-passwords']
|
const RQKEY_ROOT = 'app-passwords'
|
||||||
|
export const RQKEY = () => [RQKEY_ROOT]
|
||||||
|
|
||||||
export function useAppPasswordsQuery() {
|
export function useAppPasswordsQuery() {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
|
|
|
@ -1,24 +1,24 @@
|
||||||
import {
|
import {
|
||||||
useQuery,
|
|
||||||
useInfiniteQuery,
|
|
||||||
InfiniteData,
|
|
||||||
QueryKey,
|
|
||||||
useMutation,
|
|
||||||
} from '@tanstack/react-query'
|
|
||||||
import {
|
|
||||||
AtUri,
|
|
||||||
RichText,
|
|
||||||
AppBskyFeedDefs,
|
AppBskyFeedDefs,
|
||||||
AppBskyGraphDefs,
|
AppBskyGraphDefs,
|
||||||
AppBskyUnspeccedGetPopularFeedGenerators,
|
AppBskyUnspeccedGetPopularFeedGenerators,
|
||||||
|
AtUri,
|
||||||
|
RichText,
|
||||||
} from '@atproto/api'
|
} from '@atproto/api'
|
||||||
|
import {
|
||||||
|
InfiniteData,
|
||||||
|
QueryKey,
|
||||||
|
useInfiniteQuery,
|
||||||
|
useMutation,
|
||||||
|
useQuery,
|
||||||
|
} from '@tanstack/react-query'
|
||||||
|
|
||||||
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 {getAgent} from '#/state/session'
|
|
||||||
import {usePreferencesQuery} from '#/state/queries/preferences'
|
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
import {usePreferencesQuery} from '#/state/queries/preferences'
|
||||||
|
import {getAgent} from '#/state/session'
|
||||||
|
import {router} from '#/routes'
|
||||||
|
|
||||||
export type FeedSourceFeedInfo = {
|
export type FeedSourceFeedInfo = {
|
||||||
type: 'feed'
|
type: 'feed'
|
||||||
|
@ -56,8 +56,9 @@ export type FeedSourceListInfo = {
|
||||||
|
|
||||||
export type FeedSourceInfo = FeedSourceFeedInfo | FeedSourceListInfo
|
export type FeedSourceInfo = FeedSourceFeedInfo | FeedSourceListInfo
|
||||||
|
|
||||||
|
const feedSourceInfoQueryKeyRoot = 'getFeedSourceInfo'
|
||||||
export const feedSourceInfoQueryKey = ({uri}: {uri: string}) => [
|
export const feedSourceInfoQueryKey = ({uri}: {uri: string}) => [
|
||||||
'getFeedSourceInfo',
|
feedSourceInfoQueryKeyRoot,
|
||||||
uri,
|
uri,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -216,6 +217,8 @@ const FOLLOWING_FEED_STUB: FeedSourceInfo = {
|
||||||
likeUri: '',
|
likeUri: '',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const pinnedFeedInfosQueryKeyRoot = 'pinnedFeedsInfos'
|
||||||
|
|
||||||
export function usePinnedFeedsInfos() {
|
export function usePinnedFeedsInfos() {
|
||||||
const {data: preferences, isLoading: isLoadingPrefs} = usePreferencesQuery()
|
const {data: preferences, isLoading: isLoadingPrefs} = usePreferencesQuery()
|
||||||
const pinnedUris = preferences?.feeds?.pinned ?? []
|
const pinnedUris = preferences?.feeds?.pinned ?? []
|
||||||
|
@ -223,7 +226,7 @@ export function usePinnedFeedsInfos() {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
staleTime: STALE.INFINITY,
|
staleTime: STALE.INFINITY,
|
||||||
enabled: !isLoadingPrefs,
|
enabled: !isLoadingPrefs,
|
||||||
queryKey: ['pinnedFeedsInfos', pinnedUris.join(',')],
|
queryKey: [pinnedFeedInfosQueryKeyRoot, pinnedUris.join(',')],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
let resolved = new Map()
|
let resolved = new Map()
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {useQueryClient, useMutation} from '@tanstack/react-query'
|
import {useMutation, useQueryClient} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {getAgent} from '#/state/session'
|
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
import {getAgent} from '#/state/session'
|
||||||
|
|
||||||
const fetchHandleQueryKey = (handleOrDid: string) => ['handle', handleOrDid]
|
const handleQueryKeyRoot = 'handle'
|
||||||
const fetchDidQueryKey = (handleOrDid: string) => ['did', handleOrDid]
|
const fetchHandleQueryKey = (handleOrDid: string) => [
|
||||||
|
handleQueryKeyRoot,
|
||||||
|
handleOrDid,
|
||||||
|
]
|
||||||
|
const didQueryKeyRoot = 'did'
|
||||||
|
const fetchDidQueryKey = (handleOrDid: string) => [didQueryKeyRoot, handleOrDid]
|
||||||
|
|
||||||
export function useFetchHandle() {
|
export function useFetchHandle() {
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
import {ComAtprotoServerDefs} from '@atproto/api'
|
import {ComAtprotoServerDefs} from '@atproto/api'
|
||||||
import {useQuery} from '@tanstack/react-query'
|
import {useQuery} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {getAgent} from '#/state/session'
|
|
||||||
import {STALE} from '#/state/queries'
|
|
||||||
import {cleanError} from '#/lib/strings/errors'
|
import {cleanError} from '#/lib/strings/errors'
|
||||||
|
import {STALE} from '#/state/queries'
|
||||||
|
import {getAgent} from '#/state/session'
|
||||||
|
|
||||||
function isInviteAvailable(invite: ComAtprotoServerDefs.InviteCode): boolean {
|
function isInviteAvailable(invite: ComAtprotoServerDefs.InviteCode): boolean {
|
||||||
return invite.available - invite.uses.length > 0 && !invite.disabled
|
return invite.available - invite.uses.length > 0 && !invite.disabled
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const inviteCodesQueryKeyRoot = 'inviteCodes'
|
||||||
|
|
||||||
export type InviteCodesQueryResponse = Exclude<
|
export type InviteCodesQueryResponse = Exclude<
|
||||||
ReturnType<typeof useInviteCodesQuery>['data'],
|
ReturnType<typeof useInviteCodesQuery>['data'],
|
||||||
undefined
|
undefined
|
||||||
|
@ -16,7 +18,7 @@ export type InviteCodesQueryResponse = Exclude<
|
||||||
export function useInviteCodesQuery() {
|
export function useInviteCodesQuery() {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
staleTime: STALE.MINUTES.FIVE,
|
staleTime: STALE.MINUTES.FIVE,
|
||||||
queryKey: ['inviteCodes'],
|
queryKey: [inviteCodesQueryKeyRoot],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const res = await getAgent()
|
const res = await getAgent()
|
||||||
.com.atproto.server.getAccountInviteCodes({})
|
.com.atproto.server.getAccountInviteCodes({})
|
||||||
|
|
|
@ -2,17 +2,25 @@ import {AppBskyLabelerDefs} from '@atproto/api'
|
||||||
import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'
|
import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'
|
||||||
import {z} from 'zod'
|
import {z} from 'zod'
|
||||||
|
|
||||||
|
import {labelersDetailedInfoQueryKeyRoot} from '#/lib/react-query'
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
import {preferencesQueryKey} from '#/state/queries/preferences'
|
import {preferencesQueryKey} from '#/state/queries/preferences'
|
||||||
import {getAgent} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
|
|
||||||
export const labelerInfoQueryKey = (did: string) => ['labeler-info', did]
|
const labelerInfoQueryKeyRoot = 'labeler-info'
|
||||||
|
export const labelerInfoQueryKey = (did: string) => [
|
||||||
|
labelerInfoQueryKeyRoot,
|
||||||
|
did,
|
||||||
|
]
|
||||||
|
|
||||||
|
const labelersInfoQueryKeyRoot = 'labelers-info'
|
||||||
export const labelersInfoQueryKey = (dids: string[]) => [
|
export const labelersInfoQueryKey = (dids: string[]) => [
|
||||||
'labelers-info',
|
labelersInfoQueryKeyRoot,
|
||||||
dids.slice().sort(),
|
dids.slice().sort(),
|
||||||
]
|
]
|
||||||
|
|
||||||
export const labelersDetailedInfoQueryKey = (dids: string[]) => [
|
export const labelersDetailedInfoQueryKey = (dids: string[]) => [
|
||||||
'labelers-detailed-info',
|
labelersDetailedInfoQueryKeyRoot,
|
||||||
dids,
|
dids,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,19 @@
|
||||||
import {AppBskyActorDefs, AppBskyGraphGetList} from '@atproto/api'
|
import {AppBskyActorDefs, AppBskyGraphGetList} from '@atproto/api'
|
||||||
import {
|
import {
|
||||||
useInfiniteQuery,
|
|
||||||
InfiniteData,
|
InfiniteData,
|
||||||
QueryClient,
|
QueryClient,
|
||||||
QueryKey,
|
QueryKey,
|
||||||
|
useInfiniteQuery,
|
||||||
} from '@tanstack/react-query'
|
} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {getAgent} from '#/state/session'
|
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
import {getAgent} from '#/state/session'
|
||||||
|
|
||||||
const PAGE_SIZE = 30
|
const PAGE_SIZE = 30
|
||||||
type RQPageParam = string | undefined
|
type RQPageParam = string | undefined
|
||||||
|
|
||||||
export const RQKEY = (uri: string) => ['list-members', uri]
|
const RQKEY_ROOT = 'list-members'
|
||||||
|
export const RQKEY = (uri: string) => [RQKEY_ROOT, uri]
|
||||||
|
|
||||||
export function useListMembersQuery(uri: string) {
|
export function useListMembersQuery(uri: string) {
|
||||||
return useInfiniteQuery<
|
return useInfiniteQuery<
|
||||||
|
@ -44,7 +45,7 @@ export function* findAllProfilesInQueryData(
|
||||||
const queryDatas = queryClient.getQueriesData<
|
const queryDatas = queryClient.getQueriesData<
|
||||||
InfiniteData<AppBskyGraphGetList.OutputSchema>
|
InfiniteData<AppBskyGraphGetList.OutputSchema>
|
||||||
>({
|
>({
|
||||||
queryKey: ['list-members'],
|
queryKey: [RQKEY_ROOT],
|
||||||
})
|
})
|
||||||
for (const [_queryKey, queryData] of queryDatas) {
|
for (const [_queryKey, queryData] of queryDatas) {
|
||||||
if (!queryData) {
|
if (!queryData) {
|
||||||
|
|
|
@ -17,16 +17,17 @@
|
||||||
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, getAgent} from '#/state/session'
|
|
||||||
import {RQKEY as LIST_MEMBERS_RQKEY} from '#/state/queries/list-members'
|
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
import {RQKEY as LIST_MEMBERS_RQKEY} from '#/state/queries/list-members'
|
||||||
|
import {getAgent, useSession} from '#/state/session'
|
||||||
|
|
||||||
// sanity limit is SANITY_PAGE_LIMIT*PAGE_SIZE total records
|
// sanity limit is SANITY_PAGE_LIMIT*PAGE_SIZE total records
|
||||||
const SANITY_PAGE_LIMIT = 1000
|
const SANITY_PAGE_LIMIT = 1000
|
||||||
const PAGE_SIZE = 100
|
const PAGE_SIZE = 100
|
||||||
// ...which comes 100,000k list members
|
// ...which comes 100,000k list members
|
||||||
|
|
||||||
export const RQKEY = () => ['list-memberships']
|
const RQKEY_ROOT = 'list-memberships'
|
||||||
|
export const RQKEY = () => [RQKEY_ROOT]
|
||||||
|
|
||||||
export interface ListMembersip {
|
export interface ListMembersip {
|
||||||
membershipUri: string
|
membershipUri: string
|
||||||
|
|
|
@ -1,21 +1,23 @@
|
||||||
|
import {Image as RNImage} from 'react-native-image-crop-picker'
|
||||||
import {
|
import {
|
||||||
AtUri,
|
AppBskyGraphDefs,
|
||||||
AppBskyGraphGetList,
|
AppBskyGraphGetList,
|
||||||
AppBskyGraphList,
|
AppBskyGraphList,
|
||||||
AppBskyGraphDefs,
|
AtUri,
|
||||||
Facet,
|
Facet,
|
||||||
} from '@atproto/api'
|
} from '@atproto/api'
|
||||||
import {Image as RNImage} from 'react-native-image-crop-picker'
|
import {useMutation, useQuery, 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, getAgent} from '../session'
|
|
||||||
import {invalidate as invalidateMyLists} from './my-lists'
|
|
||||||
import {RQKEY as PROFILE_LISTS_RQKEY} from './profile-lists'
|
|
||||||
import {uploadBlob} from '#/lib/api'
|
import {uploadBlob} from '#/lib/api'
|
||||||
import {until} from '#/lib/async/until'
|
import {until} from '#/lib/async/until'
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
import {getAgent, useSession} from '../session'
|
||||||
|
import {invalidate as invalidateMyLists} from './my-lists'
|
||||||
|
import {RQKEY as PROFILE_LISTS_RQKEY} from './profile-lists'
|
||||||
|
|
||||||
export const RQKEY = (uri: string) => ['list', uri]
|
const RQKEY_ROOT = 'list'
|
||||||
|
export const RQKEY = (uri: string) => [RQKEY_ROOT, uri]
|
||||||
|
|
||||||
export function useListQuery(uri?: string) {
|
export function useListQuery(uri?: string) {
|
||||||
return useQuery<AppBskyGraphDefs.ListView, Error>({
|
return useQuery<AppBskyGraphDefs.ListView, Error>({
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
import {AppBskyActorDefs, AppBskyGraphGetBlocks} from '@atproto/api'
|
import {AppBskyActorDefs, AppBskyGraphGetBlocks} from '@atproto/api'
|
||||||
import {
|
import {
|
||||||
useInfiniteQuery,
|
|
||||||
InfiniteData,
|
InfiniteData,
|
||||||
QueryClient,
|
QueryClient,
|
||||||
QueryKey,
|
QueryKey,
|
||||||
|
useInfiniteQuery,
|
||||||
} from '@tanstack/react-query'
|
} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {getAgent} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
|
|
||||||
export const RQKEY = () => ['my-blocked-accounts']
|
const RQKEY_ROOT = 'my-blocked-accounts'
|
||||||
|
export const RQKEY = () => [RQKEY_ROOT]
|
||||||
type RQPageParam = string | undefined
|
type RQPageParam = string | undefined
|
||||||
|
|
||||||
export function useMyBlockedAccountsQuery() {
|
export function useMyBlockedAccountsQuery() {
|
||||||
|
@ -39,7 +40,7 @@ export function* findAllProfilesInQueryData(
|
||||||
const queryDatas = queryClient.getQueriesData<
|
const queryDatas = queryClient.getQueriesData<
|
||||||
InfiniteData<AppBskyGraphGetBlocks.OutputSchema>
|
InfiniteData<AppBskyGraphGetBlocks.OutputSchema>
|
||||||
>({
|
>({
|
||||||
queryKey: ['my-blocked-accounts'],
|
queryKey: [RQKEY_ROOT],
|
||||||
})
|
})
|
||||||
for (const [_queryKey, queryData] of queryDatas) {
|
for (const [_queryKey, queryData] of queryDatas) {
|
||||||
if (!queryData?.pages) {
|
if (!queryData?.pages) {
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
import {AppBskyActorDefs} from '@atproto/api'
|
import {AppBskyActorDefs} from '@atproto/api'
|
||||||
import {useQuery} from '@tanstack/react-query'
|
import {useQuery} from '@tanstack/react-query'
|
||||||
import {useSession, getAgent} from '../session'
|
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
import {getAgent, useSession} from '../session'
|
||||||
|
|
||||||
// sanity limit is SANITY_PAGE_LIMIT*PAGE_SIZE total records
|
// sanity limit is SANITY_PAGE_LIMIT*PAGE_SIZE total records
|
||||||
const SANITY_PAGE_LIMIT = 1000
|
const SANITY_PAGE_LIMIT = 1000
|
||||||
const PAGE_SIZE = 100
|
const PAGE_SIZE = 100
|
||||||
// ...which comes 10,000k follows
|
// ...which comes 10,000k follows
|
||||||
|
|
||||||
export const RQKEY = () => ['my-follows']
|
const RQKEY_ROOT = 'my-follows'
|
||||||
|
export const RQKEY = () => [RQKEY_ROOT]
|
||||||
|
|
||||||
export function useMyFollowsQuery() {
|
export function useMyFollowsQuery() {
|
||||||
const {currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
|
|
|
@ -1,16 +1,18 @@
|
||||||
import {AppBskyGraphDefs} from '@atproto/api'
|
import {AppBskyGraphDefs} from '@atproto/api'
|
||||||
import {useQuery, QueryClient} from '@tanstack/react-query'
|
import {QueryClient, useQuery} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {accumulate} from '#/lib/async/accumulate'
|
import {accumulate} from '#/lib/async/accumulate'
|
||||||
import {useSession, getAgent} from '#/state/session'
|
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
import {getAgent, useSession} from '#/state/session'
|
||||||
|
|
||||||
export type MyListsFilter =
|
export type MyListsFilter =
|
||||||
| 'all'
|
| 'all'
|
||||||
| 'curate'
|
| 'curate'
|
||||||
| 'mod'
|
| 'mod'
|
||||||
| 'all-including-subscribed'
|
| 'all-including-subscribed'
|
||||||
export const RQKEY = (filter: MyListsFilter) => ['my-lists', filter]
|
|
||||||
|
const RQKEY_ROOT = 'my-lists'
|
||||||
|
export const RQKEY = (filter: MyListsFilter) => [RQKEY_ROOT, filter]
|
||||||
|
|
||||||
export function useMyListsQuery(filter: MyListsFilter) {
|
export function useMyListsQuery(filter: MyListsFilter) {
|
||||||
const {currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
|
@ -91,6 +93,6 @@ export function invalidate(qc: QueryClient, filter?: MyListsFilter) {
|
||||||
if (filter) {
|
if (filter) {
|
||||||
qc.invalidateQueries({queryKey: RQKEY(filter)})
|
qc.invalidateQueries({queryKey: RQKEY(filter)})
|
||||||
} else {
|
} else {
|
||||||
qc.invalidateQueries({queryKey: ['my-lists']})
|
qc.invalidateQueries({queryKey: [RQKEY_ROOT]})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
import {AppBskyActorDefs, AppBskyGraphGetMutes} from '@atproto/api'
|
import {AppBskyActorDefs, AppBskyGraphGetMutes} from '@atproto/api'
|
||||||
import {
|
import {
|
||||||
useInfiniteQuery,
|
|
||||||
InfiniteData,
|
InfiniteData,
|
||||||
QueryClient,
|
QueryClient,
|
||||||
QueryKey,
|
QueryKey,
|
||||||
|
useInfiniteQuery,
|
||||||
} from '@tanstack/react-query'
|
} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {getAgent} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
|
|
||||||
export const RQKEY = () => ['my-muted-accounts']
|
const RQKEY_ROOT = 'my-muted-accounts'
|
||||||
|
export const RQKEY = () => [RQKEY_ROOT]
|
||||||
type RQPageParam = string | undefined
|
type RQPageParam = string | undefined
|
||||||
|
|
||||||
export function useMyMutedAccountsQuery() {
|
export function useMyMutedAccountsQuery() {
|
||||||
|
@ -39,7 +40,7 @@ export function* findAllProfilesInQueryData(
|
||||||
const queryDatas = queryClient.getQueriesData<
|
const queryDatas = queryClient.getQueriesData<
|
||||||
InfiniteData<AppBskyGraphGetMutes.OutputSchema>
|
InfiniteData<AppBskyGraphGetMutes.OutputSchema>
|
||||||
>({
|
>({
|
||||||
queryKey: ['my-muted-accounts'],
|
queryKey: [RQKEY_ROOT],
|
||||||
})
|
})
|
||||||
for (const [_queryKey, queryData] of queryDatas) {
|
for (const [_queryKey, queryData] of queryDatas) {
|
||||||
if (!queryData?.pages) {
|
if (!queryData?.pages) {
|
||||||
|
|
|
@ -19,28 +19,30 @@
|
||||||
import {useEffect, useRef} from 'react'
|
import {useEffect, useRef} from 'react'
|
||||||
import {AppBskyFeedDefs} from '@atproto/api'
|
import {AppBskyFeedDefs} from '@atproto/api'
|
||||||
import {
|
import {
|
||||||
useInfiniteQuery,
|
|
||||||
InfiniteData,
|
InfiniteData,
|
||||||
QueryKey,
|
|
||||||
useQueryClient,
|
|
||||||
QueryClient,
|
QueryClient,
|
||||||
|
QueryKey,
|
||||||
|
useInfiniteQuery,
|
||||||
|
useQueryClient,
|
||||||
} from '@tanstack/react-query'
|
} from '@tanstack/react-query'
|
||||||
import {useModerationOpts} from '../preferences'
|
|
||||||
import {useUnreadNotificationsApi} from './unread'
|
|
||||||
import {fetchPage} from './util'
|
|
||||||
import {FeedPage} from './types'
|
|
||||||
import {useMutedThreads} from '#/state/muted-threads'
|
import {useMutedThreads} from '#/state/muted-threads'
|
||||||
import {STALE} from '..'
|
import {STALE} from '..'
|
||||||
|
import {useModerationOpts} from '../preferences'
|
||||||
import {embedViewRecordToPostView, getEmbeddedPost} from '../util'
|
import {embedViewRecordToPostView, getEmbeddedPost} from '../util'
|
||||||
|
import {FeedPage} from './types'
|
||||||
|
import {useUnreadNotificationsApi} from './unread'
|
||||||
|
import {fetchPage} from './util'
|
||||||
|
|
||||||
export type {NotificationType, FeedNotification, FeedPage} from './types'
|
export type {FeedNotification, FeedPage, NotificationType} from './types'
|
||||||
|
|
||||||
const PAGE_SIZE = 30
|
const PAGE_SIZE = 30
|
||||||
|
|
||||||
type RQPageParam = string | undefined
|
type RQPageParam = string | undefined
|
||||||
|
|
||||||
|
const RQKEY_ROOT = 'notification-feed'
|
||||||
export function RQKEY() {
|
export function RQKEY() {
|
||||||
return ['notification-feed']
|
return [RQKEY_ROOT]
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useNotificationFeedQuery(opts?: {enabled?: boolean}) {
|
export function useNotificationFeedQuery(opts?: {enabled?: boolean}) {
|
||||||
|
@ -138,7 +140,7 @@ export function* findAllPostsInQueryData(
|
||||||
uri: string,
|
uri: string,
|
||||||
): Generator<AppBskyFeedDefs.PostView, void> {
|
): Generator<AppBskyFeedDefs.PostView, void> {
|
||||||
const queryDatas = queryClient.getQueriesData<InfiniteData<FeedPage>>({
|
const queryDatas = queryClient.getQueriesData<InfiniteData<FeedPage>>({
|
||||||
queryKey: ['notification-feed'],
|
queryKey: [RQKEY_ROOT],
|
||||||
})
|
})
|
||||||
for (const [_queryKey, queryData] of queryDatas) {
|
for (const [_queryKey, queryData] of queryDatas) {
|
||||||
if (!queryData?.pages) {
|
if (!queryData?.pages) {
|
||||||
|
|
|
@ -58,8 +58,9 @@ export interface FeedParams {
|
||||||
|
|
||||||
type RQPageParam = {cursor: string | undefined; api: FeedAPI} | undefined
|
type RQPageParam = {cursor: string | undefined; api: FeedAPI} | undefined
|
||||||
|
|
||||||
|
const RQKEY_ROOT = 'post-feed'
|
||||||
export function RQKEY(feedDesc: FeedDescriptor, params?: FeedParams) {
|
export function RQKEY(feedDesc: FeedDescriptor, params?: FeedParams) {
|
||||||
return ['post-feed', feedDesc, params || {}]
|
return [RQKEY_ROOT, feedDesc, params || {}]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FeedPostSliceItem {
|
export interface FeedPostSliceItem {
|
||||||
|
@ -402,7 +403,7 @@ export function* findAllPostsInQueryData(
|
||||||
const queryDatas = queryClient.getQueriesData<
|
const queryDatas = queryClient.getQueriesData<
|
||||||
InfiniteData<FeedPageUnselected>
|
InfiniteData<FeedPageUnselected>
|
||||||
>({
|
>({
|
||||||
queryKey: ['post-feed'],
|
queryKey: [RQKEY_ROOT],
|
||||||
})
|
})
|
||||||
for (const [_queryKey, queryData] of queryDatas) {
|
for (const [_queryKey, queryData] of queryDatas) {
|
||||||
if (!queryData?.pages) {
|
if (!queryData?.pages) {
|
||||||
|
@ -467,7 +468,7 @@ export function resetProfilePostsQueries(
|
||||||
queryClient.resetQueries({
|
queryClient.resetQueries({
|
||||||
predicate: query =>
|
predicate: query =>
|
||||||
!!(
|
!!(
|
||||||
query.queryKey[0] === 'post-feed' &&
|
query.queryKey[0] === RQKEY_ROOT &&
|
||||||
(query.queryKey[1] as string)?.includes(did)
|
(query.queryKey[1] as string)?.includes(did)
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import {AppBskyActorDefs, AppBskyFeedGetRepostedBy} from '@atproto/api'
|
import {AppBskyActorDefs, AppBskyFeedGetRepostedBy} from '@atproto/api'
|
||||||
import {
|
import {
|
||||||
useInfiniteQuery,
|
|
||||||
InfiniteData,
|
InfiniteData,
|
||||||
QueryClient,
|
QueryClient,
|
||||||
QueryKey,
|
QueryKey,
|
||||||
|
useInfiniteQuery,
|
||||||
} from '@tanstack/react-query'
|
} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {getAgent} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
|
@ -12,7 +12,8 @@ const PAGE_SIZE = 30
|
||||||
type RQPageParam = string | undefined
|
type RQPageParam = string | undefined
|
||||||
|
|
||||||
// TODO refactor invalidate on mutate?
|
// TODO refactor invalidate on mutate?
|
||||||
export const RQKEY = (resolvedUri: string) => ['post-reposted-by', resolvedUri]
|
const RQKEY_ROOT = 'post-reposted-by'
|
||||||
|
export const RQKEY = (resolvedUri: string) => [RQKEY_ROOT, resolvedUri]
|
||||||
|
|
||||||
export function usePostRepostedByQuery(resolvedUri: string | undefined) {
|
export function usePostRepostedByQuery(resolvedUri: string | undefined) {
|
||||||
return useInfiniteQuery<
|
return useInfiniteQuery<
|
||||||
|
@ -44,7 +45,7 @@ export function* findAllProfilesInQueryData(
|
||||||
const queryDatas = queryClient.getQueriesData<
|
const queryDatas = queryClient.getQueriesData<
|
||||||
InfiniteData<AppBskyFeedGetRepostedBy.OutputSchema>
|
InfiniteData<AppBskyFeedGetRepostedBy.OutputSchema>
|
||||||
>({
|
>({
|
||||||
queryKey: ['post-reposted-by'],
|
queryKey: [RQKEY_ROOT],
|
||||||
})
|
})
|
||||||
for (const [_queryKey, queryData] of queryDatas) {
|
for (const [_queryKey, queryData] of queryDatas) {
|
||||||
if (!queryData?.pages) {
|
if (!queryData?.pages) {
|
||||||
|
|
|
@ -1,19 +1,20 @@
|
||||||
import {
|
import {
|
||||||
AppBskyFeedDefs,
|
|
||||||
AppBskyFeedPost,
|
|
||||||
AppBskyFeedGetPostThread,
|
|
||||||
AppBskyEmbedRecord,
|
AppBskyEmbedRecord,
|
||||||
|
AppBskyFeedDefs,
|
||||||
|
AppBskyFeedGetPostThread,
|
||||||
|
AppBskyFeedPost,
|
||||||
} from '@atproto/api'
|
} from '@atproto/api'
|
||||||
import {useQuery, useQueryClient, QueryClient} from '@tanstack/react-query'
|
import {QueryClient, useQuery, useQueryClient} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {getAgent} from '#/state/session'
|
|
||||||
import {UsePreferencesQueryResponse} from '#/state/queries/preferences/types'
|
import {UsePreferencesQueryResponse} from '#/state/queries/preferences/types'
|
||||||
import {findAllPostsInQueryData as findAllPostsInFeedQueryData} from './post-feed'
|
import {getAgent} from '#/state/session'
|
||||||
import {findAllPostsInQueryData as findAllPostsInNotifsQueryData} from './notifications/feed'
|
import {findAllPostsInQueryData as findAllPostsInNotifsQueryData} from './notifications/feed'
|
||||||
|
import {findAllPostsInQueryData as findAllPostsInFeedQueryData} from './post-feed'
|
||||||
import {precacheThreadPostProfiles} from './profile'
|
import {precacheThreadPostProfiles} from './profile'
|
||||||
import {getEmbeddedPost} from './util'
|
import {getEmbeddedPost} from './util'
|
||||||
|
|
||||||
export const RQKEY = (uri: string) => ['post-thread', uri]
|
const RQKEY_ROOT = 'post-thread'
|
||||||
|
export const RQKEY = (uri: string) => [RQKEY_ROOT, uri]
|
||||||
type ThreadViewNode = AppBskyFeedGetPostThread.OutputSchema['thread']
|
type ThreadViewNode = AppBskyFeedGetPostThread.OutputSchema['thread']
|
||||||
|
|
||||||
export interface ThreadCtx {
|
export interface ThreadCtx {
|
||||||
|
@ -233,7 +234,7 @@ export function* findAllPostsInQueryData(
|
||||||
uri: string,
|
uri: string,
|
||||||
): Generator<ThreadNode, void> {
|
): Generator<ThreadNode, void> {
|
||||||
const queryDatas = queryClient.getQueriesData<ThreadNode>({
|
const queryDatas = queryClient.getQueriesData<ThreadNode>({
|
||||||
queryKey: ['post-thread'],
|
queryKey: [RQKEY_ROOT],
|
||||||
})
|
})
|
||||||
for (const [_queryKey, queryData] of queryDatas) {
|
for (const [_queryKey, queryData] of queryDatas) {
|
||||||
if (!queryData) {
|
if (!queryData) {
|
||||||
|
|
|
@ -9,7 +9,8 @@ import {updatePostShadow} from '#/state/cache/post-shadow'
|
||||||
import {Shadow} from '#/state/cache/types'
|
import {Shadow} from '#/state/cache/types'
|
||||||
import {getAgent} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
|
|
||||||
export const RQKEY = (postUri: string) => ['post', postUri]
|
const RQKEY_ROOT = 'post'
|
||||||
|
export const RQKEY = (postUri: string) => [RQKEY_ROOT, postUri]
|
||||||
|
|
||||||
export function usePostQuery(uri: string | undefined) {
|
export function usePostQuery(uri: string | undefined) {
|
||||||
return useQuery<AppBskyFeedDefs.PostView>({
|
return useQuery<AppBskyFeedDefs.PostView>({
|
||||||
|
|
|
@ -1,35 +1,36 @@
|
||||||
import {useMemo, createContext, useContext} from 'react'
|
import {createContext, useContext, useMemo} from 'react'
|
||||||
import {useQuery, useMutation, useQueryClient} from '@tanstack/react-query'
|
|
||||||
import {
|
import {
|
||||||
LabelPreference,
|
|
||||||
BskyFeedViewPreference,
|
|
||||||
ModerationOpts,
|
|
||||||
AppBskyActorDefs,
|
AppBskyActorDefs,
|
||||||
BSKY_LABELER_DID,
|
BSKY_LABELER_DID,
|
||||||
|
BskyFeedViewPreference,
|
||||||
|
LabelPreference,
|
||||||
|
ModerationOpts,
|
||||||
} from '@atproto/api'
|
} from '@atproto/api'
|
||||||
|
import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'
|
||||||
|
|
||||||
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 {getAgent, useSession} from '#/state/session'
|
import {useHiddenPosts, useLabelDefinitions} from '#/state/preferences'
|
||||||
import {
|
import {STALE} from '#/state/queries'
|
||||||
UsePreferencesQueryResponse,
|
|
||||||
ThreadViewPreferences,
|
|
||||||
} from '#/state/queries/preferences/types'
|
|
||||||
import {
|
import {
|
||||||
DEFAULT_HOME_FEED_PREFS,
|
DEFAULT_HOME_FEED_PREFS,
|
||||||
DEFAULT_THREAD_VIEW_PREFS,
|
|
||||||
DEFAULT_LOGGED_OUT_PREFERENCES,
|
DEFAULT_LOGGED_OUT_PREFERENCES,
|
||||||
|
DEFAULT_THREAD_VIEW_PREFS,
|
||||||
} from '#/state/queries/preferences/const'
|
} from '#/state/queries/preferences/const'
|
||||||
import {DEFAULT_LOGGED_OUT_LABEL_PREFERENCES} from '#/state/queries/preferences/moderation'
|
import {DEFAULT_LOGGED_OUT_LABEL_PREFERENCES} from '#/state/queries/preferences/moderation'
|
||||||
import {STALE} from '#/state/queries'
|
import {
|
||||||
import {useHiddenPosts, useLabelDefinitions} from '#/state/preferences'
|
ThreadViewPreferences,
|
||||||
|
UsePreferencesQueryResponse,
|
||||||
|
} from '#/state/queries/preferences/types'
|
||||||
|
import {getAgent, useSession} from '#/state/session'
|
||||||
import {saveLabelers} from '#/state/session/agent-config'
|
import {saveLabelers} from '#/state/session/agent-config'
|
||||||
|
|
||||||
export * from '#/state/queries/preferences/types'
|
|
||||||
export * from '#/state/queries/preferences/moderation'
|
|
||||||
export * from '#/state/queries/preferences/const'
|
export * from '#/state/queries/preferences/const'
|
||||||
|
export * from '#/state/queries/preferences/moderation'
|
||||||
|
export * from '#/state/queries/preferences/types'
|
||||||
|
|
||||||
export const preferencesQueryKey = ['getPreferences']
|
const preferencesQueryKeyRoot = 'getPreferences'
|
||||||
|
export const preferencesQueryKey = [preferencesQueryKeyRoot]
|
||||||
|
|
||||||
export function usePreferencesQuery() {
|
export function usePreferencesQuery() {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import {AppBskyFeedGetActorFeeds} from '@atproto/api'
|
import {AppBskyFeedGetActorFeeds} from '@atproto/api'
|
||||||
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
import {InfiniteData, QueryKey, useInfiniteQuery} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {getAgent} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
|
|
||||||
|
@ -7,7 +7,8 @@ const PAGE_SIZE = 30
|
||||||
type RQPageParam = string | undefined
|
type RQPageParam = string | undefined
|
||||||
|
|
||||||
// TODO refactor invalidate on mutate?
|
// TODO refactor invalidate on mutate?
|
||||||
export const RQKEY = (did: string) => ['profile-feedgens', did]
|
const RQKEY_ROOT = 'profile-feedgens'
|
||||||
|
export const RQKEY = (did: string) => [RQKEY_ROOT, did]
|
||||||
|
|
||||||
export function useProfileFeedgensQuery(
|
export function useProfileFeedgensQuery(
|
||||||
did: string,
|
did: string,
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import {AppBskyActorDefs, AppBskyGraphGetFollowers} from '@atproto/api'
|
import {AppBskyActorDefs, AppBskyGraphGetFollowers} from '@atproto/api'
|
||||||
import {
|
import {
|
||||||
useInfiniteQuery,
|
|
||||||
InfiniteData,
|
InfiniteData,
|
||||||
QueryClient,
|
QueryClient,
|
||||||
QueryKey,
|
QueryKey,
|
||||||
|
useInfiniteQuery,
|
||||||
} from '@tanstack/react-query'
|
} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {getAgent} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
|
@ -11,7 +11,8 @@ import {getAgent} from '#/state/session'
|
||||||
const PAGE_SIZE = 30
|
const PAGE_SIZE = 30
|
||||||
type RQPageParam = string | undefined
|
type RQPageParam = string | undefined
|
||||||
|
|
||||||
export const RQKEY = (did: string) => ['profile-followers', did]
|
const RQKEY_ROOT = 'profile-followers'
|
||||||
|
export const RQKEY = (did: string) => [RQKEY_ROOT, did]
|
||||||
|
|
||||||
export function useProfileFollowersQuery(did: string | undefined) {
|
export function useProfileFollowersQuery(did: string | undefined) {
|
||||||
return useInfiniteQuery<
|
return useInfiniteQuery<
|
||||||
|
@ -43,7 +44,7 @@ export function* findAllProfilesInQueryData(
|
||||||
const queryDatas = queryClient.getQueriesData<
|
const queryDatas = queryClient.getQueriesData<
|
||||||
InfiniteData<AppBskyGraphGetFollowers.OutputSchema>
|
InfiniteData<AppBskyGraphGetFollowers.OutputSchema>
|
||||||
>({
|
>({
|
||||||
queryKey: ['profile-followers'],
|
queryKey: [RQKEY_ROOT],
|
||||||
})
|
})
|
||||||
for (const [_queryKey, queryData] of queryDatas) {
|
for (const [_queryKey, queryData] of queryDatas) {
|
||||||
if (!queryData?.pages) {
|
if (!queryData?.pages) {
|
||||||
|
|
|
@ -1,19 +1,20 @@
|
||||||
import {AppBskyActorDefs, AppBskyGraphGetFollows} from '@atproto/api'
|
import {AppBskyActorDefs, AppBskyGraphGetFollows} from '@atproto/api'
|
||||||
import {
|
import {
|
||||||
useInfiniteQuery,
|
|
||||||
InfiniteData,
|
InfiniteData,
|
||||||
QueryClient,
|
QueryClient,
|
||||||
QueryKey,
|
QueryKey,
|
||||||
|
useInfiniteQuery,
|
||||||
} from '@tanstack/react-query'
|
} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {getAgent} from '#/state/session'
|
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
import {getAgent} from '#/state/session'
|
||||||
|
|
||||||
const PAGE_SIZE = 30
|
const PAGE_SIZE = 30
|
||||||
type RQPageParam = string | undefined
|
type RQPageParam = string | undefined
|
||||||
|
|
||||||
// TODO refactor invalidate on mutate?
|
// TODO refactor invalidate on mutate?
|
||||||
export const RQKEY = (did: string) => ['profile-follows', did]
|
const RQKEY_ROOT = 'profile-follows'
|
||||||
|
export const RQKEY = (did: string) => [RQKEY_ROOT, did]
|
||||||
|
|
||||||
export function useProfileFollowsQuery(did: string | undefined) {
|
export function useProfileFollowsQuery(did: string | undefined) {
|
||||||
return useInfiniteQuery<
|
return useInfiniteQuery<
|
||||||
|
@ -46,7 +47,7 @@ export function* findAllProfilesInQueryData(
|
||||||
const queryDatas = queryClient.getQueriesData<
|
const queryDatas = queryClient.getQueriesData<
|
||||||
InfiniteData<AppBskyGraphGetFollows.OutputSchema>
|
InfiniteData<AppBskyGraphGetFollows.OutputSchema>
|
||||||
>({
|
>({
|
||||||
queryKey: ['profile-follows'],
|
queryKey: [RQKEY_ROOT],
|
||||||
})
|
})
|
||||||
for (const [_queryKey, queryData] of queryDatas) {
|
for (const [_queryKey, queryData] of queryDatas) {
|
||||||
if (!queryData?.pages) {
|
if (!queryData?.pages) {
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
import {AppBskyGraphGetLists} from '@atproto/api'
|
import {AppBskyGraphGetLists} from '@atproto/api'
|
||||||
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
import {InfiniteData, QueryKey, useInfiniteQuery} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {getAgent} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
|
|
||||||
const PAGE_SIZE = 30
|
const PAGE_SIZE = 30
|
||||||
type RQPageParam = string | undefined
|
type RQPageParam = string | undefined
|
||||||
|
|
||||||
export const RQKEY = (did: string) => ['profile-lists', did]
|
const RQKEY_ROOT = 'profile-lists'
|
||||||
|
export const RQKEY = (did: string) => [RQKEY_ROOT, did]
|
||||||
|
|
||||||
export function useProfileListsQuery(did: string, opts?: {enabled?: boolean}) {
|
export function useProfileListsQuery(did: string, opts?: {enabled?: boolean}) {
|
||||||
const enabled = opts?.enabled !== false
|
const enabled = opts?.enabled !== false
|
||||||
|
|
|
@ -30,10 +30,18 @@ import {RQKEY as RQKEY_MY_BLOCKED} from './my-blocked-accounts'
|
||||||
import {RQKEY as RQKEY_MY_MUTED} from './my-muted-accounts'
|
import {RQKEY as RQKEY_MY_MUTED} from './my-muted-accounts'
|
||||||
import {ThreadNode} from './post-thread'
|
import {ThreadNode} from './post-thread'
|
||||||
|
|
||||||
export const RQKEY = (did: string) => ['profile', did]
|
const RQKEY_ROOT = 'profile'
|
||||||
export const profilesQueryKey = (handles: string[]) => ['profiles', handles]
|
export const RQKEY = (did: string) => [RQKEY_ROOT, did]
|
||||||
|
|
||||||
|
const profilesQueryKeyRoot = 'profiles'
|
||||||
|
export const profilesQueryKey = (handles: string[]) => [
|
||||||
|
profilesQueryKeyRoot,
|
||||||
|
handles,
|
||||||
|
]
|
||||||
|
|
||||||
|
const profileBasicQueryKeyRoot = 'profileBasic'
|
||||||
export const profileBasicQueryKey = (didOrHandle: string) => [
|
export const profileBasicQueryKey = (didOrHandle: string) => [
|
||||||
'profileBasic',
|
profileBasicQueryKeyRoot,
|
||||||
didOrHandle,
|
didOrHandle,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -511,7 +519,7 @@ export function* findAllProfilesInQueryData(
|
||||||
): Generator<AppBskyActorDefs.ProfileViewDetailed, void> {
|
): Generator<AppBskyActorDefs.ProfileViewDetailed, void> {
|
||||||
const queryDatas =
|
const queryDatas =
|
||||||
queryClient.getQueriesData<AppBskyActorDefs.ProfileViewDetailed>({
|
queryClient.getQueriesData<AppBskyActorDefs.ProfileViewDetailed>({
|
||||||
queryKey: ['profile'],
|
queryKey: [RQKEY_ROOT],
|
||||||
})
|
})
|
||||||
for (const [_queryKey, queryData] of queryDatas) {
|
for (const [_queryKey, queryData] of queryDatas) {
|
||||||
if (!queryData) {
|
if (!queryData) {
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
|
import {AppBskyActorDefs, AtUri} from '@atproto/api'
|
||||||
import {useQuery, useQueryClient, UseQueryResult} from '@tanstack/react-query'
|
import {useQuery, useQueryClient, UseQueryResult} from '@tanstack/react-query'
|
||||||
import {AtUri, AppBskyActorDefs} from '@atproto/api'
|
|
||||||
|
|
||||||
import {profileBasicQueryKey as RQKEY_PROFILE_BASIC} from './profile'
|
|
||||||
import {getAgent} from '#/state/session'
|
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
import {getAgent} from '#/state/session'
|
||||||
|
import {profileBasicQueryKey as RQKEY_PROFILE_BASIC} from './profile'
|
||||||
|
|
||||||
export const RQKEY = (didOrHandle: string) => ['resolved-did', didOrHandle]
|
const RQKEY_ROOT = 'resolved-did'
|
||||||
|
export const RQKEY = (didOrHandle: string) => [RQKEY_ROOT, didOrHandle]
|
||||||
|
|
||||||
type UriUseQueryResult = UseQueryResult<{did: string; uri: string}, Error>
|
type UriUseQueryResult = UseQueryResult<{did: string; uri: string}, Error>
|
||||||
export function useResolveUriQuery(uri: string | undefined): UriUseQueryResult {
|
export function useResolveUriQuery(uri: string | undefined): UriUseQueryResult {
|
||||||
|
|
|
@ -1,16 +1,17 @@
|
||||||
import {AppBskyFeedDefs, AppBskyFeedSearchPosts} from '@atproto/api'
|
import {AppBskyFeedDefs, AppBskyFeedSearchPosts} from '@atproto/api'
|
||||||
import {
|
import {
|
||||||
useInfiniteQuery,
|
|
||||||
InfiniteData,
|
InfiniteData,
|
||||||
QueryKey,
|
|
||||||
QueryClient,
|
QueryClient,
|
||||||
|
QueryKey,
|
||||||
|
useInfiniteQuery,
|
||||||
} from '@tanstack/react-query'
|
} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {getAgent} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
import {embedViewRecordToPostView, getEmbeddedPost} from './util'
|
import {embedViewRecordToPostView, getEmbeddedPost} from './util'
|
||||||
|
|
||||||
|
const searchPostsQueryKeyRoot = 'search-posts'
|
||||||
const searchPostsQueryKey = ({query}: {query: string}) => [
|
const searchPostsQueryKey = ({query}: {query: string}) => [
|
||||||
'search-posts',
|
searchPostsQueryKeyRoot,
|
||||||
query,
|
query,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -43,7 +44,7 @@ export function* findAllPostsInQueryData(
|
||||||
const queryDatas = queryClient.getQueriesData<
|
const queryDatas = queryClient.getQueriesData<
|
||||||
InfiniteData<AppBskyFeedSearchPosts.OutputSchema>
|
InfiniteData<AppBskyFeedSearchPosts.OutputSchema>
|
||||||
>({
|
>({
|
||||||
queryKey: ['search-posts'],
|
queryKey: [searchPostsQueryKeyRoot],
|
||||||
})
|
})
|
||||||
for (const [_queryKey, queryData] of queryDatas) {
|
for (const [_queryKey, queryData] of queryDatas) {
|
||||||
if (!queryData?.pages) {
|
if (!queryData?.pages) {
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import {BskyAgent} from '@atproto/api'
|
import {BskyAgent} from '@atproto/api'
|
||||||
import {useQuery} from '@tanstack/react-query'
|
import {useQuery} from '@tanstack/react-query'
|
||||||
|
|
||||||
export const RQKEY = (serviceUrl: string) => ['service', serviceUrl]
|
const RQKEY_ROOT = 'service'
|
||||||
|
export const RQKEY = (serviceUrl: string) => [RQKEY_ROOT, serviceUrl]
|
||||||
|
|
||||||
export function useServiceQuery(serviceUrl: string) {
|
export function useServiceQuery(serviceUrl: string) {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
|
||||||
import {AppBskyFeedGetSuggestedFeeds} from '@atproto/api'
|
import {AppBskyFeedGetSuggestedFeeds} from '@atproto/api'
|
||||||
|
import {InfiniteData, QueryKey, useInfiniteQuery} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {getAgent} from '#/state/session'
|
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
import {getAgent} from '#/state/session'
|
||||||
|
|
||||||
export const suggestedFeedsQueryKey = ['suggestedFeeds']
|
const suggestedFeedsQueryKeyRoot = 'suggestedFeeds'
|
||||||
|
export const suggestedFeedsQueryKey = [suggestedFeedsQueryKeyRoot]
|
||||||
|
|
||||||
export function useSuggestedFeedsQuery() {
|
export function useSuggestedFeedsQuery() {
|
||||||
return useInfiniteQuery<
|
return useInfiniteQuery<
|
||||||
|
|
|
@ -6,21 +6,24 @@ import {
|
||||||
moderateProfile,
|
moderateProfile,
|
||||||
} from '@atproto/api'
|
} from '@atproto/api'
|
||||||
import {
|
import {
|
||||||
useInfiniteQuery,
|
|
||||||
useQueryClient,
|
|
||||||
useQuery,
|
|
||||||
InfiniteData,
|
InfiniteData,
|
||||||
QueryClient,
|
QueryClient,
|
||||||
QueryKey,
|
QueryKey,
|
||||||
|
useInfiniteQuery,
|
||||||
|
useQuery,
|
||||||
|
useQueryClient,
|
||||||
} from '@tanstack/react-query'
|
} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {useSession, getAgent} from '#/state/session'
|
|
||||||
import {useModerationOpts} from '#/state/queries/preferences'
|
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
|
import {useModerationOpts} from '#/state/queries/preferences'
|
||||||
|
import {getAgent, useSession} from '#/state/session'
|
||||||
|
|
||||||
const suggestedFollowsQueryKey = ['suggested-follows']
|
const suggestedFollowsQueryKeyRoot = 'suggested-follows'
|
||||||
|
const suggestedFollowsQueryKey = [suggestedFollowsQueryKeyRoot]
|
||||||
|
|
||||||
|
const suggestedFollowsByActorQueryKeyRoot = 'suggested-follows-by-actor'
|
||||||
const suggestedFollowsByActorQueryKey = (did: string) => [
|
const suggestedFollowsByActorQueryKey = (did: string) => [
|
||||||
'suggested-follows-by-actor',
|
suggestedFollowsByActorQueryKeyRoot,
|
||||||
did,
|
did,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -125,7 +128,7 @@ function* findAllProfilesInSuggestedFollowsQueryData(
|
||||||
const queryDatas = queryClient.getQueriesData<
|
const queryDatas = queryClient.getQueriesData<
|
||||||
InfiniteData<AppBskyActorGetSuggestions.OutputSchema>
|
InfiniteData<AppBskyActorGetSuggestions.OutputSchema>
|
||||||
>({
|
>({
|
||||||
queryKey: ['suggested-follows'],
|
queryKey: [suggestedFollowsQueryKeyRoot],
|
||||||
})
|
})
|
||||||
for (const [_queryKey, queryData] of queryDatas) {
|
for (const [_queryKey, queryData] of queryDatas) {
|
||||||
if (!queryData?.pages) {
|
if (!queryData?.pages) {
|
||||||
|
@ -148,7 +151,7 @@ function* findAllProfilesInSuggestedFollowsByActorQueryData(
|
||||||
const queryDatas =
|
const queryDatas =
|
||||||
queryClient.getQueriesData<AppBskyGraphGetSuggestedFollowsByActor.OutputSchema>(
|
queryClient.getQueriesData<AppBskyGraphGetSuggestedFollowsByActor.OutputSchema>(
|
||||||
{
|
{
|
||||||
queryKey: ['suggested-follows-by-actor'],
|
queryKey: [suggestedFollowsByActorQueryKeyRoot],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
for (const [_queryKey, queryData] of queryDatas) {
|
for (const [_queryKey, queryData] of queryDatas) {
|
||||||
|
|
Loading…
Reference in New Issue