diff --git a/pkg/interface/src/lib/useDropdown.ts b/pkg/interface/src/lib/useDropdown.ts deleted file mode 100644 index da54bd100..000000000 --- a/pkg/interface/src/lib/useDropdown.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { useState, useEffect, useMemo, useCallback } from "react"; - -export function useDropdown( - candidates: C[], - key: (c: C) => string, - searchPred: (query: string, c: C) => boolean -) { - const [options, setOptions] = useState(candidates); - const [selected, setSelected] = useState(); - const search = useCallback( - (s: string) => { - const opts = candidates.filter((c) => searchPred(s, c)); - setOptions(opts); - if (selected) { - const idx = opts.findIndex((c) => key(c) === key(selected)); - console.log(idx); - if (idx < 0) { - setSelected(undefined); - } - } - }, - [candidates, searchPred, key, selected, setOptions, setSelected] - ); - - const changeSelection = useCallback( - (backward = false) => { - const select = (idx: number) => { - setSelected(options[idx]); - }; - if(!selected) { select(0); return false; } - - const idx = options.findIndex((c) => key(c) === key(selected)); - if ( - idx === -1 || - (options.length - 1 <= idx && !backward) - ) { - select(0); - } else if (idx === 0 && backward) { - select(options.length - 1); - } else { - select(idx + (backward ? -1 : 1)); - } - return false; - }, - [options, setSelected, selected] - ); - - const next = useCallback(() => changeSelection(), [changeSelection]); - const back = useCallback(() => changeSelection(true), [changeSelection]); - - return { - next, - back, - search, - selected, - options, - }; -} diff --git a/pkg/interface/src/lib/useLocalStorageState.ts b/pkg/interface/src/lib/useLocalStorageState.ts deleted file mode 100644 index a3f81c666..000000000 --- a/pkg/interface/src/lib/useLocalStorageState.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { useState, useCallback } from 'react'; - -export function useLocalStorageState(key: string, initial: T) { - const [state, _setState] = useState(() => { - const s = localStorage.getItem(key); - if(s) { - return JSON.parse(s) as T; - } - return initial; - - }); - - const setState = useCallback((s: T) => { - _setState(s); - localStorage.setItem(key, JSON.stringify(s)); - - }, [_setState]); - - return [state, setState] as const; -} - - diff --git a/pkg/interface/src/lib/useQuery.ts b/pkg/interface/src/lib/useQuery.ts deleted file mode 100644 index 0957ca098..000000000 --- a/pkg/interface/src/lib/useQuery.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { useMemo, useCallback } from "react"; -import { useLocation } from "react-router-dom"; -import _ from 'lodash'; - -export function useQuery() { - const { search } = useLocation(); - - const query = useMemo(() => new URLSearchParams(search), [search]); - - const appendQuery = useCallback( - (q: Record) => { - const newQuery = new URLSearchParams(search); - _.forIn(q, (value, key) => { - if (!value) { - newQuery.delete(key); - } else { - newQuery.append(key, value); - } - }); - - return newQuery.toString(); - }, - [search] - ); - - return { - query, - appendQuery, - }; -} diff --git a/pkg/interface/src/lib/useWaitForProps.ts b/pkg/interface/src/lib/useWaitForProps.ts deleted file mode 100644 index 5a2d752e6..000000000 --- a/pkg/interface/src/lib/useWaitForProps.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { useState, useEffect, useCallback } from 'react'; - - -export function useWaitForProps

(props: P, timeout: number) { - const [resolve, setResolve] = useState<() => void>(() => () => {}); - const [ready, setReady] = useState<(p: P) => boolean | undefined>(); - - useEffect(() => { - if (typeof ready === "function" && ready(props)) { - resolve(); - } - }, [props, ready, resolve]); - - /** - * Waits until some predicate is true - * - * @param r - Predicate to wait for - * @returns A promise that resolves when `r` returns true, or rejects if the - * waiting times out - * - */ - const waiter = useCallback( - (r: (props: P) => boolean) => { - setReady(() => r); - return new Promise((resolve, reject) => { - setResolve(() => resolve); - setTimeout(() => { - reject(new Error("Timed out")); - }, timeout); - }); - }, - [setResolve, setReady, timeout] - ); - - return waiter; -}