From 93731e6d6bd345d8f45cd560e8185a60472cdf25 Mon Sep 17 00:00:00 2001 From: Hailey <me@haileyok.com> Date: Fri, 12 Apr 2024 17:31:55 -0700 Subject: [PATCH] cache fix for search post results (#3520) --- src/state/queries/post-thread.ts | 4 +++ src/view/com/post/Post.tsx | 53 +++++++++++++++++++------------- 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/src/state/queries/post-thread.ts b/src/state/queries/post-thread.ts index dfc568b7d5..521fc4751b 100644 --- a/src/state/queries/post-thread.ts +++ b/src/state/queries/post-thread.ts @@ -8,6 +8,7 @@ import {QueryClient, useQuery, useQueryClient} from '@tanstack/react-query' import {UsePreferencesQueryResponse} from '#/state/queries/preferences/types' import {getAgent} from '#/state/session' +import {findAllPostsInQueryData as findAllPostsInSearchQueryData} from 'state/queries/search-posts' import {findAllPostsInQueryData as findAllPostsInNotifsQueryData} from './notifications/feed' import {findAllPostsInQueryData as findAllPostsInFeedQueryData} from './post-feed' import {precacheThreadPostProfiles} from './profile' @@ -260,6 +261,9 @@ export function* findAllPostsInQueryData( for (let post of findAllPostsInNotifsQueryData(queryClient, uri)) { yield postViewToPlaceholderThread(post) } + for (let post of findAllPostsInSearchQueryData(queryClient, uri)) { + yield postViewToPlaceholderThread(post) + } } function* traverseThread(node: ThreadNode): Generator<ThreadNode, void> { diff --git a/src/view/com/post/Post.tsx b/src/view/com/post/Post.tsx index 47e46eb0cb..9a084e96a2 100644 --- a/src/view/com/post/Post.tsx +++ b/src/view/com/post/Post.tsx @@ -1,4 +1,4 @@ -import React, {useState, useMemo} from 'react' +import React, {useMemo, useState} from 'react' import {StyleProp, StyleSheet, View, ViewStyle} from 'react-native' import { AppBskyFeedDefs, @@ -7,30 +7,33 @@ import { ModerationDecision, RichText as RichTextAPI, } from '@atproto/api' -import {moderatePost_wrapped as moderatePost} from '#/lib/moderatePost_wrapped' import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' -import {Link, TextLink} from '../util/Link' -import {UserInfoText} from '../util/UserInfoText' -import {PostMeta} from '../util/PostMeta' -import {PostEmbeds} from '../util/post-embeds' -import {PostCtrls} from '../util/post-ctrls/PostCtrls' -import {ContentHider} from '../../../components/moderation/ContentHider' -import {PostAlerts} from '../../../components/moderation/PostAlerts' -import {LabelsOnMyPost} from '../../../components/moderation/LabelsOnMe' -import {Text} from '../util/text/Text' -import {RichText} from '#/components/RichText' -import {PreviewableUserAvatar} from '../util/UserAvatar' -import {s, colors} from 'lib/styles' +import {msg, Trans} from '@lingui/macro' +import {useLingui} from '@lingui/react' +import {useQueryClient} from '@tanstack/react-query' + +import {moderatePost_wrapped as moderatePost} from '#/lib/moderatePost_wrapped' +import {POST_TOMBSTONE, Shadow, usePostShadow} from '#/state/cache/post-shadow' +import {useModerationOpts} from '#/state/queries/preferences' +import {useComposerControls} from '#/state/shell/composer' +import {MAX_POST_LINES} from 'lib/constants' import {usePalette} from 'lib/hooks/usePalette' import {makeProfileLink} from 'lib/routes/links' -import {MAX_POST_LINES} from 'lib/constants' import {countLines} from 'lib/strings/helpers' -import {useModerationOpts} from '#/state/queries/preferences' -import {useComposerControls} from '#/state/shell/composer' -import {Shadow, usePostShadow, POST_TOMBSTONE} from '#/state/cache/post-shadow' -import {Trans, msg} from '@lingui/macro' -import {useLingui} from '@lingui/react' +import {colors, s} from 'lib/styles' +import {RQKEY as RQKEY_URI} from 'state/queries/resolve-uri' import {atoms as a} from '#/alf' +import {RichText} from '#/components/RichText' +import {ContentHider} from '../../../components/moderation/ContentHider' +import {LabelsOnMyPost} from '../../../components/moderation/LabelsOnMe' +import {PostAlerts} from '../../../components/moderation/PostAlerts' +import {Link, TextLink} from '../util/Link' +import {PostCtrls} from '../util/post-ctrls/PostCtrls' +import {PostEmbeds} from '../util/post-embeds' +import {PostMeta} from '../util/PostMeta' +import {Text} from '../util/text/Text' +import {PreviewableUserAvatar} from '../util/UserAvatar' +import {UserInfoText} from '../util/UserInfoText' export function Post({ post, @@ -98,6 +101,7 @@ function PostInner({ showReplyLine?: boolean style?: StyleProp<ViewStyle> }) { + const queryClient = useQueryClient() const pal = usePalette('default') const {_} = useLingui() const {openComposer} = useComposerControls() @@ -129,8 +133,15 @@ function PostInner({ setLimitLines(false) }, [setLimitLines]) + const onBeforePress = React.useCallback(() => { + queryClient.setQueryData(RQKEY_URI(post.author.handle), post.author.did) + }, [queryClient, post.author.handle, post.author.did]) + return ( - <Link href={itemHref} style={[styles.outer, pal.border, style]}> + <Link + href={itemHref} + style={[styles.outer, pal.border, style]} + onBeforePress={onBeforePress}> {showReplyLine && <View style={styles.replyLine} />} <View style={styles.layout}> <View style={styles.layoutAvi}>