import { useQuery } from "@tanstack/react-query"; import axios from "axios"; import type { SyntheticEvent } from "react"; import { z } from "zod"; import { env } from "../../env/client.mjs"; import FadeIn from "../motions/FadeIn"; interface LinkInfo { link: string; index: number; } const MetaDataSchema = z.object({ title: z.string().nullish(), favicon: z.string().nullish(), hostname: z.string().nullish(), }); const SourceLink = ({ link, index }: LinkInfo) => { const linkMeta = useQuery(["linkMeta", link], async () => MetaDataSchema.parse( ( await axios.get(env.NEXT_PUBLIC_BACKEND_URL + "/api/metadata", { params: { url: link, }, }) ).data ) ); const addImageFallback = (event: SyntheticEvent) => { event.currentTarget.src = "/errorFavicon.ico"; }; return (
{linkMeta.isLoading ? (
) : linkMeta.isSuccess ? ( <>

{linkMeta.data.title}

Logo

{linkMeta.data.hostname}

{index + 1}

) : linkMeta.isError ? (

{link}

{index + 1}

) : null}
); }; export default SourceLink;