fix major violations
This commit is contained in:
@@ -226,6 +226,7 @@ export function createGetPopularFeedsQueryKey(
|
||||
export function useGetPopularFeedsQuery(options?: GetPopularFeedsOptions) {
|
||||
const {hasSession} = useSession()
|
||||
const agent = useAgent()
|
||||
const enabled = options?.enabled
|
||||
const limit = options?.limit || 10
|
||||
const {data: preferences} = usePreferencesQuery()
|
||||
const queryClient = useQueryClient()
|
||||
@@ -243,8 +244,8 @@ export function useGetPopularFeedsQuery(options?: GetPopularFeedsOptions) {
|
||||
const lastPageCountRef = useRef(0)
|
||||
|
||||
const query = useInfiniteQuery({
|
||||
enabled: Boolean(moderationOpts) && options?.enabled !== false,
|
||||
queryKey: createGetPopularFeedsQueryKey(options),
|
||||
enabled: Boolean(moderationOpts) && enabled !== false,
|
||||
queryKey: createGetPopularFeedsQueryKey({enabled, limit}),
|
||||
queryFn: async ({pageParam}) => {
|
||||
const res = await agent.app.bsky.unspecced.getPopularFeedGenerators({
|
||||
limit,
|
||||
@@ -298,8 +299,8 @@ export function useGetPopularFeedsQuery(options?: GetPopularFeedsOptions) {
|
||||
),
|
||||
})
|
||||
|
||||
const {isFetching, hasNextPage, data, fetchNextPage} = query
|
||||
useEffect(() => {
|
||||
const {isFetching, hasNextPage, data} = query
|
||||
if (isFetching || !hasNextPage) {
|
||||
return
|
||||
}
|
||||
@@ -318,10 +319,10 @@ export function useGetPopularFeedsQuery(options?: GetPopularFeedsOptions) {
|
||||
count += page.feeds.length
|
||||
}
|
||||
if (count < limit && (data?.pages.length || 0) < 6) {
|
||||
query.fetchNextPage()
|
||||
void fetchNextPage()
|
||||
lastPageCountRef.current = data?.pages?.length || 0
|
||||
}
|
||||
}, [query, limit])
|
||||
}, [isFetching, hasNextPage, data, fetchNextPage, limit])
|
||||
|
||||
return query
|
||||
}
|
||||
|
||||
@@ -228,9 +228,15 @@ export function useNotificationFeedQuery(opts: {
|
||||
const lastItemCount = useRef(0)
|
||||
const wantedItemCount = useRef(0)
|
||||
const autoPaginationAttemptCount = useRef(0)
|
||||
const {
|
||||
data,
|
||||
isLoading,
|
||||
isRefetching,
|
||||
isFetchingNextPage,
|
||||
hasNextPage,
|
||||
fetchNextPage,
|
||||
} = query
|
||||
useEffect(() => {
|
||||
const {data, isLoading, isRefetching, isFetchingNextPage, hasNextPage} =
|
||||
query
|
||||
// Count the items that we already have.
|
||||
let itemCount = 0
|
||||
for (const page of data?.pages || []) {
|
||||
@@ -262,13 +268,20 @@ export function useNotificationFeedQuery(opts: {
|
||||
if (itemCount < wantedItemCount.current) {
|
||||
autoPaginationAttemptCount.current++
|
||||
if (autoPaginationAttemptCount.current < 50 /* failsafe */) {
|
||||
query.fetchNextPage()
|
||||
void fetchNextPage()
|
||||
}
|
||||
} else {
|
||||
autoPaginationAttemptCount.current = 0
|
||||
}
|
||||
}
|
||||
}, [query])
|
||||
}, [
|
||||
data,
|
||||
isLoading,
|
||||
isRefetching,
|
||||
isFetchingNextPage,
|
||||
hasNextPage,
|
||||
fetchNextPage,
|
||||
])
|
||||
|
||||
return query
|
||||
}
|
||||
@@ -298,7 +311,7 @@ export function* findAllPostsInQueryData(
|
||||
if (AppBskyFeedDefs.isPostView(item.subject)) {
|
||||
const quotedPost = getEmbeddedPost(item.subject?.embed)
|
||||
if (quotedPost && didOrHandleUriMatches(atUri, quotedPost)) {
|
||||
yield embedViewRecordToPostView(quotedPost!)
|
||||
yield embedViewRecordToPostView(quotedPost)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -369,9 +369,15 @@ export function usePostFeedQuery(
|
||||
const lastItemCount = useRef(0)
|
||||
const wantedItemCount = useRef(0)
|
||||
const autoPaginationAttemptCount = useRef(0)
|
||||
const {
|
||||
data,
|
||||
isLoading,
|
||||
isRefetching,
|
||||
isFetchingNextPage,
|
||||
hasNextPage,
|
||||
fetchNextPage,
|
||||
} = query
|
||||
useEffect(() => {
|
||||
const {data, isLoading, isRefetching, isFetchingNextPage, hasNextPage} =
|
||||
query
|
||||
// Count the items that we already have.
|
||||
let itemCount = 0
|
||||
for (const page of data?.pages || []) {
|
||||
@@ -405,13 +411,20 @@ export function usePostFeedQuery(
|
||||
if (itemCount < wantedItemCount.current) {
|
||||
autoPaginationAttemptCount.current++
|
||||
if (autoPaginationAttemptCount.current < 50 /* failsafe */) {
|
||||
query.fetchNextPage()
|
||||
void fetchNextPage()
|
||||
}
|
||||
} else {
|
||||
autoPaginationAttemptCount.current = 0
|
||||
}
|
||||
}
|
||||
}, [query])
|
||||
}, [
|
||||
data,
|
||||
isLoading,
|
||||
isRefetching,
|
||||
isFetchingNextPage,
|
||||
hasNextPage,
|
||||
fetchNextPage,
|
||||
])
|
||||
|
||||
return query
|
||||
}
|
||||
|
||||
@@ -167,25 +167,30 @@ export function usePostThread({anchor}: {anchor?: string}) {
|
||||
return data
|
||||
},
|
||||
})
|
||||
const {
|
||||
data: additionalItemsData,
|
||||
isLoading: additionalItemsIsLoading,
|
||||
isError: additionalItemsIsError,
|
||||
} = additionalItemsQuery
|
||||
const serverOtherThreadItems: ThreadItem[] = useMemo(() => {
|
||||
if (!additionalQueryEnabled) return []
|
||||
if (additionalItemsQuery.isLoading) {
|
||||
if (additionalItemsIsLoading) {
|
||||
return Array.from({length: 2}).map((_, i) =>
|
||||
views.skeleton({
|
||||
key: `other-reply-${i}`,
|
||||
item: 'reply',
|
||||
}),
|
||||
)
|
||||
} else if (additionalItemsQuery.isError) {
|
||||
} else if (additionalItemsIsError) {
|
||||
/*
|
||||
* We could insert an special error component in here, but since these
|
||||
* are optional additional replies, it's not critical that they're shown
|
||||
* atm.
|
||||
*/
|
||||
return []
|
||||
} else if (additionalItemsQuery.data?.thread) {
|
||||
} else if (additionalItemsData?.thread) {
|
||||
const {threadItems} = sortAndAnnotateThreadItems(
|
||||
additionalItemsQuery.data.thread,
|
||||
additionalItemsData?.thread,
|
||||
{
|
||||
view,
|
||||
skipModerationHandling: true,
|
||||
@@ -202,10 +207,12 @@ export function usePostThread({anchor}: {anchor?: string}) {
|
||||
}, [
|
||||
view,
|
||||
additionalQueryEnabled,
|
||||
additionalItemsQuery,
|
||||
mergeThreadgateHiddenReplies,
|
||||
moderationOpts,
|
||||
threadgate?.record,
|
||||
additionalItemsData,
|
||||
additionalItemsIsLoading,
|
||||
additionalItemsIsError,
|
||||
])
|
||||
|
||||
/**
|
||||
@@ -248,6 +255,8 @@ export function usePostThread({anchor}: {anchor?: string}) {
|
||||
view,
|
||||
])
|
||||
|
||||
const {isFetching, isPlaceholderData, error, refetch} = query
|
||||
|
||||
/*
|
||||
* Take all three sets of thread items and combine them into a single thread,
|
||||
* along with any other thread items required for rendering e.g. "Show more
|
||||
@@ -258,7 +267,7 @@ export function usePostThread({anchor}: {anchor?: string}) {
|
||||
threadItems,
|
||||
otherThreadItems,
|
||||
serverOtherThreadItems,
|
||||
isLoading: query.isPlaceholderData,
|
||||
isLoading: isPlaceholderData,
|
||||
hasSession,
|
||||
hasOtherThreadItems,
|
||||
otherItemsVisible,
|
||||
@@ -268,7 +277,7 @@ export function usePostThread({anchor}: {anchor?: string}) {
|
||||
threadItems,
|
||||
otherThreadItems,
|
||||
serverOtherThreadItems,
|
||||
query.isPlaceholderData,
|
||||
isPlaceholderData,
|
||||
hasSession,
|
||||
hasOtherThreadItems,
|
||||
otherItemsVisible,
|
||||
@@ -286,9 +295,9 @@ export function usePostThread({anchor}: {anchor?: string}) {
|
||||
/*
|
||||
* Copy in any query state that is useful
|
||||
*/
|
||||
isFetching: query.isFetching,
|
||||
isPlaceholderData: query.isPlaceholderData,
|
||||
error: query.error,
|
||||
isFetching: isFetching,
|
||||
isPlaceholderData: isPlaceholderData,
|
||||
error: error,
|
||||
/*
|
||||
* Other state
|
||||
*/
|
||||
@@ -305,7 +314,7 @@ export function usePostThread({anchor}: {anchor?: string}) {
|
||||
* Copy in any query actions that are useful
|
||||
*/
|
||||
insertReplies: mutator.insertReplies,
|
||||
refetch: query.refetch,
|
||||
refetch: refetch,
|
||||
/*
|
||||
* Other actions
|
||||
*/
|
||||
@@ -314,7 +323,10 @@ export function usePostThread({anchor}: {anchor?: string}) {
|
||||
},
|
||||
}
|
||||
}, [
|
||||
query,
|
||||
isFetching,
|
||||
isPlaceholderData,
|
||||
error,
|
||||
refetch,
|
||||
mutator.insertReplies,
|
||||
otherItemsVisible,
|
||||
sort,
|
||||
|
||||
Reference in New Issue
Block a user