import { TranslatedString } from "@gnu-taler/taler-util"; import { useTranslationContext } from "@gnu-taler/web-util/browser"; import { h, VNode } from "preact"; import { useState } from "preact/hooks"; export function JumpToElementById({ testIfExist, onSelect, placeholder, description }: { placeholder: TranslatedString, description: TranslatedString, testIfExist: (id: string) => Promise, onSelect: (id: string) => void }): VNode { const { i18n } = useTranslationContext() const [error, setError] = useState( undefined, ); const [id, setId] = useState() async function check(currentId: string | undefined): Promise { if (!currentId) { setError(i18n.str`missing id`); return; } try { const exi = await testIfExist(currentId); if (exi) { onSelect(currentId); setError(undefined); } else { setError(i18n.str`not found`); } } catch { setError(i18n.str`not found`); } } return
setId(e.currentTarget.value)} placeholder={placeholder} /> {error &&

{error}

}
}