mirror of
https://github.com/Xevion/rdap.git
synced 2025-12-12 05:11:04 -06:00
Simplify ip4/ip6 handling with refined TargetType
This commit is contained in:
@@ -7,12 +7,12 @@ import { OGP } from "react-ogp";
|
|||||||
import LookupInput from "@/components/form/LookupInput";
|
import LookupInput from "@/components/form/LookupInput";
|
||||||
import ErrorCard from "@/components/common/ErrorCard";
|
import ErrorCard from "@/components/common/ErrorCard";
|
||||||
import { Maybe } from "true-myth";
|
import { Maybe } from "true-myth";
|
||||||
import type { ObjectType } from "@/types";
|
import type { TargetType } from "@/types";
|
||||||
import { getType } from "@/rdap";
|
import { getType } from "@/rdap";
|
||||||
|
|
||||||
const Index: NextPage = () => {
|
const Index: NextPage = () => {
|
||||||
const { error, setTarget, submit } = useLookup();
|
const { error, setTarget, setTargetType, submit } = useLookup();
|
||||||
const [detectedType, setDetectedType] = useState<Maybe<ObjectType>>(Maybe.nothing());
|
const [detectedType, setDetectedType] = useState<Maybe<TargetType>>(Maybe.nothing());
|
||||||
const [response, setResponse] = useState<ParsedGeneric | null>();
|
const [response, setResponse] = useState<ParsedGeneric | null>();
|
||||||
const [isLoading, setLoading] = useState<boolean>(false);
|
const [isLoading, setLoading] = useState<boolean>(false);
|
||||||
|
|
||||||
@@ -47,14 +47,11 @@ const Index: NextPage = () => {
|
|||||||
detectedType={detectedType}
|
detectedType={detectedType}
|
||||||
onChange={({ target, targetType }) => {
|
onChange={({ target, targetType }) => {
|
||||||
setTarget(target);
|
setTarget(target);
|
||||||
|
setTargetType(targetType);
|
||||||
|
|
||||||
const detectResult = getType(target);
|
const detectResult = getType(target);
|
||||||
if (detectResult.isOk) {
|
if (detectResult.isOk) {
|
||||||
const value = detectResult.value;
|
setDetectedType(Maybe.just(detectResult.value));
|
||||||
if (value == "ip4" || value == "ip6")
|
|
||||||
setDetectedType(Maybe.just("ip"));
|
|
||||||
else
|
|
||||||
setDetectedType(Maybe.just(value));
|
|
||||||
} else {
|
} else {
|
||||||
setDetectedType(Maybe.nothing());
|
setDetectedType(Maybe.nothing());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user