Retro Bulletin Board Systems on atproto. Web app and TUI.
lazy mirror of alyraffauf/atbbs
atbbs.xyz
forums
python
tui
atproto
bbs
1import { useMutation } from "@tanstack/react-query";
2import { useAuth } from "../lib/auth";
3import { resolveIdentity } from "../lib/atproto";
4import {
5 createBan,
6 createHide,
7 deleteBan,
8 deleteHide,
9} from "../lib/writes";
10import { alertOnError } from "../lib/alerts";
11
12// Shared ban/unban/hide/unhide mutations
13// `ban` accepts either a DID or a handle
14export function useModerationMutations() {
15 const { agent } = useAuth();
16
17 const ban = useMutation({
18 mutationFn: async (identifier: string) => {
19 if (!agent) throw new Error("Not signed in");
20 const did = identifier.startsWith("did:")
21 ? identifier
22 : (await resolveIdentity(identifier)).did;
23 await createBan(agent, did);
24 },
25 onError: alertOnError("ban"),
26 });
27
28 const unban = useMutation({
29 mutationFn: async (rkey: string) => {
30 if (!agent) throw new Error("Not signed in");
31 await deleteBan(agent, rkey);
32 },
33 onError: alertOnError("unban"),
34 });
35
36 const hide = useMutation({
37 mutationFn: async (uri: string) => {
38 if (!agent) throw new Error("Not signed in");
39 await createHide(agent, uri);
40 },
41 onError: alertOnError("hide"),
42 });
43
44 const unhide = useMutation({
45 mutationFn: async (rkey: string) => {
46 if (!agent) throw new Error("Not signed in");
47 await deleteHide(agent, rkey);
48 },
49 onError: alertOnError("unhide"),
50 });
51
52 return { ban, unban, hide, unhide };
53}