fix minor linting/type errors

This commit is contained in:
2024-05-10 02:25:44 -05:00
parent 00088afa5c
commit 1f93c8568f
4 changed files with 10 additions and 7 deletions

View File

@@ -1,6 +1,6 @@
import type { FunctionComponent } from "react";
import { useBoolean } from "usehooks-ts";
import { format, formatDistanceToNow } from "date-fns";
import { format } from "date-fns";
import TimeAgo from "react-timeago";
type DynamicDateProps = {

2
src/env/client.mjs vendored
View File

@@ -10,7 +10,7 @@ export const formatErrors = (
Object.entries(errors)
.map(([name, value]) => {
if (value && "_errors" in value)
return `${name}: ${value._errors.join(", ")}\n`;
return `${String(name)}: ${value._errors.join(", ")}\n`;
})
.filter(Boolean);

View File

@@ -143,7 +143,7 @@ const useLookup = (warningHandler?: WarningHandler) => {
};
preload().catch(console.error);
}, [target]);
}, [target, uriType, warningHandler]);
async function getAndParse<T>(
url: string,
@@ -181,7 +181,7 @@ const useLookup = (warningHandler?: WarningHandler) => {
);
}
async function submitInternal(): Promise<Result<ParsedGeneric, Error>> {
async function submitInternal(target: string): Promise<Result<ParsedGeneric, Error>> {
if (target == null || target.length == 0)
return Result.err(
new Error("A target must be given in order to execute a lookup.")
@@ -219,6 +219,7 @@ const useLookup = (warningHandler?: WarningHandler) => {
await loadBootstrap("domain");
const url = getRegistryURL(targetType.value, target);
// HTTP
if (url.startsWith("http://") && url != repeatableRef.current) {
repeatableRef.current = url;
return Result.err(
@@ -261,7 +262,9 @@ const useLookup = (warningHandler?: WarningHandler) => {
target,
}: SubmitProps): Promise<Maybe<ParsedGeneric>> {
try {
const response = await submitInternal();
// target is already set in state, but it's also provided by the form callback, so we'll use it.
const response = await submitInternal(target);
if (response.isErr) {
setError(response.error.message);
console.error(response.error);

View File

@@ -42,11 +42,11 @@ export function ipMatch(prefix: string, ip: string) {
*/
// return the first HTTPS url, or the first URL
export function getBestURL(urls: string[]): string {
export function getBestURL(urls: [string, ...string[]]): string {
urls.forEach((url) => {
if (url.startsWith("https://")) return url;
});
return urls[0]!;
return urls[0];
}
// given a URL, injects that URL into the query input,