-
-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Preview page for the stored content of links
- Loading branch information
1 parent
b2e64b9
commit b8b0a44
Showing
4 changed files
with
86 additions
and
7 deletions.
There are no files selected for viewing
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
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,64 @@ | ||
import { BackButton } from "@/components/ui/back-button"; | ||
import { api } from "@/server/api/client"; | ||
import { ArrowLeftCircle, CalendarDays, ExternalLink } from "lucide-react"; | ||
import Link from "next/link"; | ||
import Markdown from "react-markdown"; | ||
|
||
export default async function BookmarkPreviewPage({ | ||
params, | ||
}: { | ||
params: { bookmarkId: string }; | ||
}) { | ||
const bookmark = await api.bookmarks.getBookmark({ | ||
bookmarkId: params.bookmarkId, | ||
}); | ||
|
||
const linkHeader = bookmark.content.type == "link" && ( | ||
<div className="flex flex-col space-y-2"> | ||
<p className="text-center text-3xl">{bookmark.content.title}</p> | ||
<Link href={bookmark.content.url} className="mx-auto flex gap-2"> | ||
<span className="my-auto">View Original</span> | ||
<ExternalLink /> | ||
</Link> | ||
</div> | ||
); | ||
|
||
let content; | ||
switch (bookmark.content.type) { | ||
case "link": { | ||
content = ( | ||
<div | ||
dangerouslySetInnerHTML={{ | ||
__html: bookmark.content.htmlContent || "", | ||
}} | ||
className="prose" | ||
/> | ||
); | ||
break; | ||
} | ||
case "text": { | ||
content = <Markdown className="prose">{bookmark.content.text}</Markdown>; | ||
break; | ||
} | ||
} | ||
|
||
return ( | ||
<div className="bg-background m-4 min-h-screen space-y-4 rounded-md border p-4"> | ||
<div className="flex justify-between"> | ||
<BackButton className="ghost" variant="ghost"> | ||
<ArrowLeftCircle /> | ||
</BackButton> | ||
<div className="my-auto"> | ||
<span className="my-auto flex gap-2"> | ||
<CalendarDays /> {bookmark.createdAt.toLocaleString()} | ||
</span> | ||
</div> | ||
</div> | ||
<hr /> | ||
{linkHeader} | ||
<div className="mx-auto flex h-full border-x p-2 px-4 lg:w-2/3"> | ||
{content} | ||
</div> | ||
</div> | ||
); | ||
} |
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,9 @@ | ||
"use client"; | ||
|
||
import { useRouter } from "next/navigation"; | ||
import { Button, ButtonProps } from "./button"; | ||
|
||
export function BackButton({ ...props }: ButtonProps) { | ||
const router = useRouter(); | ||
return <Button {...props} onClick={() => router.back()} />; | ||
} |