ui(admin): cleanup table hooks

This commit is contained in:
Matthew Penner 2021-07-19 14:34:10 -06:00
parent 30f09a4098
commit 7524bbe8ee
20 changed files with 209 additions and 389 deletions

View File

@ -0,0 +1,33 @@
import { createContext } from 'react';
export interface ListContext<T> {
page: number;
setPage: (page: ((p: number) => number) | number) => void;
filters: T | null;
setFilters: (filters: ((f: T | null) => T | null) | T | null) => void;
sort: string | null;
setSort: (sort: string | null) => void;
sortDirection: boolean;
setSortDirection: (direction: ((p: boolean) => boolean) | boolean) => void;
}
function create<T> () {
return createContext<ListContext<T>>({
page: 1,
setPage: () => 1,
filters: null,
setFilters: () => null,
sort: null,
setSort: () => null,
sortDirection: false,
setSortDirection: () => false,
});
}
export { create as createContext };

View File

@ -1,6 +1,7 @@
import http, { FractalResponseData, getPaginationSet, PaginatedResult } from '@/api/http'; import http, { FractalResponseData, getPaginationSet, PaginatedResult } from '@/api/http';
import { createContext, useContext } from 'react'; import { useContext } from 'react';
import useSWR from 'swr'; import useSWR from 'swr';
import { createContext } from '@/api/admin/admin';
export interface Database { export interface Database {
id: number; id: number;
@ -34,33 +35,7 @@ export interface Filters {
host?: string; host?: string;
} }
interface ctx { export const Context = createContext<Filters>();
page: number;
setPage: (value: number | ((s: number) => number)) => void;
filters: Filters | null;
setFilters: (filters: Filters | null) => void;
sort: string | null;
setSort: (sort: string | null) => void;
sortDirection: boolean;
setSortDirection: (direction: boolean) => void;
}
export const Context = createContext<ctx>({
page: 1,
setPage: () => 1,
filters: null,
setFilters: () => null,
sort: null,
setSort: () => null,
sortDirection: false,
setSortDirection: () => false,
});
export default (include: string[] = []) => { export default (include: string[] = []) => {
const { page, filters, sort, sortDirection } = useContext(Context); const { page, filters, sort, sortDirection } = useContext(Context);

View File

@ -1,6 +1,7 @@
import http, { FractalResponseData, getPaginationSet, PaginatedResult } from '@/api/http'; import http, { FractalResponseData, getPaginationSet, PaginatedResult } from '@/api/http';
import { createContext, useContext } from 'react'; import { useContext } from 'react';
import useSWR from 'swr'; import useSWR from 'swr';
import { createContext } from '@/api/admin/admin';
export interface Location { export interface Location {
id: number; id: number;
@ -24,33 +25,7 @@ export interface Filters {
long?: string; long?: string;
} }
interface ctx { export const Context = createContext<Filters>();
page: number;
setPage: (value: number | ((s: number) => number)) => void;
filters: Filters | null;
setFilters: (filters: Filters | null) => void;
sort: string | null;
setSort: (sort: string | null) => void;
sortDirection: boolean;
setSortDirection: (direction: boolean) => void;
}
export const Context = createContext<ctx>({
page: 1,
setPage: () => 1,
filters: null,
setFilters: () => null,
sort: null,
setSort: () => null,
sortDirection: false,
setSortDirection: () => false,
});
export default (include: string[] = []) => { export default (include: string[] = []) => {
const { page, filters, sort, sortDirection } = useContext(Context); const { page, filters, sort, sortDirection } = useContext(Context);

View File

@ -1,6 +1,7 @@
import http, { FractalResponseData, FractalResponseList, getPaginationSet, PaginatedResult } from '@/api/http'; import http, { FractalResponseData, FractalResponseList, getPaginationSet, PaginatedResult } from '@/api/http';
import { createContext, useContext } from 'react'; import { useContext } from 'react';
import useSWR from 'swr'; import useSWR from 'swr';
import { createContext } from '@/api/admin/admin';
import { Egg, rawDataToEgg } from '@/api/admin/eggs/getEgg'; import { Egg, rawDataToEgg } from '@/api/admin/eggs/getEgg';
import { Node, rawDataToNode } from '@/api/admin/nodes/getNodes'; import { Node, rawDataToNode } from '@/api/admin/nodes/getNodes';
import { Server, rawDataToServer } from '@/api/admin/servers/getServers'; import { Server, rawDataToServer } from '@/api/admin/servers/getServers';
@ -50,33 +51,7 @@ export interface Filters {
target?: string; target?: string;
} }
interface ctx { export const Context = createContext<Filters>();
page: number;
setPage: (value: number | ((s: number) => number)) => void;
filters: Filters | null;
setFilters: (filters: Filters | null) => void;
sort: string | null;
setSort: (sort: string | null) => void;
sortDirection: boolean;
setSortDirection: (direction: boolean) => void;
}
export const Context = createContext<ctx>({
page: 1,
setPage: () => 1,
filters: null,
setFilters: () => null,
sort: null,
setSort: () => null,
sortDirection: false,
setSortDirection: () => false,
});
export default (include: string[] = []) => { export default (include: string[] = []) => {
const { page, filters, sort, sortDirection } = useContext(Context); const { page, filters, sort, sortDirection } = useContext(Context);

View File

@ -1,6 +1,7 @@
import http, { getPaginationSet, PaginatedResult } from '@/api/http'; import http, { getPaginationSet, PaginatedResult } from '@/api/http';
import { createContext, useContext } from 'react'; import { useContext } from 'react';
import useSWR from 'swr'; import useSWR from 'swr';
import { createContext } from '@/api/admin/admin';
import { Egg, rawDataToEgg } from '@/api/admin/eggs/getEgg'; import { Egg, rawDataToEgg } from '@/api/admin/eggs/getEgg';
export interface Filters { export interface Filters {
@ -8,33 +9,7 @@ export interface Filters {
name?: string; name?: string;
} }
interface ctx { export const Context = createContext<Filters>();
page: number;
setPage: (value: number | ((s: number) => number)) => void;
filters: Filters | null;
setFilters: (filters: Filters | null) => void;
sort: string | null;
setSort: (sort: string | null) => void;
sortDirection: boolean;
setSortDirection: (direction: boolean) => void;
}
export const Context = createContext<ctx>({
page: 1,
setPage: () => 1,
filters: null,
setFilters: () => null,
sort: null,
setSort: () => null,
sortDirection: false,
setSortDirection: () => false,
});
export default (nestId: number, include: string[] = []) => { export default (nestId: number, include: string[] = []) => {
const { page, filters, sort, sortDirection } = useContext(Context); const { page, filters, sort, sortDirection } = useContext(Context);

View File

@ -1,6 +1,7 @@
import http, { FractalResponseData, FractalResponseList, getPaginationSet, PaginatedResult } from '@/api/http'; import http, { FractalResponseData, FractalResponseList, getPaginationSet, PaginatedResult } from '@/api/http';
import { createContext, useContext } from 'react'; import { useContext } from 'react';
import useSWR from 'swr'; import useSWR from 'swr';
import { createContext } from '@/api/admin/admin';
import { Egg, rawDataToEgg } from '@/api/admin/eggs/getEgg'; import { Egg, rawDataToEgg } from '@/api/admin/eggs/getEgg';
export interface Nest { export interface Nest {
@ -36,33 +37,7 @@ export interface Filters {
name?: string; name?: string;
} }
interface ctx { export const Context = createContext<Filters>();
page: number;
setPage: (value: number | ((s: number) => number)) => void;
filters: Filters | null;
setFilters: (filters: Filters | null) => void;
sort: string | null;
setSort: (sort: string | null) => void;
sortDirection: boolean;
setSortDirection: (direction: boolean) => void;
}
export const Context = createContext<ctx>({
page: 1,
setPage: () => 1,
filters: null,
setFilters: () => null,
sort: null,
setSort: () => null,
sortDirection: false,
setSortDirection: () => false,
});
export default (include: string[] = []) => { export default (include: string[] = []) => {
const { page, filters, sort, sortDirection } = useContext(Context); const { page, filters, sort, sortDirection } = useContext(Context);

View File

@ -1,6 +1,7 @@
import http, { FractalResponseData, getPaginationSet, PaginatedResult } from '@/api/http'; import http, { FractalResponseData, getPaginationSet, PaginatedResult } from '@/api/http';
import { createContext, useContext } from 'react'; import { useContext } from 'react';
import useSWR from 'swr'; import useSWR from 'swr';
import { createContext } from '@/api/admin/admin';
import { Database, rawDataToDatabase } from '@/api/admin/databases/getDatabases'; import { Database, rawDataToDatabase } from '@/api/admin/databases/getDatabases';
import { Location, rawDataToLocation } from '@/api/admin/locations/getLocations'; import { Location, rawDataToLocation } from '@/api/admin/locations/getLocations';
@ -32,7 +33,7 @@ export interface Node {
relations: { relations: {
databaseHost: Database | undefined; databaseHost: Database | undefined;
location: Location | undefined; location: Location | undefined;
}; }
} }
export const rawDataToNode = ({ attributes }: FractalResponseData): Node => ({ export const rawDataToNode = ({ attributes }: FractalResponseData): Node => ({
@ -77,33 +78,7 @@ export interface Filters {
/* eslint-enable camelcase */ /* eslint-enable camelcase */
} }
interface ctx { export const Context = createContext<Filters>();
page: number;
setPage: (value: number | ((s: number) => number)) => void;
filters: Filters | null;
setFilters: (filters: Filters | null) => void;
sort: string | null;
setSort: (sort: string | null) => void;
sortDirection: boolean;
setSortDirection: (direction: boolean) => void;
}
export const Context = createContext<ctx>({
page: 1,
setPage: () => 1,
filters: null,
setFilters: () => null,
sort: null,
setSort: () => null,
sortDirection: false,
setSortDirection: () => false,
});
export default (include: string[] = []) => { export default (include: string[] = []) => {
const { page, filters, sort, sortDirection } = useContext(Context); const { page, filters, sort, sortDirection } = useContext(Context);

View File

@ -1,6 +1,7 @@
import http, { FractalResponseData, getPaginationSet, PaginatedResult } from '@/api/http'; import http, { FractalResponseData, getPaginationSet, PaginatedResult } from '@/api/http';
import { createContext, useContext } from 'react'; import { useContext } from 'react';
import useSWR from 'swr'; import useSWR from 'swr';
import { createContext } from '@/api/admin/admin';
export interface Role { export interface Role {
id: number; id: number;
@ -19,33 +20,7 @@ export interface Filters {
name?: string; name?: string;
} }
interface ctx { export const Context = createContext<Filters>();
page: number;
setPage: (value: number | ((s: number) => number)) => void;
filters: Filters | null;
setFilters: (filters: Filters | null) => void;
sort: string | null;
setSort: (sort: string | null) => void;
sortDirection: boolean;
setSortDirection: (direction: boolean) => void;
}
export const Context = createContext<ctx>({
page: 1,
setPage: () => 1,
filters: null,
setFilters: () => null,
sort: null,
setSort: () => null,
sortDirection: false,
setSortDirection: () => false,
});
export default (include: string[] = []) => { export default (include: string[] = []) => {
const { page, filters, sort, sortDirection } = useContext(Context); const { page, filters, sort, sortDirection } = useContext(Context);

View File

@ -1,7 +1,8 @@
import { Egg, rawDataToEgg } from '@/api/admin/eggs/getEgg'; import { Egg, rawDataToEgg } from '@/api/admin/eggs/getEgg';
import http, { FractalResponseData, getPaginationSet, PaginatedResult } from '@/api/http'; import http, { FractalResponseData, getPaginationSet, PaginatedResult } from '@/api/http';
import { createContext, useContext } from 'react'; import { useContext } from 'react';
import useSWR from 'swr'; import useSWR from 'swr';
import { createContext } from '@/api/admin/admin';
import { Node, rawDataToNode } from '@/api/admin/nodes/getNodes'; import { Node, rawDataToNode } from '@/api/admin/nodes/getNodes';
import { User, rawDataToUser } from '@/api/admin/users/getUsers'; import { User, rawDataToUser } from '@/api/admin/users/getUsers';
@ -49,7 +50,7 @@ export interface Server {
egg: Egg | undefined; egg: Egg | undefined;
node: Node | undefined; node: Node | undefined;
user: User | undefined; user: User | undefined;
}; }
} }
export const rawDataToServer = ({ attributes }: FractalResponseData): Server => ({ export const rawDataToServer = ({ attributes }: FractalResponseData): Server => ({
@ -109,33 +110,7 @@ export interface Filters {
/* eslint-enable camelcase */ /* eslint-enable camelcase */
} }
interface ctx { export const Context = createContext<Filters>();
page: number;
setPage: (value: number | ((s: number) => number)) => void;
filters: Filters | null;
setFilters: (filters: Filters | null) => void;
sort: string | null;
setSort: (sort: string | null) => void;
sortDirection: boolean;
setSortDirection: (direction: boolean) => void;
}
export const Context = createContext<ctx>({
page: 1,
setPage: () => 1,
filters: null,
setFilters: () => null,
sort: null,
setSort: () => null,
sortDirection: false,
setSortDirection: () => false,
});
export default (include: string[] = []) => { export default (include: string[] = []) => {
const { page, filters, sort, sortDirection } = useContext(Context); const { page, filters, sort, sortDirection } = useContext(Context);

View File

@ -1,6 +1,7 @@
import http, { FractalResponseData, getPaginationSet, PaginatedResult } from '@/api/http'; import http, { FractalResponseData, getPaginationSet, PaginatedResult } from '@/api/http';
import { createContext, useContext } from 'react'; import { useContext } from 'react';
import useSWR from 'swr'; import useSWR from 'swr';
import { createContext } from '@/api/admin/admin';
export interface User { export interface User {
id: number; id: number;
@ -45,33 +46,7 @@ export interface Filters {
lastName?: string; lastName?: string;
} }
interface ctx { export const Context = createContext<Filters>();
page: number;
setPage: (value: number | ((s: number) => number)) => void;
filters: Filters | null;
setFilters: (filters: Filters | null) => void;
sort: string | null;
setSort: (sort: string | null) => void;
sortDirection: boolean;
setSortDirection: (direction: boolean) => void;
}
export const Context = createContext<ctx>({
page: 1,
setPage: () => 1,
filters: null,
setFilters: () => null,
sort: null,
setSort: () => null,
sortDirection: false,
setSortDirection: () => false,
});
export default (include: string[] = []) => { export default (include: string[] = []) => {
const { page, filters, sort, sortDirection } = useContext(Context); const { page, filters, sort, sortDirection } = useContext(Context);

View File

@ -8,6 +8,38 @@ import styled from 'styled-components/macro';
import tw from 'twin.macro'; import tw from 'twin.macro';
import { PaginatedResult, PaginationDataSet } from '@/api/http'; import { PaginatedResult, PaginationDataSet } from '@/api/http';
interface Hooks<T> {
page: number;
setPage: (page: ((p: number) => number) | number) => void;
filters: T | null;
setFilters: (filters: ((f: T | null) => T | null) | T | null) => void;
sort: string | null;
setSort: (sort: string | null) => void;
sortDirection: boolean;
setSortDirection: (direction: ((p: boolean) => boolean) | boolean) => void;
}
export function useTableHooks<T> (): Hooks<T> {
const [ page, setPage ] = useState<number>(1);
const [ filters, setFilters ] = useState<T | null>(null);
const [ sort, setSortState ] = useState<string | null>(null);
const [ sortDirection, setSortDirection ] = useState<boolean>(false);
const setSort = (newSort: string | null) => {
if (sort === newSort) {
setSortDirection(!sortDirection);
} else {
setSortState(newSort);
setSortDirection(false);
}
};
return { page, setPage, filters, setFilters, sort, setSort, sortDirection, setSortDirection };
}
export const TableHeader = ({ name, onClick, direction }: { name?: string, onClick?: (e: React.MouseEvent) => void, direction?: number | null }) => { export const TableHeader = ({ name, onClick, direction }: { name?: string, onClick?: (e: React.MouseEvent) => void, direction?: number | null }) => {
if (!name) { if (!name) {
return <th css={tw`px-6 py-2`}/>; return <th css={tw`px-6 py-2`}/>;

View File

@ -7,7 +7,17 @@ import { NavLink, useRouteMatch } from 'react-router-dom';
import tw from 'twin.macro'; import tw from 'twin.macro';
import AdminContentBlock from '@/components/admin/AdminContentBlock'; import AdminContentBlock from '@/components/admin/AdminContentBlock';
import AdminCheckbox from '@/components/admin/AdminCheckbox'; import AdminCheckbox from '@/components/admin/AdminCheckbox';
import AdminTable, { TableBody, TableHead, TableHeader, TableRow, Pagination, Loading, NoItems, ContentWrapper } from '@/components/admin/AdminTable'; import AdminTable, {
TableBody,
TableHead,
TableHeader,
TableRow,
Pagination,
Loading,
NoItems,
ContentWrapper,
useTableHooks
} from '@/components/admin/AdminTable';
import Button from '@/components/elements/Button'; import Button from '@/components/elements/Button';
import CopyOnClick from '@/components/elements/CopyOnClick'; import CopyOnClick from '@/components/elements/CopyOnClick';
@ -156,22 +166,10 @@ const DatabasesContainer = () => {
}; };
export default () => { export default () => {
const [ page, setPage ] = useState<number>(1); const hooks = useTableHooks<Filters>();
const [ filters, setFilters ] = useState<Filters | null>(null);
const [ sort, setSortState ] = useState<string | null>(null);
const [ sortDirection, setSortDirection ] = useState<boolean>(false);
const setSort = (newSort: string | null) => {
if (sort === newSort) {
setSortDirection(!sortDirection);
} else {
setSortState(newSort);
setSortDirection(false);
}
};
return ( return (
<DatabasesContext.Provider value={{ page, setPage, filters, setFilters, sort, setSort, sortDirection, setSortDirection }}> <DatabasesContext.Provider value={hooks}>
<DatabasesContainer/> <DatabasesContainer/>
</DatabasesContext.Provider> </DatabasesContext.Provider>
); );

View File

@ -7,7 +7,17 @@ import { NavLink, useRouteMatch } from 'react-router-dom';
import tw from 'twin.macro'; import tw from 'twin.macro';
import AdminContentBlock from '@/components/admin/AdminContentBlock'; import AdminContentBlock from '@/components/admin/AdminContentBlock';
import AdminCheckbox from '@/components/admin/AdminCheckbox'; import AdminCheckbox from '@/components/admin/AdminCheckbox';
import AdminTable, { TableBody, TableHead, TableHeader, TableRow, Pagination, Loading, NoItems, ContentWrapper } from '@/components/admin/AdminTable'; import AdminTable, {
TableBody,
TableHead,
TableHeader,
TableRow,
Pagination,
Loading,
NoItems,
ContentWrapper,
useTableHooks
} from '@/components/admin/AdminTable';
import NewLocationButton from '@/components/admin/locations/NewLocationButton'; import NewLocationButton from '@/components/admin/locations/NewLocationButton';
import CopyOnClick from '@/components/elements/CopyOnClick'; import CopyOnClick from '@/components/elements/CopyOnClick';
@ -145,22 +155,10 @@ const LocationsContainer = () => {
}; };
export default () => { export default () => {
const [ page, setPage ] = useState<number>(1); const hooks = useTableHooks<Filters>();
const [ filters, setFilters ] = useState<Filters | null>(null);
const [ sort, setSortState ] = useState<string | null>(null);
const [ sortDirection, setSortDirection ] = useState<boolean>(false);
const setSort = (newSort: string | null) => {
if (sort === newSort) {
setSortDirection(!sortDirection);
} else {
setSortState(newSort);
setSortDirection(false);
}
};
return ( return (
<LocationsContext.Provider value={{ page, setPage, filters, setFilters, sort, setSort, sortDirection, setSortDirection }}> <LocationsContext.Provider value={hooks}>
<LocationsContainer/> <LocationsContainer/>
</LocationsContext.Provider> </LocationsContext.Provider>
); );

View File

@ -7,7 +7,17 @@ import { NavLink, useRouteMatch } from 'react-router-dom';
import tw from 'twin.macro'; import tw from 'twin.macro';
import AdminContentBlock from '@/components/admin/AdminContentBlock'; import AdminContentBlock from '@/components/admin/AdminContentBlock';
import AdminCheckbox from '@/components/admin/AdminCheckbox'; import AdminCheckbox from '@/components/admin/AdminCheckbox';
import AdminTable, { TableBody, TableHead, TableHeader, TableRow, Pagination, Loading, NoItems, ContentWrapper } from '@/components/admin/AdminTable'; import AdminTable, {
TableBody,
TableHead,
TableHeader,
TableRow,
Pagination,
Loading,
NoItems,
ContentWrapper,
useTableHooks
} from '@/components/admin/AdminTable';
import Button from '@/components/elements/Button'; import Button from '@/components/elements/Button';
import CopyOnClick from '@/components/elements/CopyOnClick'; import CopyOnClick from '@/components/elements/CopyOnClick';
@ -185,22 +195,10 @@ const MountsContainer = () => {
}; };
export default () => { export default () => {
const [ page, setPage ] = useState<number>(1); const hooks = useTableHooks<Filters>();
const [ filters, setFilters ] = useState<Filters | null>(null);
const [ sort, setSortState ] = useState<string | null>(null);
const [ sortDirection, setSortDirection ] = useState<boolean>(false);
const setSort = (newSort: string | null) => {
if (sort === newSort) {
setSortDirection(!sortDirection);
} else {
setSortState(newSort);
setSortDirection(false);
}
};
return ( return (
<MountsContext.Provider value={{ page, setPage, filters, setFilters, sort, setSort, sortDirection, setSortDirection }}> <MountsContext.Provider value={hooks}>
<MountsContainer/> <MountsContainer/>
</MountsContext.Provider> </MountsContext.Provider>
); );

View File

@ -5,7 +5,17 @@ import useFlash from '@/plugins/useFlash';
import { NavLink, useRouteMatch } from 'react-router-dom'; import { NavLink, useRouteMatch } from 'react-router-dom';
import tw from 'twin.macro'; import tw from 'twin.macro';
import AdminCheckbox from '@/components/admin/AdminCheckbox'; import AdminCheckbox from '@/components/admin/AdminCheckbox';
import AdminTable, { TableBody, TableHead, TableHeader, TableRow, Pagination, Loading, NoItems, ContentWrapper } from '@/components/admin/AdminTable'; import AdminTable, {
TableBody,
TableHead,
TableHeader,
TableRow,
Pagination,
Loading,
NoItems,
ContentWrapper,
useTableHooks
} from '@/components/admin/AdminTable';
import { Context } from '@/components/admin/nests/NestEditContainer'; import { Context } from '@/components/admin/nests/NestEditContainer';
const RowCheckbox = ({ id }: { id: number}) => { const RowCheckbox = ({ id }: { id: number}) => {
@ -127,22 +137,10 @@ const EggsTable = () => {
}; };
export default () => { export default () => {
const [ page, setPage ] = useState<number>(1); const hooks = useTableHooks<Filters>();
const [ filters, setFilters ] = useState<Filters | null>(null);
const [ sort, setSortState ] = useState<string | null>(null);
const [ sortDirection, setSortDirection ] = useState<boolean>(false);
const setSort = (newSort: string | null) => {
if (sort === newSort) {
setSortDirection(!sortDirection);
} else {
setSortState(newSort);
setSortDirection(false);
}
};
return ( return (
<EggsContext.Provider value={{ page, setPage, filters, setFilters, sort, setSort, sortDirection, setSortDirection }}> <EggsContext.Provider value={hooks}>
<EggsTable/> <EggsTable/>
</EggsContext.Provider> </EggsContext.Provider>
); );

View File

@ -9,7 +9,17 @@ import { NavLink, useRouteMatch } from 'react-router-dom';
import tw from 'twin.macro'; import tw from 'twin.macro';
import AdminContentBlock from '@/components/admin/AdminContentBlock'; import AdminContentBlock from '@/components/admin/AdminContentBlock';
import AdminCheckbox from '@/components/admin/AdminCheckbox'; import AdminCheckbox from '@/components/admin/AdminCheckbox';
import AdminTable, { TableBody, TableHead, TableHeader, TableRow, Pagination, Loading, NoItems, ContentWrapper } from '@/components/admin/AdminTable'; import AdminTable, {
TableBody,
TableHead,
TableHeader,
TableRow,
Pagination,
Loading,
NoItems,
ContentWrapper,
useTableHooks
} from '@/components/admin/AdminTable';
const RowCheckbox = ({ id }: { id: number}) => { const RowCheckbox = ({ id }: { id: number}) => {
const isChecked = AdminContext.useStoreState(state => state.nests.selectedNests.indexOf(id) >= 0); const isChecked = AdminContext.useStoreState(state => state.nests.selectedNests.indexOf(id) >= 0);
@ -145,22 +155,10 @@ const NestsContainer = () => {
}; };
export default () => { export default () => {
const [ page, setPage ] = useState<number>(1); const hooks = useTableHooks<Filters>();
const [ filters, setFilters ] = useState<Filters | null>(null);
const [ sort, setSortState ] = useState<string | null>(null);
const [ sortDirection, setSortDirection ] = useState<boolean>(false);
const setSort = (newSort: string | null) => {
if (sort === newSort) {
setSortDirection(!sortDirection);
} else {
setSortState(newSort);
setSortDirection(false);
}
};
return ( return (
<NestsContext.Provider value={{ page, setPage, filters, setFilters, sort, setSort, sortDirection, setSortDirection }}> <NestsContext.Provider value={hooks}>
<NestsContainer/> <NestsContainer/>
</NestsContext.Provider> </NestsContext.Provider>
); );

View File

@ -8,7 +8,17 @@ import { NavLink, useRouteMatch } from 'react-router-dom';
import tw from 'twin.macro'; import tw from 'twin.macro';
import AdminContentBlock from '@/components/admin/AdminContentBlock'; import AdminContentBlock from '@/components/admin/AdminContentBlock';
import AdminCheckbox from '@/components/admin/AdminCheckbox'; import AdminCheckbox from '@/components/admin/AdminCheckbox';
import AdminTable, { TableBody, TableHead, TableHeader, TableRow, Pagination, Loading, NoItems, ContentWrapper } from '@/components/admin/AdminTable'; import AdminTable, {
TableBody,
TableHead,
TableHeader,
TableRow,
Pagination,
Loading,
NoItems,
ContentWrapper,
useTableHooks
} from '@/components/admin/AdminTable';
import Button from '@/components/elements/Button'; import Button from '@/components/elements/Button';
import CopyOnClick from '@/components/elements/CopyOnClick'; import CopyOnClick from '@/components/elements/CopyOnClick';
import { bytesToHuman, megabytesToBytes } from '@/helpers'; import { bytesToHuman, megabytesToBytes } from '@/helpers';
@ -196,22 +206,10 @@ const NodesContainer = () => {
}; };
export default () => { export default () => {
const [ page, setPage ] = useState<number>(1); const hooks = useTableHooks<Filters>();
const [ filters, setFilters ] = useState<Filters | null>(null);
const [ sort, setSortState ] = useState<string | null>(null);
const [ sortDirection, setSortDirection ] = useState<boolean>(false);
const setSort = (newSort: string | null) => {
if (sort === newSort) {
setSortDirection(!sortDirection);
} else {
setSortState(newSort);
setSortDirection(false);
}
};
return ( return (
<NodesContext.Provider value={{ page, setPage, filters, setFilters, sort, setSort, sortDirection, setSortDirection }}> <NodesContext.Provider value={hooks}>
<NodesContainer/> <NodesContainer/>
</NodesContext.Provider> </NodesContext.Provider>
); );

View File

@ -8,7 +8,17 @@ import { NavLink, useRouteMatch } from 'react-router-dom';
import tw from 'twin.macro'; import tw from 'twin.macro';
import AdminContentBlock from '@/components/admin/AdminContentBlock'; import AdminContentBlock from '@/components/admin/AdminContentBlock';
import AdminCheckbox from '@/components/admin/AdminCheckbox'; import AdminCheckbox from '@/components/admin/AdminCheckbox';
import AdminTable, { TableBody, TableHead, TableHeader, TableRow, Pagination, Loading, NoItems, ContentWrapper } from '@/components/admin/AdminTable'; import AdminTable, {
TableBody,
TableHead,
TableHeader,
TableRow,
Pagination,
Loading,
NoItems,
ContentWrapper,
useTableHooks
} from '@/components/admin/AdminTable';
import CopyOnClick from '@/components/elements/CopyOnClick'; import CopyOnClick from '@/components/elements/CopyOnClick';
const RowCheckbox = ({ id }: { id: number }) => { const RowCheckbox = ({ id }: { id: number }) => {
@ -145,22 +155,10 @@ const RolesContainer = () => {
}; };
export default () => { export default () => {
const [ page, setPage ] = useState<number>(1); const hooks = useTableHooks<Filters>();
const [ filters, setFilters ] = useState<Filters | null>(null);
const [ sort, setSortState ] = useState<string | null>(null);
const [ sortDirection, setSortDirection ] = useState<boolean>(false);
const setSort = (newSort: string | null) => {
if (sort === newSort) {
setSortDirection(!sortDirection);
} else {
setSortState(newSort);
setSortDirection(false);
}
};
return ( return (
<RolesContext.Provider value={{ page, setPage, filters, setFilters, sort, setSort, sortDirection, setSortDirection }}> <RolesContext.Provider value={hooks}>
<RolesContainer/> <RolesContainer/>
</RolesContext.Provider> </RolesContext.Provider>
); );

View File

@ -1,7 +1,16 @@
import React, { useContext, useEffect, useState } from 'react'; import React, { useContext, useEffect, useState } from 'react';
import getServers, { Context as ServersContext, Filters } from '@/api/admin/servers/getServers'; import getServers, { Context as ServersContext, Filters } from '@/api/admin/servers/getServers';
import AdminCheckbox from '@/components/admin/AdminCheckbox'; import AdminCheckbox from '@/components/admin/AdminCheckbox';
import AdminTable, { ContentWrapper, Loading, NoItems, Pagination, TableBody, TableHead, TableHeader } from '@/components/admin/AdminTable'; import AdminTable, {
ContentWrapper,
Loading,
NoItems,
Pagination,
TableBody,
TableHead,
TableHeader,
useTableHooks
} from '@/components/admin/AdminTable';
import Button from '@/components/elements/Button'; import Button from '@/components/elements/Button';
import CopyOnClick from '@/components/elements/CopyOnClick'; import CopyOnClick from '@/components/elements/CopyOnClick';
import FlashMessageRender from '@/components/FlashMessageRender'; import FlashMessageRender from '@/components/FlashMessageRender';
@ -196,22 +205,10 @@ const ServersContainer = () => {
}; };
export default () => { export default () => {
const [ page, setPage ] = useState<number>(1); const hooks = useTableHooks<Filters>();
const [ filters, setFilters ] = useState<Filters | null>(null);
const [ sort, setSortState ] = useState<string | null>(null);
const [ sortDirection, setSortDirection ] = useState<boolean>(false);
const setSort = (newSort: string | null) => {
if (sort === newSort) {
setSortDirection(!sortDirection);
} else {
setSortState(newSort);
setSortDirection(false);
}
};
return ( return (
<ServersContext.Provider value={{ page, setPage, filters, setFilters, sort, setSort, sortDirection, setSortDirection }}> <ServersContext.Provider value={hooks}>
<ServersContainer/> <ServersContainer/>
</ServersContext.Provider> </ServersContext.Provider>
); );

View File

@ -2,7 +2,16 @@ import React, { useContext, useEffect, useState } from 'react';
import AdminCheckbox from '@/components/admin/AdminCheckbox'; import AdminCheckbox from '@/components/admin/AdminCheckbox';
import CopyOnClick from '@/components/elements/CopyOnClick'; import CopyOnClick from '@/components/elements/CopyOnClick';
import getUsers, { Context as UsersContext, Filters } from '@/api/admin/users/getUsers'; import getUsers, { Context as UsersContext, Filters } from '@/api/admin/users/getUsers';
import AdminTable, { ContentWrapper, Loading, NoItems, Pagination, TableBody, TableHead, TableHeader } from '@/components/admin/AdminTable'; import AdminTable, {
ContentWrapper,
Loading,
NoItems,
Pagination,
TableBody,
TableHead,
TableHeader,
useTableHooks
} from '@/components/admin/AdminTable';
import Button from '@/components/elements/Button'; import Button from '@/components/elements/Button';
import FlashMessageRender from '@/components/FlashMessageRender'; import FlashMessageRender from '@/components/FlashMessageRender';
import useFlash from '@/plugins/useFlash'; import useFlash from '@/plugins/useFlash';
@ -173,22 +182,10 @@ const UsersContainer = () => {
}; };
export default () => { export default () => {
const [ page, setPage ] = useState<number>(1); const hooks = useTableHooks<Filters>();
const [ filters, setFilters ] = useState<Filters | null>(null);
const [ sort, setSortState ] = useState<string | null>(null);
const [ sortDirection, setSortDirection ] = useState<boolean>(false);
const setSort = (newSort: string | null) => {
if (sort === newSort) {
setSortDirection(!sortDirection);
} else {
setSortState(newSort);
setSortDirection(false);
}
};
return ( return (
<UsersContext.Provider value={{ page, setPage, filters, setFilters, sort, setSort, sortDirection, setSortDirection }}> <UsersContext.Provider value={hooks}>
<UsersContainer/> <UsersContainer/>
</UsersContext.Provider> </UsersContext.Provider>
); );