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