mirror of
https://github.com/MrUnknownDE/panel.git
synced 2026-04-14 04:13:46 +02:00
Fix RolesContainer, refactor NestsContainer
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import http from '@/api/http';
|
||||
import http, { getPaginationSet, PaginatedResult } from '@/api/http';
|
||||
import { rawDataToNest } from '@/api/transformers';
|
||||
import { createContext, useContext } from 'react';
|
||||
import useSWR from 'swr';
|
||||
|
||||
export interface Nest {
|
||||
id: number;
|
||||
@@ -11,10 +13,22 @@ export interface Nest {
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
export default (): Promise<Nest[]> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.get('/api/application/nests')
|
||||
.then(({ data }) => resolve((data.data || []).map(rawDataToNest)))
|
||||
.catch(reject);
|
||||
interface ctx {
|
||||
page: number;
|
||||
setPage: (value: number | ((s: number) => number)) => void;
|
||||
}
|
||||
|
||||
export const Context = createContext<ctx>({ page: 1, setPage: () => 1 });
|
||||
|
||||
export default () => {
|
||||
const { page } = useContext(Context);
|
||||
|
||||
return useSWR<PaginatedResult<Nest>>([ 'nests', page ], async () => {
|
||||
const { data } = await http.get('/api/application/nests', { params: { page } });
|
||||
|
||||
return ({
|
||||
items: (data.data || []).map(rawDataToNest),
|
||||
pagination: getPaginationSet(data.meta.pagination),
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user