diff options
author | Hailey <me@haileyok.com> | 2024-04-30 15:04:17 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-30 15:04:17 -0700 |
commit | db968b7610e8f3f217093c7a0d59b2ce1f319776 (patch) | |
tree | 06c4ac83a87ada2d1f4f4319a2cf7b0e7df6ab10 /src/screens/Messages/Temp/query/query.ts | |
parent | 268e30d21af3c71ad3d3a71590ef681a21f69438 (diff) | |
download | voidsky-db968b7610e8f3f217093c7a0d59b2ce1f319776.tar.zst |
[Clipclops] Header for chat (#3775)
* add temp `getchat` query * properly get the other profile * add basic header * normalize layout on all devices * remove unused imports, adjust style * remove unnecessary log * remove another log * remove some more imports * cleanup * use `Button` instead in the header * lint
Diffstat (limited to 'src/screens/Messages/Temp/query/query.ts')
-rw-r--r-- | src/screens/Messages/Temp/query/query.ts | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/screens/Messages/Temp/query/query.ts b/src/screens/Messages/Temp/query/query.ts index a51929bca..a4d78e0bb 100644 --- a/src/screens/Messages/Temp/query/query.ts +++ b/src/screens/Messages/Temp/query/query.ts @@ -73,6 +73,8 @@ export function useChat(chatId: string) { const chatJson = (await chatResponse.json()) as TempDmChatGetChat.OutputSchema + queryClient.setQueryData(['chatQuery', chatId], chatJson.chat) + const newChat = { chatId, messages: messagesJson.messages, @@ -275,3 +277,25 @@ export function useListChats() { getNextPageParam: lastPage => lastPage.cursor, }) } + +export function useChatQuery(chatId: string) { + const headers = useHeaders() + const {serviceUrl} = useDmServiceUrlStorage() + + return useQuery({ + queryKey: ['chatQuery', chatId], + queryFn: async () => { + const chatResponse = await fetch( + `${serviceUrl}/xrpc/temp.dm.getChat?chatId=${chatId}`, + { + headers, + }, + ) + + if (!chatResponse.ok) throw new Error('Failed to fetch chat') + + const json = (await chatResponse.json()) as TempDmChatGetChat.OutputSchema + return json.chat + }, + }) +} |