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 { WhatsAppClient } from "./src/client/whatsapp";
|
||||||
import { getId } from "./ui/src/lib/utils";
|
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();
|
await wa.connect();
|
||||||
|
|
||||||
// console.log("status", await wa.status());
|
// console.log("status", await wa.status());
|
||||||
@@ -9,19 +10,30 @@ await wa.connect();
|
|||||||
// const devices = await wa.listDevices();
|
// const devices = await wa.listDevices();
|
||||||
// console.log("devices", devices);
|
// console.log("devices", devices);
|
||||||
|
|
||||||
// const test = await wa.exec("return window.location;");
|
// const data = JSON.stringify({
|
||||||
// console.log("test", test);
|
// 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();
|
// const groups = await wa.listGroups();
|
||||||
// console.log(groups.map((i) => ({ name: i.subject, id: getId(i.id) })));
|
// 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 });
|
// const messages = await wa.getMessages({ chatId: groupId, count: 50 });
|
||||||
console.log(
|
// console.log(
|
||||||
messages
|
// messages
|
||||||
.filter((i) => i.type === "chat")
|
// .filter((i) => i.type === "chat")
|
||||||
.map((i) => ({ body: i.body, fromMe: i.fromMe })),
|
// .map((i) => ({ body: i.body, fromMe: i.fromMe })),
|
||||||
);
|
// );
|
||||||
|
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
|
|||||||
+14
-2
@@ -13,7 +13,7 @@ import {
|
|||||||
PhoneIcon,
|
PhoneIcon,
|
||||||
UsersIcon,
|
UsersIcon,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { useMemo, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
selected: string | null;
|
selected: string | null;
|
||||||
@@ -23,10 +23,22 @@ export default function ChatsSection({ selected, onSelect }: Props) {
|
|||||||
const [query, setQuery] = useState("");
|
const [query, setQuery] = useState("");
|
||||||
|
|
||||||
const contacts = useContacts();
|
const contacts = useContacts();
|
||||||
const { data: chats, isLoading } = useChats({
|
const {
|
||||||
|
data: chats,
|
||||||
|
isLoading,
|
||||||
|
refetch,
|
||||||
|
} = useChats({
|
||||||
refetchInterval: 10_000,
|
refetchInterval: 10_000,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Refetch chat list when returning to main screen
|
||||||
|
if (!selected) {
|
||||||
|
console.log("test");
|
||||||
|
refetch();
|
||||||
|
}
|
||||||
|
}, [selected]);
|
||||||
|
|
||||||
const chatList = useMemo(() => {
|
const chatList = useMemo(() => {
|
||||||
return (
|
return (
|
||||||
chats?.map((i) => {
|
chats?.map((i) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user