|
| 1 | +"use client" |
| 2 | + |
| 3 | +import { useMemo, useState } from "react" |
| 4 | +import Link from "next/link" |
| 5 | +import { ArrowRight, Check, Copy, Github, Route, Terminal } from "lucide-react" |
| 6 | + |
| 7 | +import { Badge } from "@/components/ui/badge" |
| 8 | +import { buttonVariants } from "@/components/ui/button" |
| 9 | +import { buildRepoLaunchArtifacts } from "@/lib/repo-launch-artifacts" |
| 10 | +import { cn } from "@/lib/utils" |
| 11 | + |
| 12 | +function CopyAction({ value, label }: { value: string; label: string }) { |
| 13 | + const [copied, setCopied] = useState(false) |
| 14 | + |
| 15 | + const handleCopy = async () => { |
| 16 | + try { |
| 17 | + await navigator.clipboard.writeText(value) |
| 18 | + } catch { |
| 19 | + const input = document.createElement("input") |
| 20 | + input.value = value |
| 21 | + document.body.appendChild(input) |
| 22 | + input.select() |
| 23 | + document.execCommand("copy") |
| 24 | + document.body.removeChild(input) |
| 25 | + } |
| 26 | + |
| 27 | + setCopied(true) |
| 28 | + window.setTimeout(() => setCopied(false), 1800) |
| 29 | + } |
| 30 | + |
| 31 | + return ( |
| 32 | + <button |
| 33 | + type="button" |
| 34 | + onClick={handleCopy} |
| 35 | + className="inline-flex h-8 items-center gap-1.5 rounded-md border border-border bg-background px-2.5 text-xs font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-foreground" |
| 36 | + > |
| 37 | + {copied ? <Check className="h-3.5 w-3.5 text-emerald-500" /> : <Copy className="h-3.5 w-3.5" />} |
| 38 | + {copied ? "Copied" : label} |
| 39 | + </button> |
| 40 | + ) |
| 41 | +} |
| 42 | + |
| 43 | +export function RepoLaunchBuilder() { |
| 44 | + const [input, setInput] = useState("github.com/openai/codex") |
| 45 | + const artifacts = useMemo(() => buildRepoLaunchArtifacts(input), [input]) |
| 46 | + const hasInput = input.trim().length > 0 |
| 47 | + |
| 48 | + return ( |
| 49 | + <section className="grid gap-5 rounded-[1.25rem] border border-border bg-card/60 p-5 sm:p-6 lg:grid-cols-[0.9fr_1.1fr]"> |
| 50 | + <div className="space-y-3"> |
| 51 | + <div className="flex items-center gap-2"> |
| 52 | + <Route className="h-4 w-4 text-primary" /> |
| 53 | + <div className="font-mono text-[11px] uppercase tracking-[0.22em] text-muted-foreground">Repo route builder</div> |
| 54 | + </div> |
| 55 | + <h2 className="text-lg font-semibold text-foreground">Turn any GitHub repo into a Discofork workspace.</h2> |
| 56 | + <p className="text-sm leading-7 text-muted-foreground"> |
| 57 | + Paste a GitHub URL, SSH remote, owner/repo, or Discofork URL. The builder gives you the web route and the local analysis command in one place. |
| 58 | + </p> |
| 59 | + </div> |
| 60 | + |
| 61 | + <div className="space-y-4"> |
| 62 | + <div className="space-y-2"> |
| 63 | + <label htmlFor="repo-launch-builder-input" className="text-xs font-medium text-muted-foreground"> |
| 64 | + Repository |
| 65 | + </label> |
| 66 | + <input |
| 67 | + id="repo-launch-builder-input" |
| 68 | + type="text" |
| 69 | + value={input} |
| 70 | + onChange={(event) => setInput(event.target.value)} |
| 71 | + placeholder="github.com/owner/repo" |
| 72 | + className="w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground outline-none transition-colors placeholder:text-muted-foreground focus:border-ring" |
| 73 | + /> |
| 74 | + {!artifacts && hasInput ? <p className="text-xs text-rose-500">Enter a GitHub repository URL or owner/repo name.</p> : null} |
| 75 | + </div> |
| 76 | + |
| 77 | + <div className="grid gap-3"> |
| 78 | + <div className="rounded-md border border-border bg-background/70 p-3"> |
| 79 | + <div className="flex flex-wrap items-center justify-between gap-2"> |
| 80 | + <div className="flex items-center gap-2 text-sm font-semibold text-foreground"> |
| 81 | + <Github className="h-4 w-4 text-primary" /> |
| 82 | + {artifacts?.fullName ?? "Waiting for a repository"} |
| 83 | + </div> |
| 84 | + {artifacts ? <Badge variant="success">Ready</Badge> : <Badge variant="muted">Preview</Badge>} |
| 85 | + </div> |
| 86 | + <div className="mt-3 flex flex-wrap gap-2"> |
| 87 | + {artifacts ? ( |
| 88 | + <> |
| 89 | + <Link href={artifacts.canonicalPath} className={cn(buttonVariants({ variant: "default" }), "h-8 rounded-md px-3 text-xs")}> |
| 90 | + Open route |
| 91 | + <ArrowRight className="h-3.5 w-3.5" /> |
| 92 | + </Link> |
| 93 | + <CopyAction value={artifacts.discoforkUrl} label="Copy URL" /> |
| 94 | + <a href={artifacts.githubUrl} target="_blank" rel="noreferrer" className={cn(buttonVariants({ variant: "outline" }), "h-8 rounded-md px-3 text-xs")}> |
| 95 | + GitHub |
| 96 | + </a> |
| 97 | + </> |
| 98 | + ) : null} |
| 99 | + </div> |
| 100 | + </div> |
| 101 | + |
| 102 | + <div className="rounded-md border border-border bg-background/70 p-3"> |
| 103 | + <div className="flex items-center gap-2 text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground"> |
| 104 | + <Terminal className="h-3.5 w-3.5" /> |
| 105 | + Local command |
| 106 | + </div> |
| 107 | + <div className="mt-2 break-all font-mono text-sm leading-6 text-foreground"> |
| 108 | + {artifacts?.analysisCommand ?? "discofork analyze owner/repo"} |
| 109 | + </div> |
| 110 | + {artifacts ? <div className="mt-3"><CopyAction value={artifacts.analysisCommand} label="Copy command" /></div> : null} |
| 111 | + </div> |
| 112 | + </div> |
| 113 | + </div> |
| 114 | + </section> |
| 115 | + ) |
| 116 | +} |
0 commit comments