https://dev.kronoz.win/r/marzneshin.git
1import { HostType } from "@marzneshin/features/hosts";
2import { useQuery } from "@tanstack/react-query";
3import { fetch } from "@marzneshin/utils";
4import {
5 FetchEntityReturn,
6 UseEntityQueryProps,
7 EntitySidebarQueryKeyType
8} from "@marzneshin/features/entity-table/hooks";
9
10export async function fetchHosts({ queryKey }: EntitySidebarQueryKeyType): FetchEntityReturn<HostType> {
11 return fetch(queryKey[1] !== undefined ? `/inbounds/${queryKey[1]}/hosts` : `/inbounds/hosts`, {
12 query: {
13 page: queryKey[3],
14 size: queryKey[4],
15 }
16 }).then((result) => {
17 return {
18 entity: result.items,
19 pageCount: result.pages
20 };
21 });
22}
23
24export const HostsQueryFetchKey = "hosts";
25
26export const useHostsQuery = ({
27 inboundId, page, size, search = ""
28}: UseEntityQueryProps & { inboundId?: number }) => {
29 return useQuery({
30 queryKey: ["inbounds", inboundId, HostsQueryFetchKey, page, size, search],
31 queryFn: fetchHosts,
32 initialData: { entity: [], pageCount: 0 }
33 })
34}