diff --git a/src/components/react/link-form.tsx b/src/components/react/link-form.tsx index 841d723..0723d4c 100644 --- a/src/components/react/link-form.tsx +++ b/src/components/react/link-form.tsx @@ -1,7 +1,45 @@ -import { useState, type FormEvent } from "react"; +import { useRef, useState, type FormEvent } from "react"; type Status = { type: "none" } | { type: "success" | "error"; message: string }; +const CopyButton = ({ value }: { value: string }) => { + const [timeoutId, setTimeoutId] = useState(-1); + const copiedRef = useRef(null); + const copyToRef = useRef(null); + + function handleClick() { + window.clearTimeout(timeoutId); + + navigator.clipboard.writeText(`go.czw.sh/${value}`); + + copiedRef.current!.removeAttribute("hidden"); + copyToRef.current!.style.opacity = "0"; + + const id = window.setTimeout(() => { + copiedRef.current!.setAttribute("hidden", ""); + copyToRef.current!.style.opacity = "100"; + }, 2000); + + setTimeoutId(id); + } + + return ( + + ); +}; + const LinkForm = () => { const [status, setStatus] = useState({ type: "none" }); @@ -23,28 +61,48 @@ const LinkForm = () => { } return ( -
- - +
+ + + + + {status.type !== "none" ? ( status.type === "error" ? ( -

{status.message}

+

{status.message}

) : ( - go.czw.sh/{status.message} +
+ + + +
) ) : null} - +
); }; diff --git a/src/layouts/layout.astro b/src/layouts/layout.astro index 27666c3..e2323e5 100644 --- a/src/layouts/layout.astro +++ b/src/layouts/layout.astro @@ -77,7 +77,7 @@ const canonicalUrl = removeTrailingSlash(new URL(Astro.url.pathname, Astro.site) {title} - + diff --git a/src/pages/index.astro b/src/pages/index.astro index 89b1d29..33b2579 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -11,10 +11,18 @@ const links = await db.select().from(Link); title="link shortener" description="Hello world" > -
- +
+
+

link shortener

+ made by charles +

+
-

<= === !== != --> ->

+

Recent links: