mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Use next-basics package.
This commit is contained in:
parent
1a6af8fc41
commit
f4e0da481e
62 changed files with 255 additions and 373 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { useCallback } from 'react';
|
||||
import { useRouter } from 'next/router';
|
||||
import { get, post, put, del, getItem } from 'lib/web';
|
||||
import { get, post, put, del, getItem } from 'next-basics';
|
||||
import { AUTH_TOKEN, SHARE_TOKEN_HEADER } from 'lib/constants';
|
||||
import useStore from 'store/app';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { useState, useEffect } from 'react';
|
||||
import { useRouter } from 'next/router';
|
||||
import { get } from 'lib/web';
|
||||
import { get } from 'next-basics';
|
||||
import enUS from 'public/intl/country/en-US.json';
|
||||
|
||||
const countryNames = {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { useCallback, useMemo } from 'react';
|
||||
import { parseISO } from 'date-fns';
|
||||
import { getDateRange } from 'lib/date';
|
||||
import { getItem, setItem } from 'lib/web';
|
||||
import { getItem, setItem } from 'next-basics';
|
||||
import { DATE_RANGE_CONFIG, DEFAULT_DATE_RANGE } from 'lib/constants';
|
||||
import useForceUpdate from './useForceUpdate';
|
||||
import useLocale from './useLocale';
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ export default function useFetch(url, options = {}, update = []) {
|
|||
const [loading, setLoading] = useState(false);
|
||||
const [count, setCount] = useState(0);
|
||||
const { get } = useApi();
|
||||
const { params = {}, headers = {}, disabled, delay = 0, interval, onDataLoad } = options;
|
||||
const { params = {}, headers = {}, disabled = false, delay = 0, interval, onDataLoad } = options;
|
||||
|
||||
async function loadData(params) {
|
||||
try {
|
||||
|
|
@ -29,7 +29,9 @@ export default function useFetch(url, options = {}, update = []) {
|
|||
|
||||
onDataLoad?.(data);
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(e);
|
||||
|
||||
setError(e);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
|
|
@ -44,7 +46,7 @@ export default function useFetch(url, options = {}, update = []) {
|
|||
clearTimeout(id);
|
||||
};
|
||||
}
|
||||
}, [url, !!disabled, count, ...update]);
|
||||
}, [url, disabled, count, ...update]);
|
||||
|
||||
useEffect(() => {
|
||||
if (interval && !disabled) {
|
||||
|
|
@ -54,7 +56,7 @@ export default function useFetch(url, options = {}, update = []) {
|
|||
clearInterval(id);
|
||||
};
|
||||
}
|
||||
}, [interval, !!disabled]);
|
||||
}, [interval, disabled]);
|
||||
|
||||
return { ...response, error, loading };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { useState, useEffect } from 'react';
|
||||
import { useRouter } from 'next/router';
|
||||
import { get } from 'lib/web';
|
||||
import { get } from 'next-basics';
|
||||
import enUS from 'public/intl/language/en-US.json';
|
||||
|
||||
const languageNames = {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { useEffect } from 'react';
|
||||
import { useRouter } from 'next/router';
|
||||
import { get, setItem } from 'lib/web';
|
||||
import { get, setItem } from 'next-basics';
|
||||
import { LOCALE_CONFIG } from 'lib/constants';
|
||||
import { getDateLocale, getTextDirection } from 'lib/lang';
|
||||
import useStore, { setLocale } from 'store/app';
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
import { useMemo } from 'react';
|
||||
import { useRouter } from 'next/router';
|
||||
import { getQueryString } from 'lib/url';
|
||||
|
||||
function getQueryString(params) {
|
||||
return new URLSearchParams({ ...params }).toString();
|
||||
}
|
||||
|
||||
export default function usePageQuery() {
|
||||
const router = useRouter();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { useEffect } from 'react';
|
||||
import useStore, { setTheme } from 'store/app';
|
||||
import { getItem, setItem } from 'lib/web';
|
||||
import { getItem, setItem } from 'next-basics';
|
||||
import { THEME_CONFIG } from 'lib/constants';
|
||||
|
||||
const selector = state => state.theme;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { useState, useCallback } from 'react';
|
||||
import { getTimezone } from 'lib/date';
|
||||
import { getItem, setItem } from 'lib/web';
|
||||
import { getItem, setItem } from 'next-basics';
|
||||
import { TIMEZONE_CONFIG } from 'lib/constants';
|
||||
|
||||
export default function useTimezone() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue