cache fix for search post results (#3520)

zio/stable
Hailey 2024-04-12 17:31:55 -07:00 committed by GitHub
parent 7d01ff90d3
commit 93731e6d6b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 37 additions and 22 deletions

View File

@ -8,6 +8,7 @@ import {QueryClient, useQuery, useQueryClient} from '@tanstack/react-query'
import {UsePreferencesQueryResponse} from '#/state/queries/preferences/types' import {UsePreferencesQueryResponse} from '#/state/queries/preferences/types'
import {getAgent} from '#/state/session' import {getAgent} from '#/state/session'
import {findAllPostsInQueryData as findAllPostsInSearchQueryData} from 'state/queries/search-posts'
import {findAllPostsInQueryData as findAllPostsInNotifsQueryData} from './notifications/feed' import {findAllPostsInQueryData as findAllPostsInNotifsQueryData} from './notifications/feed'
import {findAllPostsInQueryData as findAllPostsInFeedQueryData} from './post-feed' import {findAllPostsInQueryData as findAllPostsInFeedQueryData} from './post-feed'
import {precacheThreadPostProfiles} from './profile' import {precacheThreadPostProfiles} from './profile'
@ -260,6 +261,9 @@ export function* findAllPostsInQueryData(
for (let post of findAllPostsInNotifsQueryData(queryClient, uri)) { for (let post of findAllPostsInNotifsQueryData(queryClient, uri)) {
yield postViewToPlaceholderThread(post) yield postViewToPlaceholderThread(post)
} }
for (let post of findAllPostsInSearchQueryData(queryClient, uri)) {
yield postViewToPlaceholderThread(post)
}
} }
function* traverseThread(node: ThreadNode): Generator<ThreadNode, void> { function* traverseThread(node: ThreadNode): Generator<ThreadNode, void> {

View File

@ -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 {StyleProp, StyleSheet, View, ViewStyle} from 'react-native'
import { import {
AppBskyFeedDefs, AppBskyFeedDefs,
@ -7,30 +7,33 @@ import {
ModerationDecision, ModerationDecision,
RichText as RichTextAPI, RichText as RichTextAPI,
} from '@atproto/api' } from '@atproto/api'
import {moderatePost_wrapped as moderatePost} from '#/lib/moderatePost_wrapped'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
import {Link, TextLink} from '../util/Link' import {msg, Trans} from '@lingui/macro'
import {UserInfoText} from '../util/UserInfoText' import {useLingui} from '@lingui/react'
import {PostMeta} from '../util/PostMeta' import {useQueryClient} from '@tanstack/react-query'
import {PostEmbeds} from '../util/post-embeds'
import {PostCtrls} from '../util/post-ctrls/PostCtrls' import {moderatePost_wrapped as moderatePost} from '#/lib/moderatePost_wrapped'
import {ContentHider} from '../../../components/moderation/ContentHider' import {POST_TOMBSTONE, Shadow, usePostShadow} from '#/state/cache/post-shadow'
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 {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 {useModerationOpts} from '#/state/queries/preferences'
import {useComposerControls} from '#/state/shell/composer' import {useComposerControls} from '#/state/shell/composer'
import {Shadow, usePostShadow, POST_TOMBSTONE} from '#/state/cache/post-shadow' import {MAX_POST_LINES} from 'lib/constants'
import {Trans, msg} from '@lingui/macro' import {usePalette} from 'lib/hooks/usePalette'
import {useLingui} from '@lingui/react' import {makeProfileLink} from 'lib/routes/links'
import {countLines} from 'lib/strings/helpers'
import {colors, s} from 'lib/styles'
import {RQKEY as RQKEY_URI} from 'state/queries/resolve-uri'
import {atoms as a} from '#/alf' 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({ export function Post({
post, post,
@ -98,6 +101,7 @@ function PostInner({
showReplyLine?: boolean showReplyLine?: boolean
style?: StyleProp<ViewStyle> style?: StyleProp<ViewStyle>
}) { }) {
const queryClient = useQueryClient()
const pal = usePalette('default') const pal = usePalette('default')
const {_} = useLingui() const {_} = useLingui()
const {openComposer} = useComposerControls() const {openComposer} = useComposerControls()
@ -129,8 +133,15 @@ function PostInner({
setLimitLines(false) setLimitLines(false)
}, [setLimitLines]) }, [setLimitLines])
const onBeforePress = React.useCallback(() => {
queryClient.setQueryData(RQKEY_URI(post.author.handle), post.author.did)
}, [queryClient, post.author.handle, post.author.did])
return ( 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} />} {showReplyLine && <View style={styles.replyLine} />}
<View style={styles.layout}> <View style={styles.layout}>
<View style={styles.layoutAvi}> <View style={styles.layoutAvi}>