Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

simplify implementation

Steven Teyb81223a5ae93
diff --git a/apps/web/ui/guides/guide.tsx b/apps/web/ui/guides/guide.tsx
index 0608f0d404..6f96fd1f2f 100644
--- a/apps/web/ui/guides/guide.tsx
+++ b/apps/web/ui/guides/guide.tsx
@@ -1,8 +1,18 @@
"use client";
-import { BookOpen, Button, buttonVariants, ChevronLeft, Popover, Anthropic, OpenAI } from "@dub/ui";
+import {
+ Anthropic,
+ BookOpen,
+ Button,
+ buttonVariants,
+ Check,
+ ChevronLeft,
+ OpenAI,
+ Popover,
+ useCopyToClipboard,
+} from "@dub/ui";
import { cn } from "@dub/utils";
-import { ChevronDown, Copy, ArrowUpRight } from "lucide-react";
+import { ArrowUpRight, ChevronDown, Copy } from "lucide-react";
import Link from "next/link";
import { useParams, usePathname } from "next/navigation";
import { useState } from "react";
@@ -27,50 +37,9 @@ export function Guide({ markdown }: { markdown: string }) {
const pathname = usePathname();
const backHref = `${pathname.replace(`/${guideKey}`, "")}?step=${selectedGuide.type}`;
- const getPageContentAsMarkdown = async (): Promise<string> => {
- try {
- if (markdown) {
- return markdown;
- }
-
- const contentElement = document.querySelector('[data-markdown-content]');
- if (contentElement) {
- return contentElement.textContent || 'Content not available';
- }
-
- return 'Content not available';
- } catch (error) {
- console.error('Error getting markdown content:', error);
- return 'Error getting content';
- }
- };
-
- const handleCopyContent = async () => {
- try {
- const markdownContent = await getPageContentAsMarkdown();
- await navigator.clipboard.writeText(markdownContent);
- toast.success("Content copied as markdown");
- } catch (error) {
- console.error("Failed to copy content:", error);
- toast.error("Failed to copy content");
- }
- setOpenDropdown(false);
- };
-
- const handleOpenChatGPT = () => {
- const prompt = `Read from ${selectedGuide.url} so I can ask questions about it.`;
- const chatgptUrl = `https://chatgpt.com/?prompt=${encodeURIComponent(prompt)}`;
- window.open(chatgptUrl, '_blank');
- setOpenDropdown(false);
- };
-
- const handleOpenClaude = () => {
- const prompt = `Read from ${selectedGuide.url} so I can ask questions about it.`;
- const claudeUrl = `https://claude.ai/new?q=${encodeURIComponent(prompt)}`;
- const win = window.open(claudeUrl, "_blank", "noopener,noreferrer");
- if (win) win.opener = null;
- setOpenDropdown(false);
- };
+ const [copied, copyToClipboard] = useCopyToClipboard();
+
+ const prompt = `Read from ${selectedGuide.url} so I can ask questions about it.`;
return (
<>
@@ -86,7 +55,11 @@ export function Guide({ markdown }: { markdown: string }) {
</Link>
<div className="flex items-center overflow-hidden rounded-lg border border-neutral-200">
- <Link href={selectedGuide.url} target="_blank" rel="noopener noreferrer">
+ <Link
+ href={selectedGuide.url}
+ target="_blank"
+ rel="noopener noreferrer"
+ >
<Button
text="Read full guide"
variant="secondary"
@@ -94,54 +67,76 @@ export function Guide({ markdown }: { markdown: string }) {
icon={<BookOpen className="size-3.5" />}
/>
</Link>
-
+
<div className="h-8 w-px bg-neutral-200" />
-
+
<Popover
content={
<div className="flex w-full flex-col space-y-px rounded-lg bg-white p-1 sm:min-w-64">
<button
className="flex w-full cursor-pointer items-center gap-2 rounded-md p-2 text-sm text-neutral-600 transition-colors hover:bg-neutral-100"
- onClick={handleCopyContent}
+ onClick={() =>
+ copyToClipboard(markdown, {
+ onSuccess: () => {
+ toast.success("Content copied as markdown");
+ },
+ })
+ }
>
<div className="flex h-8 w-8 items-center justify-center rounded border border-neutral-200 transition-colors hover:border-neutral-300">
- <Copy className="size-4 text-neutral-600" />
+ {copied ? (
+ <Check className="size-4 text-neutral-600" />
+ ) : (
+ <Copy className="size-4 text-neutral-600" />
+ )}
</div>
<div className="flex flex-col items-start">
<span className="font-medium">Copy content</span>
- <span className="text-xs text-neutral-500">Copy page as Markdown for LLMs</span>
+ <span className="text-xs text-neutral-500">
+ Copy page as Markdown for LLMs
+ </span>
</div>
</button>
<button
className="flex w-full cursor-pointer items-center gap-2 rounded-md p-2 text-sm text-neutral-600 transition-colors hover:bg-neutral-100"
- onClick={handleOpenChatGPT}
+ onClick={() => {
+ const chatgptUrl = `https://chatgpt.com/new?q=${encodeURIComponent(prompt)}`;
+ window.open(chatgptUrl, "_blank", "noopener,noreferrer");
+ }}
>
<div className="flex h-8 w-8 items-center justify-center rounded border border-neutral-200 transition-colors hover:border-neutral-300">
<OpenAI className="size-4 text-neutral-600" />
</div>
- <div className="flex flex-col items-start flex-1">
+ <div className="flex flex-1 flex-col items-start">
<div className="flex items-center gap-1">
<span className="font-medium">Open in ChatGPT</span>
<ArrowUpRight className="size-3.5 text-neutral-600" />
</div>
- <span className="text-xs text-neutral-500">Ask questions about this step</span>
+ <span className="text-xs text-neutral-500">
+ Ask questions about this step
+ </span>
</div>
</button>
<button
className="flex w-full cursor-pointer items-center gap-2 rounded-md p-2 text-sm text-neutral-600 transition-colors hover:bg-neutral-100"
- onClick={handleOpenClaude}
+ onClick={() => {
+ const claudeUrl = `https://claude.ai/new?q=${encodeURIComponent(prompt)}`;
+ window.open(claudeUrl, "_blank", "noopener,noreferrer");
+ }}
>
<div className="flex h-8 w-8 items-center justify-center rounded border border-neutral-200 transition-colors hover:border-neutral-300">
<Anthropic className="size-4 text-neutral-600" />
</div>
- <div className="flex flex-col items-start flex-1">
+ <div className="flex flex-1 flex-col items-start">
<div className="flex items-center gap-1">
<span className="font-medium">Open in Claude</span>
<ArrowUpRight className="size-3.5 text-neutral-600" />
</div>
- <span className="text-xs text-neutral-500">Ask questions about this step</span>
+ <span className="text-xs text-neutral-500">
+ Ask questions about this step
+ </span>
</div>
</button>
</div>
@@ -155,7 +150,7 @@ export function Guide({ markdown }: { markdown: string }) {
className={cn(
"flex h-8 items-center justify-center rounded-none border-0 bg-white px-2 transition-colors",
"hover:bg-neutral-50 focus-visible:ring-2 focus-visible:ring-black/50",
- openDropdown && "bg-neutral-50"
+ openDropdown && "bg-neutral-50",
)}
>
<ChevronDown className="size-3.5 text-neutral-600" />