feat: refresh chat list on return to main menu
This commit is contained in:
+22
-10
@@ -1,7 +1,8 @@
|
||||
import { WhatsAppClient } from "./src/client/whatsapp";
|
||||
import { getId } from "./ui/src/lib/utils";
|
||||
|
||||
const wa = new WhatsAppClient("ws://127.0.0.1:8787");
|
||||
// const wa = new WhatsAppClient("ws://127.0.0.1:8787");
|
||||
const wa = new WhatsAppClient(process.env.WS_URL);
|
||||
await wa.connect();
|
||||
|
||||
// console.log("status", await wa.status());
|
||||
@@ -9,19 +10,30 @@ await wa.connect();
|
||||
// const devices = await wa.listDevices();
|
||||
// console.log("devices", devices);
|
||||
|
||||
// const test = await wa.exec("return window.location;");
|
||||
// console.log("test", test);
|
||||
// const data = JSON.stringify({
|
||||
// DEVICE_ID: "1789636162707",
|
||||
// DEVICE_NAME: "7C-1",
|
||||
// });
|
||||
// console.log(data);
|
||||
// await wa.exec(`return localStorage.setItem('wa-bridge-consts', '${data}');`);
|
||||
// const test = await wa.exec(`return localStorage.getItem('wa-bridge-consts');`);
|
||||
|
||||
// const test = await wa.exec(`return document.hasFocus();`);
|
||||
const test = await wa.exec(`window.location.reload(); return 1;`);
|
||||
console.log("test", test);
|
||||
|
||||
// const test = await wa.exec(`return GM_info.script.version;`);
|
||||
|
||||
// const groups = await wa.listGroups();
|
||||
// console.log(groups.map((i) => ({ name: i.subject, id: getId(i.id) })));
|
||||
|
||||
const groupId = "[email protected]";
|
||||
// const groupId = "[email protected]";
|
||||
|
||||
const messages = await wa.getMessages({ chatId: groupId, count: 50 });
|
||||
console.log(
|
||||
messages
|
||||
.filter((i) => i.type === "chat")
|
||||
.map((i) => ({ body: i.body, fromMe: i.fromMe })),
|
||||
);
|
||||
// const messages = await wa.getMessages({ chatId: groupId, count: 50 });
|
||||
// console.log(
|
||||
// messages
|
||||
// .filter((i) => i.type === "chat")
|
||||
// .map((i) => ({ body: i.body, fromMe: i.fromMe })),
|
||||
// );
|
||||
|
||||
process.exit(0);
|
||||
|
||||
+14
-2
@@ -13,7 +13,7 @@ import {
|
||||
PhoneIcon,
|
||||
UsersIcon,
|
||||
} from "lucide-react";
|
||||
import { useMemo, useState } from "react";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
|
||||
type Props = {
|
||||
selected: string | null;
|
||||
@@ -23,10 +23,22 @@ export default function ChatsSection({ selected, onSelect }: Props) {
|
||||
const [query, setQuery] = useState("");
|
||||
|
||||
const contacts = useContacts();
|
||||
const { data: chats, isLoading } = useChats({
|
||||
const {
|
||||
data: chats,
|
||||
isLoading,
|
||||
refetch,
|
||||
} = useChats({
|
||||
refetchInterval: 10_000,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
// Refetch chat list when returning to main screen
|
||||
if (!selected) {
|
||||
console.log("test");
|
||||
refetch();
|
||||
}
|
||||
}, [selected]);
|
||||
|
||||
const chatList = useMemo(() => {
|
||||
return (
|
||||
chats?.map((i) => {
|
||||
|
||||
Reference in New Issue
Block a user