mirror of
https://github.com/barkeser2002/pterodactyl-addons.git
synced 2026-09-25 07:20:00 +03:00
27 lines
1.0 KiB
TypeScript
27 lines
1.0 KiB
TypeScript
|
|
import useSWR from 'swr';
|
|
import http, { PaginatedResult } from '@/api/http';
|
|
import { createContext, useContext } from 'react';
|
|
|
|
interface ctx {
|
|
page: number;
|
|
setPage: (value: number | ((s: number) => number)) => void;
|
|
searchFilter: string;
|
|
setSearchFilter: (value: string | ((s: string) => string)) => void;
|
|
}
|
|
|
|
export const Context = createContext<ctx>({ page: 1, setPage: () => 1, searchFilter: '', setSearchFilter: () => '' });
|
|
|
|
export default (uuid: string) => {
|
|
const { page, searchFilter } = useContext(Context);
|
|
|
|
return useSWR<PaginatedResult<any>>([ 'server:FiveMResource', page, searchFilter ], async () => {
|
|
const { data } = await http.get(`/api/client/servers/${uuid}/listefivem`, { timeout: 60000 });
|
|
const pagetotal = Math.ceil(data.data.length / 10);
|
|
return ({
|
|
items: (data.data || []),
|
|
pagination: { total: 13170, count: data.data.length, perPage: 10, currentPage: page, totalPages: pagetotal },
|
|
});
|
|
});
|
|
};
|