mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-02-27 04:06:39 +00:00
Update shlink-frontend-kit and shlink-web-component
This commit is contained in:
@@ -1,35 +1,6 @@
|
||||
import { parseQuery } from '@shlinkio/shlink-frontend-kit';
|
||||
import { useCallback, useRef, useState } from 'react';
|
||||
import { useLocation, useNavigate } from 'react-router-dom';
|
||||
|
||||
const DEFAULT_DELAY = 2000;
|
||||
|
||||
export type TimeoutToggle = typeof useTimeoutToggle;
|
||||
|
||||
export const useTimeoutToggle = (
|
||||
initialValue = false,
|
||||
delay = DEFAULT_DELAY,
|
||||
|
||||
// Test seams
|
||||
setTimeout = window.setTimeout,
|
||||
clearTimeout = window.clearTimeout,
|
||||
): [boolean, () => void] => {
|
||||
const [flag, setFlag] = useState<boolean>(initialValue);
|
||||
const initialValueRef = useRef(initialValue);
|
||||
const timeout = useRef<number | undefined>(undefined);
|
||||
const callback = useCallback(() => {
|
||||
setFlag(!initialValueRef.current);
|
||||
|
||||
if (timeout.current) {
|
||||
clearTimeout(timeout.current);
|
||||
}
|
||||
|
||||
timeout.current = setTimeout(() => setFlag(initialValueRef.current), delay);
|
||||
}, [clearTimeout, delay, setTimeout]);
|
||||
|
||||
return [flag, callback];
|
||||
};
|
||||
|
||||
export const useGoBack = () => {
|
||||
const navigate = useNavigate();
|
||||
return () => navigate(-1);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useTimeoutToggle } from '@shlinkio/shlink-frontend-kit';
|
||||
import type Bottle from 'bottlejs';
|
||||
import { csvToJson, jsonToCsv } from '../helpers/csvjson';
|
||||
import { useTimeoutToggle } from '../helpers/hooks';
|
||||
import { LocalStorage } from './LocalStorage';
|
||||
import { TagColorsStorage } from './TagColorsStorage';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user