Skip to content

Commit

Permalink
add title automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
codegod100 committed Oct 29, 2024
1 parent c9266ab commit 17a1509
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/frontpage/app/(app)/post/new/_client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -51,8 +52,11 @@ export function NewPostForm() {
id={`${id}-url`}
type="url"
value={url}
onChange={(e) => {
setUrl(e.currentTarget.value);
onChange={async (e) => {

Check failure on line 55 in packages/frontpage/app/(app)/post/new/_client.tsx

View workflow job for this annotation

GitHub Actions / lint

Promise-returning function provided to attribute where a void return was expected
let url = e.currentTarget.value

Check failure on line 56 in packages/frontpage/app/(app)/post/new/_client.tsx

View workflow job for this annotation

GitHub Actions / lint

'url' is never reassigned. Use 'const' instead
const title = await grabTitle(url)
setTitle(title)
setUrl(url);
}}
/>
<InputLengthIndicator
Expand Down
7 changes: 7 additions & 0 deletions packages/frontpage/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

export async function grabTitle(url: string): Promise<string> {
url = encodeURI(url);
let response = await fetch(`https://cardyb.bsky.app/v1/extract?url=${url}`)

Check failure on line 10 in packages/frontpage/lib/utils.ts

View workflow job for this annotation

GitHub Actions / lint

'response' is never reassigned. Use 'const' instead
let body = await response.json()

Check failure on line 11 in packages/frontpage/lib/utils.ts

View workflow job for this annotation

GitHub Actions / lint

'body' is never reassigned. Use 'const' instead
return body.title
}

export type Prettify<T> = {
[K in keyof T]: T[K];
// eslint-disable-next-line @typescript-eslint/ban-types
Expand Down

0 comments on commit 17a1509

Please sign in to comment.