Rollback unneeded changes

This commit is contained in:
Eric Bailey
2024-04-30 20:08:07 -05:00
parent 971f229955
commit 24c8165e05
+17 -28
View File
@@ -1,5 +1,3 @@
import React from 'react'
import {BskyAgent} from '@atproto/api'
import { import {
useInfiniteQuery, useInfiniteQuery,
useMutation, useMutation,
@@ -13,6 +11,7 @@ import * as TempDmChatGetChat from '#/temp/dm/getChat'
import * as TempDmChatGetChatForMembers from '#/temp/dm/getChatForMembers' import * as TempDmChatGetChatForMembers from '#/temp/dm/getChatForMembers'
import * as TempDmChatGetChatLog from '#/temp/dm/getChatLog' import * as TempDmChatGetChatLog from '#/temp/dm/getChatLog'
import * as TempDmChatGetChatMessages from '#/temp/dm/getChatMessages' import * as TempDmChatGetChatMessages from '#/temp/dm/getChatMessages'
import * as TempDmChatListChats from '#/temp/dm/listChats'
import {useDmServiceUrlStorage} from '../useDmServiceUrlStorage' import {useDmServiceUrlStorage} from '../useDmServiceUrlStorage'
/** /**
@@ -230,24 +229,19 @@ export function useGetChatFromMembers({
const queryClient = useQueryClient() const queryClient = useQueryClient()
const headers = useHeaders() const headers = useHeaders()
const {serviceUrl} = useDmServiceUrlStorage() const {serviceUrl} = useDmServiceUrlStorage()
const [agent] = React.useState(() => {
return new BskyAgent({
service: serviceUrl,
})
})
return useMutation({ return useMutation({
mutationFn: async (members: string[]) => { mutationFn: async (members: string[]) => {
const {data} = await agent.api.temp.dm.getChatForMembers( const response = await fetch(
{ `${serviceUrl}/xrpc/temp.dm.getChatForMembers?members=${members.join(
members, ',',
}, )}`,
{ {headers},
headers,
},
) )
return data if (!response.ok) throw new Error('Failed to fetch chat')
return (await response.json()) as TempDmChatGetChatForMembers.OutputSchema
}, },
onSuccess: data => { onSuccess: data => {
queryClient.setQueryData(['chat', data.chat.id], { queryClient.setQueryData(['chat', data.chat.id], {
@@ -264,25 +258,20 @@ export function useGetChatFromMembers({
export function useListChats() { export function useListChats() {
const headers = useHeaders() const headers = useHeaders()
const {serviceUrl} = useDmServiceUrlStorage() const {serviceUrl} = useDmServiceUrlStorage()
const [agent] = React.useState(() => {
return new BskyAgent({
service: serviceUrl,
})
})
return useInfiniteQuery({ return useInfiniteQuery({
queryKey: ['chats'], queryKey: ['chats'],
queryFn: async ({pageParam}) => { queryFn: async ({pageParam}) => {
const {data} = await agent.api.temp.dm.listChats( const response = await fetch(
{ `${serviceUrl}/xrpc/temp.dm.listChats${
cursor: pageParam, pageParam ? `?cursor=${pageParam}` : ''
}, }`,
{ {headers},
headers,
},
) )
return data if (!response.ok) throw new Error('Failed to fetch chats')
return (await response.json()) as TempDmChatListChats.OutputSchema
}, },
initialPageParam: undefined as string | undefined, initialPageParam: undefined as string | undefined,
getNextPageParam: lastPage => lastPage.cursor, getNextPageParam: lastPage => lastPage.cursor,