mirror of
https://github.com/umami-software/umami.git
synced 2026-02-06 05:37:20 +01:00
Added useFilterQuery. Converted websites and reports pages.
This commit is contained in:
parent
6846355c63
commit
7e626dcd52
29 changed files with 373 additions and 499 deletions
|
|
@ -1,13 +0,0 @@
|
|||
import { useState } from 'react';
|
||||
import { usePaging } from 'components/hooks/usePaging';
|
||||
|
||||
export function useDataTable(config = {}) {
|
||||
const { initialData, initialQuery, initialPageInfo } = config;
|
||||
const [data, setData] = useState(initialData ?? null);
|
||||
const [query, setQuery] = useState(initialQuery ?? '');
|
||||
const { pageInfo, setPageInfo } = usePaging(initialPageInfo);
|
||||
|
||||
return { data, setData, query, setQuery, pageInfo, setPageInfo };
|
||||
}
|
||||
|
||||
export default useDataTable;
|
||||
16
src/components/hooks/useFilterQuery.js
Normal file
16
src/components/hooks/useFilterQuery.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import { useState } from 'react';
|
||||
import { useApi } from 'components/hooks/useApi';
|
||||
|
||||
export function useFilterQuery(key, fn, options) {
|
||||
const [params, setParams] = useState({
|
||||
query: '',
|
||||
page: 1,
|
||||
});
|
||||
const { useQuery } = useApi();
|
||||
|
||||
const result = useQuery([...key, params], fn.bind(null, params), options);
|
||||
|
||||
return { ...result, params, setParams };
|
||||
}
|
||||
|
||||
export default useFilterQuery;
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
import { useState } from 'react';
|
||||
|
||||
const DEFAULT_PAGE_INFO = { page: 1, pageSize: 10, total: 0 };
|
||||
|
||||
export function usePaging(initialPageInfo) {
|
||||
const [pageInfo, setPageInfo] = useState(initialPageInfo ?? { ...DEFAULT_PAGE_INFO });
|
||||
|
||||
return { pageInfo, setPageInfo };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue