diff --git a/src/components/form/LookupInput.tsx b/src/components/form/LookupInput.tsx index a2096ee..d64fe65 100644 --- a/src/components/form/LookupInput.tsx +++ b/src/components/form/LookupInput.tsx @@ -152,7 +152,7 @@ const LookupInput: FunctionComponent = ({
= ({ {/* Fetch special text for 'auto' mode, otherwise just use the options. */} {selected == "auto" - ? detectedType.unwrapOr("???") + // If the detected type was provided, then notate which in parentheses. Compact object naming might be better in the future. + ? (detectedType.isJust ? `Auto (${objectNames[detectedType.value]})` : objectNames["auto"]) : objectNames[selected]} diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 7708fda..3db681f 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -7,9 +7,12 @@ import { OGP } from "react-ogp"; import LookupInput from "@/components/form/LookupInput"; import ErrorCard from "@/components/common/ErrorCard"; import { Maybe } from "true-myth"; +import type { ObjectType } from "@/types"; +import { getType } from "@/rdap"; const Index: NextPage = () => { const { error, setTarget, submit } = useLookup(); + const [detectedType, setDetectedType] = useState>(Maybe.nothing()); const [response, setResponse] = useState(); const [isLoading, setLoading] = useState(false); @@ -41,9 +44,20 @@ const Index: NextPage = () => {
{ setTarget(target); + + const detectResult = getType(target); + if (detectResult.isOk) { + const value = detectResult.value; + if (value == "ip4" || value == "ip6") + setDetectedType(Maybe.just("ip")); + else + setDetectedType(Maybe.just(value)); + } else { + setDetectedType(Maybe.nothing()); + } }} onSubmit={async function (props) { try {