feat: update ui
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { useWAClient } from "@/app/context";
|
||||
import { getId } from "@/lib/utils";
|
||||
import type { ContactDTO } from "@shared/dto";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
export function useContacts() {
|
||||
const { client, isReady } = useWAClient();
|
||||
|
||||
const res = useQuery({
|
||||
queryKey: ["contacts"],
|
||||
queryFn: () => client.listContacts(),
|
||||
refetchOnWindowFocus: false,
|
||||
enabled: isReady,
|
||||
});
|
||||
|
||||
return {
|
||||
...res,
|
||||
findById(id: ContactDTO["id"]) {
|
||||
if (!id) return null;
|
||||
return res.data?.find((i) => getId(i.id) === getId(id));
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { useWAClient } from "@/app/context";
|
||||
import type { MessageDTO } from "@shared/dto";
|
||||
import { useEffect } from "react";
|
||||
|
||||
export function useMessageEvent(callback: (msg: MessageDTO) => any) {
|
||||
const { addListener } = useWAClient();
|
||||
useEffect(() => {
|
||||
return addListener("message", callback);
|
||||
}, [callback]);
|
||||
}
|
||||
Reference in New Issue
Block a user