import Plus from "lucide-solid/icons/plus"; import type { EventParameter } from "~/App"; const URL_INPUT = "url"; export type UrlFormProperties = { onSubmit(url: URL): void; }; // async function getIcon(url: URL) { // console.debug("Getting icon"); // const document = await getDocument(url); // // A link can have multiple rel // const iconLinks = document.querySelectorAll( // 'link[rel~="icon"], link[rel~="apple-touch-icon"]' // ); // // Select best icon // for (const link of iconLinks) { // if (!(link instanceof HTMLLinkElement)) continue; // if (link.sizes.contains("any")) { // } // } // } export default function UrlForm({ onSubmit }: UrlFormProperties) { function handleSubmit(event: EventParameter) { event.preventDefault(); const form = event.currentTarget; const input = form.elements.namedItem(URL_INPUT); if (!(input instanceof HTMLInputElement)) throw new Error("Expected form to have url input"); console.debug("submitted", input.value); const url = URL.parse(input.value); if (url === null) { input.setCustomValidity("Invalid url. Url is not parsable."); input.reportValidity(); // Reset on next input input.addEventListener("input", () => input.setCustomValidity(""), { once: true, }); return; } onSubmit(url); } return (
); }