From c511e951121ade6615410e65bad1825160f6cce2 Mon Sep 17 00:00:00 2001 From: nandi Date: Sat, 26 Oct 2024 16:17:50 -0700 Subject: [PATCH] add title automatically --- packages/frontpage/app/(app)/post/new/_client.tsx | 8 ++++++-- packages/frontpage/lib/utils.ts | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/frontpage/app/(app)/post/new/_client.tsx b/packages/frontpage/app/(app)/post/new/_client.tsx index 127acbee..158ce34d 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) => { + const url = e.currentTarget.value + const title = await grabTitle(url) + setTitle(title) + setUrl(url); }} /> { + url = encodeURI(url); + const response = await fetch(`https://cardyb.bsky.app/v1/extract?url=${url}`) + const body = await response.json() + return body.title +} + export type Prettify = { [K in keyof T]: T[K]; // eslint-disable-next-line @typescript-eslint/ban-types