-
Notifications
You must be signed in to change notification settings - Fork 0
/
logout-from-chats.tsx
35 lines (33 loc) · 1.15 KB
/
logout-from-chats.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { ChatQueries } from "../queries";
import { useContext } from "react";
import { NostrQueries } from "../nostr";
import { ChatContext } from "../chat-context-provider";
export function useLogoutFromChats() {
const queryClient = useQueryClient();
const { activeUsername, storage } = useContext(ChatContext);
return useMutation({
mutationKey: ["chats/logout-from-chats"],
mutationFn: async () => {
storage?.removeItem("ecency_nostr_pr_" + activeUsername);
queryClient.setQueryData([NostrQueries.PUBLIC_KEY, activeUsername], "");
queryClient.setQueryData([NostrQueries.PRIVATE_KEY, activeUsername], "");
queryClient.setQueryData(
[ChatQueries.JOINED_CHANNELS, activeUsername],
[],
);
queryClient.setQueryData(
[ChatQueries.ORIGINAL_JOINED_CHANNELS, activeUsername],
[],
);
queryClient.setQueryData(
[ChatQueries.ORIGINAL_DIRECT_CONTACTS, activeUsername],
[],
);
queryClient.setQueryData(
[ChatQueries.DIRECT_CONTACTS, activeUsername],
[],
);
},
});
}