diff --git a/packages/frontpage/app/(app)/post/new/_client.tsx b/packages/frontpage/app/(app)/post/new/_client.tsx index 127acbee..6e19f160 100644 --- a/packages/frontpage/app/(app)/post/new/_client.tsx +++ b/packages/frontpage/app/(app)/post/new/_client.tsx @@ -7,6 +7,7 @@ import { Input } from "@/lib/components/ui/input"; import { Button } from "@/lib/components/ui/button"; import { Alert, AlertDescription, AlertTitle } from "@/lib/components/ui/alert"; import { Spinner } from "@/lib/components/ui/spinner"; +import { grabTitle } from "@/lib/utils"; import { MAX_POST_TITLE_LENGTH, MAX_POST_URL_LENGTH, @@ -51,8 +52,11 @@ export function NewPostForm() { id={`${id}-url`} type="url" value={url} - onChange={(e) => { - setUrl(e.currentTarget.value); + onChange={async (e) => { + let url = e.currentTarget.value + const title = await grabTitle(url) + setTitle(title) + setUrl(url); }} /> { + url = encodeURI(url); + let response = await fetch(`https://cardyb.bsky.app/v1/extract?url=${url}`) + let body = await response.json() + return body.title +} + export type Prettify = { [K in keyof T]: T[K]; // eslint-disable-next-line @typescript-eslint/ban-types