-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move post thread metadata from page to layout
- Loading branch information
Showing
3 changed files
with
66 additions
and
43 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/app/dashboard/user/[handle]/(post)/post/[id]/layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { getAgent } from "@/lib/api/bsky/agent"; | ||
import { getPostThread } from "@/lib/api/bsky/feed"; | ||
import { AppBskyFeedDefs, AppBskyFeedPost } from "@atproto/api"; | ||
import { Metadata } from "next"; | ||
|
||
export async function generateMetadata({ params }: Props): Promise<Metadata> { | ||
const agent = await getAgent(); | ||
const { handle, id } = params; | ||
const { data } = await agent.resolveHandle({ handle }); | ||
const uri = `at://${data.did}/app.bsky.feed.post/${id}`; | ||
const post = await getPostThread(uri); | ||
|
||
const isThreadViewPost = AppBskyFeedDefs.isThreadViewPost(post) | ||
? true | ||
: false; | ||
const threadPost = isThreadViewPost | ||
? (post.post as AppBskyFeedDefs.PostView) | ||
: null; | ||
|
||
const text = | ||
threadPost && AppBskyFeedPost.isRecord(threadPost.record) | ||
? threadPost.record.text | ||
: ""; | ||
|
||
const title = | ||
text !== "" | ||
? `${threadPost?.author.displayName || params.handle}: "${text}"` | ||
: `Post by ${params.handle}`; | ||
|
||
return { | ||
title: title, | ||
description: "Feed", | ||
}; | ||
} | ||
|
||
interface Props { | ||
params: { | ||
id: string; | ||
handle: string; | ||
}; | ||
} | ||
|
||
export default function PostThreadLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
return <>{children}</>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters