diff options
author | Paul Frazee <pfrazee@gmail.com> | 2023-11-27 17:41:30 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-27 17:41:30 -0800 |
commit | f580d4daf0d2172fa285a5a87a1bec5100a70f63 (patch) | |
tree | 425c866f9d39a2c193d0b8097bcf01d6bbfe2064 /src/state/queries/notifications | |
parent | d4714baf13561236a85d44fec144f7f27a149bfd (diff) | |
download | voidsky-f580d4daf0d2172fa285a5a87a1bec5100a70f63.tar.zst |
Restore post-thread caching behaviors (react-query refactor) (#2010)
* Rework resolve-did and resolve-uri queries to be smarter about cache reuse * Precache handle resolutions * Remove old unused code * Load placeholder threads from the post-feed and notifications-feed queries * Remove logs * Fix bad ref * Add loading spinners to the cache-loading thread view * Scroll replies into view when loading threads * Add caching within a thread * Fix: dont show bottom border when the child spinner is active
Diffstat (limited to 'src/state/queries/notifications')
-rw-r--r-- | src/state/queries/notifications/feed.ts | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/state/queries/notifications/feed.ts b/src/state/queries/notifications/feed.ts index d78370e07..54bd87540 100644 --- a/src/state/queries/notifications/feed.ts +++ b/src/state/queries/notifications/feed.ts @@ -7,11 +7,18 @@ import { BskyAgent, } from '@atproto/api' import chunk from 'lodash.chunk' -import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query' +import { + useInfiniteQuery, + InfiniteData, + QueryKey, + useQueryClient, + QueryClient, +} from '@tanstack/react-query' import {getAgent} from '../../session' import {useModerationOpts} from '../preferences' import {shouldFilterNotif} from './util' import {useMutedThreads} from '#/state/muted-threads' +import {precacheProfile as precacheResolvedUri} from '../resolve-uri' const GROUPABLE_REASONS = ['like', 'repost', 'follow'] const PAGE_SIZE = 30 @@ -48,6 +55,7 @@ export interface FeedPage { } export function useNotificationFeedQuery(opts?: {enabled?: boolean}) { + const queryClient = useQueryClient() const moderationOpts = useModerationOpts() const threadMutes = useMutedThreads() const enabled = opts?.enabled !== false @@ -80,6 +88,9 @@ export function useNotificationFeedQuery(opts?: {enabled?: boolean}) { for (const notif of notifsGrouped) { if (notif.subjectUri) { notif.subject = subjects.get(notif.subjectUri) + if (notif.subject) { + precacheResolvedUri(queryClient, notif.subject.author) // precache the handle->did resolution + } } } @@ -99,6 +110,32 @@ export function useNotificationFeedQuery(opts?: {enabled?: boolean}) { }) } +/** + * This helper is used by the post-thread placeholder function to + * find a post in the query-data cache + */ +export function findPostInQueryData( + queryClient: QueryClient, + uri: string, +): AppBskyFeedDefs.PostView | undefined { + const queryDatas = queryClient.getQueriesData<InfiniteData<FeedPage>>({ + queryKey: ['notification-feed'], + }) + for (const [_queryKey, queryData] of queryDatas) { + if (!queryData?.pages) { + continue + } + for (const page of queryData?.pages) { + for (const item of page.items) { + if (item.subject?.uri === uri) { + return item.subject + } + } + } + } + return undefined +} + function groupNotifications( notifs: AppBskyNotificationListNotifications.Notification[], ): FeedNotification[] { |