2021-07-31 15:57:43 +00:00
|
|
|
import { useQuery } from "blitz";
|
2021-07-31 14:33:18 +00:00
|
|
|
|
2021-07-31 15:57:43 +00:00
|
|
|
import getConversationsQuery from "../queries/get-conversations";
|
2021-07-31 14:33:18 +00:00
|
|
|
|
|
|
|
export default function useConversation(recipient: string) {
|
|
|
|
return useQuery(
|
|
|
|
getConversationsQuery,
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
select(conversations) {
|
|
|
|
if (!conversations[recipient]) {
|
2021-07-31 15:57:43 +00:00
|
|
|
throw new Error("Conversation not found");
|
2021-07-31 14:33:18 +00:00
|
|
|
}
|
|
|
|
|
2021-07-31 15:57:43 +00:00
|
|
|
return conversations[recipient]!;
|
2021-07-31 14:33:18 +00:00
|
|
|
},
|
2021-08-01 07:40:18 +00:00
|
|
|
keepPreviousData: true,
|
2021-07-31 14:33:18 +00:00
|
|
|
}
|
2021-07-31 15:57:43 +00:00
|
|
|
);
|
2021-07-31 14:33:18 +00:00
|
|
|
}
|