Update shlink-frontend-kit and shlink-web-component

This commit is contained in:
Alejandro Celaya
2023-09-05 20:38:51 +02:00
parent b71b14a4fd
commit abe1d78ee0
6 changed files with 20 additions and 49 deletions

View File

@@ -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);

View File

@@ -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';