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,3 +1,4 @@
import type { TimeoutToggle } from '@shlinkio/shlink-frontend-kit';
import { Result, useToggle } from '@shlinkio/shlink-frontend-kit';
import type { FC } from 'react';
import { useCallback, useEffect, useState } from 'react';
@@ -7,7 +8,6 @@ import { v4 as uuid } from 'uuid';
import { NoMenuLayout } from '../common/NoMenuLayout';
import type { FCWithDeps } from '../container/utils';
import { componentFactory, useDependencies } from '../container/utils';
import type { TimeoutToggle } from '../utils/helpers/hooks';
import { useGoBack } from '../utils/helpers/hooks';
import type { ServerData, ServersMap, ServerWithId } from './data';
import { DuplicatedServersModal } from './helpers/DuplicatedServersModal';

View File

@@ -1,5 +1,6 @@
import { faFileDownload as exportIcon, faPlus as plusIcon } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import type { TimeoutToggle } from '@shlinkio/shlink-frontend-kit';
import { Result, SearchField, SimpleCard } from '@shlinkio/shlink-frontend-kit';
import type { FC } from 'react';
import { useEffect, useState } from 'react';
@@ -8,7 +9,6 @@ import { Button, Row } from 'reactstrap';
import { NoMenuLayout } from '../common/NoMenuLayout';
import type { FCWithDeps } from '../container/utils';
import { componentFactory, useDependencies } from '../container/utils';
import type { TimeoutToggle } from '../utils/helpers/hooks';
import type { ServersMap } from './data';
import type { ImportServersBtnProps } from './helpers/ImportServersBtn';
import type { ManageServersRowProps } from './ManageServersRow';

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