feat: update ui

This commit is contained in:
2026-09-17 13:47:37 +08:00
parent e9c1d5f3c7
commit 65a2e534d7
18 changed files with 284 additions and 58 deletions
+23
View File
@@ -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));
},
};
}
+10
View File
@@ -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]);
}