diff options
author | Samuel Newman <mozzius@protonmail.com> | 2025-02-03 14:37:24 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-03 22:37:24 +0000 |
commit | 32b28d666229ac24cf7b1ac328d1566fb089e1a1 (patch) | |
tree | 2e721117c9a859ca1cae52e1c15642d5e6db4d5b /src/state/messages/convo/index.tsx | |
parent | fa8607b861e0719d76778aa14af0745313640e33 (diff) | |
download | voidsky-32b28d666229ac24cf7b1ac328d1566fb089e1a1.tar.zst |
Fix convo header loading state (#7603)
* get initial convo state from cache * undo useConvoQuery changes * fix shadowing situation with new hook
Diffstat (limited to 'src/state/messages/convo/index.tsx')
-rw-r--r-- | src/state/messages/convo/index.tsx | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/state/messages/convo/index.tsx b/src/state/messages/convo/index.tsx index 10ec2a348..a1750bdf0 100644 --- a/src/state/messages/convo/index.tsx +++ b/src/state/messages/convo/index.tsx @@ -1,4 +1,5 @@ import React, {useContext, useState, useSyncExternalStore} from 'react' +import {ChatBskyConvoDefs} from '@atproto/api' import {useFocusEffect} from '@react-navigation/native' import {useQueryClient} from '@tanstack/react-query' @@ -14,7 +15,10 @@ import { } from '#/state/messages/convo/types' import {isConvoActive} from '#/state/messages/convo/util' import {useMessagesEventBus} from '#/state/messages/events' -import {useMarkAsReadMutation} from '#/state/queries/messages/conversation' +import { + RQKEY as getConvoKey, + useMarkAsReadMutation, +} from '#/state/queries/messages/conversation' import {RQKEY as ListConvosQueryKey} from '#/state/queries/messages/list-conversations' import {RQKEY as createProfileQueryKey} from '#/state/queries/profile' import {useAgent} from '#/state/session' @@ -60,14 +64,17 @@ export function ConvoProvider({ const queryClient = useQueryClient() const agent = useAgent() const events = useMessagesEventBus() - const [convo] = useState( - () => - new Convo({ - convoId, - agent, - events, - }), - ) + const [convo] = useState(() => { + const placeholder = queryClient.getQueryData<ChatBskyConvoDefs.ConvoView>( + getConvoKey(convoId), + ) + return new Convo({ + convoId, + agent, + events, + placeholderData: placeholder ? {convo: placeholder} : undefined, + }) + }) const service = useSyncExternalStore(convo.subscribe, convo.getSnapshot) const {mutate: markAsRead} = useMarkAsReadMutation() |