https://dev.kronoz.win/r/marzneshin.git
1import { HostType } from "@marzneshin/features/hosts";
2import { useQuery } from "@tanstack/react-query";
3import { fetch } from "@marzneshin/utils";
4
5export async function fetchHosts({ queryKey }: { queryKey: [string, number | undefined] }): Promise<HostType[]> {
6 if (queryKey[1]) {
7 return fetch(`/inbounds/${queryKey[1]}/hosts`).then((result) => {
8 return result.items;
9 });
10 } else {
11 return fetch(`/inbounds/hosts`).then((result) => {
12 return result.items;
13 });
14 }
15}
16
17export const HostsQueryFetchKey = "hosts";
18
19export const useHostsQuery = (inboundId?: number | undefined) => {
20 return useQuery({
21 queryKey: [HostsQueryFetchKey, inboundId],
22 queryFn: fetchHosts,
23 initialData: []
24 })
25}