Skip to content

Commit 4917fcd

Browse files
authored
Enhance UI for Resource Route Copy/Download/Edit Actions (#17)
Integrate `react-hot-toast` for user notifications when copying or downloading markdown content. Enhance the user interface for copying and downloading markdown with improved button layouts.
1 parent 05135c4 commit 4917fcd

3 files changed

Lines changed: 55 additions & 34 deletions

File tree

bun.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"prompts": "^2.4.2",
5353
"react": "^19.1.0",
5454
"react-dom": "^19.1.0",
55+
"react-hot-toast": "^2.5.2",
5556
"rehype-slug": "^6.0.0",
5657
"remark-gfm": "^4.0.1",
5758
"tailwindcss": "^4.1.2",

src/routes/ResourceRoute/ResourceRoute.tsx

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
import { useForm } from "@tanstack/react-form";
77
import type { CollectionEntry } from "astro:content";
88
import clsx from "clsx";
9-
import { Copy, Download, DownloadCloudIcon, Search } from "lucide-react";
9+
import { Copy, DownloadCloudIcon, Search } from "lucide-react";
1010
import React from "react";
1111
import { Card } from "../../components/client/AppCard/AppCard";
1212
import { getMdxComponents, MDXWrapper } from "../../components/client/MDX/MDX";
@@ -22,6 +22,8 @@ import type { DocType } from "../../domains/document/DocParser";
2222
import { evaluateMdxSync } from "../../domains/mdx/evaluateMdx";
2323
import type { ThemeType } from "../../domains/utils/getTheme";
2424

25+
import toast, { Toaster } from "react-hot-toast";
26+
2527
export function ResourceRoute(props: {
2628
origin: string;
2729
pathname: string;
@@ -94,6 +96,7 @@ export function ResourceRoute(props: {
9496
function handleCopyMarkdown() {
9597
if (props.content) {
9698
navigator.clipboard.writeText(props.content);
99+
toast.success("Copied to clipboard!");
97100
}
98101
}
99102

@@ -108,11 +111,13 @@ export function ResourceRoute(props: {
108111
anchor.click();
109112
document.body.removeChild(anchor);
110113
URL.revokeObjectURL(url);
114+
toast.success("Downloaded!");
111115
}
112116
}
113117

114118
return (
115119
<UI.Theme {...props.theme} hasBackground={false}>
120+
<Toaster></Toaster>
116121
<CampaignContext.Provider value={campaignManager}>
117122
<div>
118123
<div className="flex gap-9">
@@ -140,41 +145,51 @@ export function ResourceRoute(props: {
140145
{props.doc.currentPage?.title || ""}
141146
</h1>
142147
</MDXWrapper>
143-
<UI.DropdownMenu.Root>
144-
<UI.DropdownMenu.Trigger>
145-
<UI.IconButton
146-
variant="ghost"
147-
size="1"
148-
color="gray"
149-
highContrast
150-
>
151-
<Download></Download>
152-
</UI.IconButton>
153-
</UI.DropdownMenu.Trigger>
154-
<UI.DropdownMenu.Content>
155-
<UI.DropdownMenu.Item onClick={handleCopyMarkdown}>
156-
<Copy size={"1em"}></Copy>
157-
Copy page to clipboard
158-
</UI.DropdownMenu.Item>
159-
<UI.DropdownMenu.Item onClick={handleDownloadMarkdown}>
160-
<DownloadCloudIcon size={"1em"}></DownloadCloudIcon>
161-
Download page
162-
</UI.DropdownMenu.Item>
163-
</UI.DropdownMenu.Content>
164-
</UI.DropdownMenu.Root>
165148
</div>
166-
<div className="flex flex-row items-center justify-between gap-2">
167-
<MDXWrapper>
168-
<h3
169-
style={{
170-
marginTop: "0 !important",
171-
marginBottom: "3rem !important",
172-
color: `var(--gray-10) !important`,
173-
}}
149+
<UI.Separator className="mt-1 mb-3 flex w-full"></UI.Separator>
150+
<div className="mb-6 flex flex-row gap-2">
151+
<UI.Button
152+
variant="soft"
153+
color="gray"
154+
size="1"
155+
radius="full"
156+
onClick={handleCopyMarkdown}
157+
className="flex items-center gap-2"
158+
>
159+
<Copy size={"1em"} />
160+
Copy as Markdown
161+
</UI.Button>
162+
<UI.Button
163+
variant="soft"
164+
color="gray"
165+
size="1"
166+
radius="full"
167+
onClick={handleDownloadMarkdown}
168+
className="flex items-center gap-2"
169+
>
170+
<DownloadCloudIcon size={"1em"} />
171+
Download as Markdown
172+
</UI.Button>
173+
<UI.Link
174+
href={AppUrl.githubResource({
175+
id: props.resource.id,
176+
page: props.doc.currentPage?.gitHubId || "",
177+
})}
178+
target="_blank"
179+
rel="noopener noreferrer"
180+
className="flex items-center gap-2 no-underline"
181+
>
182+
<UI.Button
183+
variant="soft"
184+
color="gray"
185+
size="1"
186+
radius="full"
187+
className="flex items-center gap-2"
174188
>
175-
{props.resource.data.name}
176-
</h3>
177-
</MDXWrapper>
189+
<GitHubLogoIcon width={"1.2em"} height={"1.2em"} />
190+
Edit on GitHub
191+
</UI.Button>
192+
</UI.Link>
178193
</div>
179194
</div>
180195

0 commit comments

Comments
 (0)