forked from
rocksky.app/rocksky
A decentralized music tracking and discovery platform built on AT Protocol 馃幍
1import axios from "axios";
2import { useCallback } from "react";
3import { API_URL } from "../consts";
4
5function useShout() {
6 const shout = async (uri: string, message: string) => {
7 const response = await axios.post(
8 `${API_URL}/users/${uri.replace("at://", "")}/shouts`,
9 { message },
10 {
11 headers: {
12 "Content-Type": "application/json",
13 Authorization: `Bearer ${localStorage.getItem("token")}`,
14 },
15 }
16 );
17 return response.data;
18 };
19
20 const getShouts = useCallback(async (uri: string) => {
21 const response = await axios.get(
22 `${API_URL}/users/${uri.replace("at://", "")}/shouts`,
23 {
24 headers: {
25 Authorization: `Bearer ${localStorage.getItem("token")}`,
26 },
27 }
28 );
29 return response.data;
30 }, []);
31
32 const reply = async (uri: string, message: string) => {
33 const response = await axios.post(
34 `${API_URL}/users/${uri.replace("at://", "")}/replies`,
35 { message },
36 {
37 headers: {
38 "Content-Type": "application/json",
39 Authorization: `Bearer ${localStorage.getItem("token")}`,
40 },
41 }
42 );
43 return response.data;
44 };
45
46 const getReplies = useCallback(async (uri: string) => {
47 const response = await axios.get(
48 `${API_URL}/users/${uri.replace("at://", "")}/replies`
49 );
50 return response.data;
51 }, []);
52
53 const reportShout = async (uri: string) => {
54 const response = await axios.post(
55 `${API_URL}/users/${uri.replace("at://", "")}/report`,
56 {},
57 {
58 headers: {
59 Authorization: `Bearer ${localStorage.getItem("token")}`,
60 },
61 }
62 );
63 return response.data;
64 };
65
66 const deleteShout = async (uri: string) => {
67 const response = await axios.delete(
68 `${API_URL}/users/${uri.replace("at://", "")}`,
69 {
70 headers: {
71 Authorization: `Bearer ${localStorage.getItem("token")}`,
72 },
73 }
74 );
75 return response.data;
76 };
77
78 const cancelReport = async (uri: string) => {
79 const response = await axios.delete(
80 `${API_URL}/users/${uri.replace("at://", "")}/report`,
81 {
82 headers: {
83 Authorization: `Bearer ${localStorage.getItem("token")}`,
84 },
85 }
86 );
87 return response.data;
88 };
89
90 return {
91 shout,
92 getShouts,
93 reply,
94 getReplies,
95 reportShout,
96 deleteShout,
97 cancelReport,
98 };
99}
100
101export default useShout;