mirror of
https://github.com/ShayManor/github-readme-stats.git
synced 2026-12-02 11:53:48 +05:30
chore(ResultScreen): add copy functionality for embed snippet button
This commit is contained in:
@@ -52,7 +52,6 @@ export default function App() {
|
|||||||
const [username, setUsername] = useState('')
|
const [username, setUsername] = useState('')
|
||||||
const [settings, setSettings] = useState<WidgetSettings>({ ...DEFAULT_SETTINGS })
|
const [settings, setSettings] = useState<WidgetSettings>({ ...DEFAULT_SETTINGS })
|
||||||
const [widgetData, setWidgetData] = useState<WidgetData | null>(null)
|
const [widgetData, setWidgetData] = useState<WidgetData | null>(null)
|
||||||
const [isDemo, setIsDemo] = useState(false)
|
|
||||||
const [fetchDone, setFetchDone] = useState(false)
|
const [fetchDone, setFetchDone] = useState(false)
|
||||||
const [fetchError, setFetchError] = useState<string | null>(null)
|
const [fetchError, setFetchError] = useState<string | null>(null)
|
||||||
// Final SVG produced by POST /api/<u>/generate. Rendered on the Result
|
// Final SVG produced by POST /api/<u>/generate. Rendered on the Result
|
||||||
@@ -81,7 +80,6 @@ export default function App() {
|
|||||||
setFetchError(null)
|
setFetchError(null)
|
||||||
// Show demo data immediately so Workshop is interactive while the worker builds.
|
// Show demo data immediately so Workshop is interactive while the worker builds.
|
||||||
setWidgetData(DEMO_WIDGET_DATA)
|
setWidgetData(DEMO_WIDGET_DATA)
|
||||||
setIsDemo(true)
|
|
||||||
|
|
||||||
const poll = async () => {
|
const poll = async () => {
|
||||||
if (aborted.current) return
|
if (aborted.current) return
|
||||||
@@ -93,7 +91,6 @@ export default function App() {
|
|||||||
|
|
||||||
if (r.status === 200 && status === 'ready' && body.data) {
|
if (r.status === 200 && status === 'ready' && body.data) {
|
||||||
setWidgetData(body.data)
|
setWidgetData(body.data)
|
||||||
setIsDemo(false)
|
|
||||||
setFetchDone(true)
|
setFetchDone(true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -186,7 +183,6 @@ export default function App() {
|
|||||||
onBack={handleBack}
|
onBack={handleBack}
|
||||||
fetchDone={fetchDone}
|
fetchDone={fetchDone}
|
||||||
fetchError={fetchError}
|
fetchError={fetchError}
|
||||||
isDemo={isDemo}
|
|
||||||
widgetData={widgetData}
|
widgetData={widgetData}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import DOMPurify from 'dompurify'
|
import DOMPurify from 'dompurify'
|
||||||
import { useMemo } from 'react'
|
import { useMemo, useState } from 'react'
|
||||||
|
|
||||||
function sanitizeSvg(raw: string): string {
|
function sanitizeSvg(raw: string): string {
|
||||||
return DOMPurify.sanitize(raw, {
|
return DOMPurify.sanitize(raw, {
|
||||||
@@ -19,12 +19,23 @@ type Props = {
|
|||||||
|
|
||||||
export function ResultScreen({ username, generating, generatedSvg, generateError, onBack }: Props) {
|
export function ResultScreen({ username, generating, generatedSvg, generateError, onBack }: Props) {
|
||||||
const safeSvg = useMemo(() => (generatedSvg ? sanitizeSvg(generatedSvg) : ''), [generatedSvg])
|
const safeSvg = useMemo(() => (generatedSvg ? sanitizeSvg(generatedSvg) : ''), [generatedSvg])
|
||||||
|
const [copied, setCopied] = useState(false)
|
||||||
const embedUrl = `${window.location.origin}/api/${encodeURIComponent(username)}`
|
const embedUrl = `${window.location.origin}/api/${encodeURIComponent(username)}`
|
||||||
const embedSnippet = ``
|
const embedSnippet = ``
|
||||||
|
|
||||||
|
const copy = async () => {
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(embedSnippet)
|
||||||
|
setCopied(true)
|
||||||
|
setTimeout(() => setCopied(false), 1500)
|
||||||
|
} catch {
|
||||||
|
/* ignore */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen flex flex-col items-center animate-fade-in-up">
|
<div className="min-h-screen flex flex-col items-center animate-fade-in-up">
|
||||||
<div className="w-full max-w-2xl px-6 pt-6">
|
<div className="w-full max-w-3xl px-6 pt-6">
|
||||||
<button
|
<button
|
||||||
onClick={onBack}
|
onClick={onBack}
|
||||||
className="flex items-center gap-1.5 text-xs text-gray-400 hover:text-gray-600 transition-colors"
|
className="flex items-center gap-1.5 text-xs text-gray-400 hover:text-gray-600 transition-colors"
|
||||||
@@ -36,31 +47,56 @@ export function ResultScreen({ username, generating, generatedSvg, generateError
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex-1 flex flex-col items-center justify-center px-6 pb-12 w-full max-w-2xl">
|
<div className="flex-1 flex flex-col items-center justify-center px-6 pb-12 w-full max-w-3xl">
|
||||||
<h2 className="font-serif text-2xl text-gray-800 tracking-tight mb-1">
|
<h2 className="font-serif text-3xl text-gray-800 tracking-tight mb-2">
|
||||||
Your Widget
|
Your Widget
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
{generating && (
|
{generating && (
|
||||||
<div className="mt-8 flex flex-col items-center gap-3">
|
<div className="mt-10 flex flex-col items-center gap-3">
|
||||||
<div className="w-5 h-5 border-2 border-gray-300 border-t-gray-600 rounded-full animate-spin-slow" />
|
<div className="w-6 h-6 border-2 border-gray-300 border-t-gray-600 rounded-full animate-spin-slow" />
|
||||||
<p className="text-xs text-gray-400">Generating with real data…</p>
|
<p className="text-xs text-gray-400">Generating with real data…</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!generating && generateError && (
|
{!generating && generateError && (
|
||||||
<div className="mt-8 flex flex-col items-center gap-3">
|
<div className="mt-10 flex flex-col items-center gap-3">
|
||||||
<p className="text-xs text-red-500">{generateError}</p>
|
<p className="text-sm text-red-500">{generateError}</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!generating && !generateError && safeSvg && (
|
{!generating && !generateError && safeSvg && (
|
||||||
<>
|
<>
|
||||||
<p className="text-xs text-gray-400 mb-6">Rendered from live data</p>
|
<p className="text-xs text-gray-400 mb-6">Rendered from live GitHub data</p>
|
||||||
<div className="w-full flex justify-center" dangerouslySetInnerHTML={{ __html: safeSvg }} />
|
<div className="w-full rounded-2xl bg-white shadow-lg ring-1 ring-gray-200 p-6 flex justify-center">
|
||||||
|
{/*
|
||||||
|
Force the inline SVG to scale up to the card width. The
|
||||||
|
composite is authored at 380px wide — without this the
|
||||||
|
preview looked tiny on wide screens.
|
||||||
|
*/}
|
||||||
|
<div
|
||||||
|
className="w-full max-w-xl [&_svg]:w-full [&_svg]:h-auto"
|
||||||
|
dangerouslySetInnerHTML={{ __html: safeSvg }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="w-full mt-8">
|
<div className="w-full mt-8">
|
||||||
<p className="text-xs text-gray-500 mb-2">Embed in your README:</p>
|
<div className="flex items-baseline justify-between mb-2">
|
||||||
<pre className="bg-gray-100 text-xs p-3 rounded overflow-x-auto">{embedSnippet}</pre>
|
<p className="text-xs uppercase tracking-wider text-gray-500">Embed in your README</p>
|
||||||
|
<button
|
||||||
|
onClick={copy}
|
||||||
|
className="text-xs text-gray-500 hover:text-gray-800 transition-colors"
|
||||||
|
>
|
||||||
|
{copied ? 'Copied!' : 'Copy'}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<pre className="bg-gray-900 text-gray-100 text-xs p-4 rounded-lg overflow-x-auto">
|
||||||
|
{embedSnippet}
|
||||||
|
</pre>
|
||||||
|
<p className="text-[11px] text-gray-400 mt-2">
|
||||||
|
GitHub requires HTTPS for README images — serve this behind a TLS
|
||||||
|
reverse proxy or Cloudflare Tunnel if the page is on http://.
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -86,7 +86,6 @@ type Props = {
|
|||||||
onBack: () => void
|
onBack: () => void
|
||||||
fetchDone: boolean
|
fetchDone: boolean
|
||||||
fetchError: string | null
|
fetchError: string | null
|
||||||
isDemo: boolean
|
|
||||||
widgetData: WidgetData | null
|
widgetData: WidgetData | null
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,7 +97,6 @@ export function WorkshopScreen({
|
|||||||
onBack,
|
onBack,
|
||||||
fetchDone,
|
fetchDone,
|
||||||
fetchError,
|
fetchError,
|
||||||
isDemo,
|
|
||||||
widgetData,
|
widgetData,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const [expandedWidget, setExpandedWidget] = useState<string | null>(null)
|
const [expandedWidget, setExpandedWidget] = useState<string | null>(null)
|
||||||
@@ -177,30 +175,13 @@ export function WorkshopScreen({
|
|||||||
Back
|
Back
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<div className="text-sm font-semibold text-gray-800 mb-1">{username}</div>
|
<div className="text-sm font-semibold text-gray-800 mb-6">{username}</div>
|
||||||
<div className="flex items-center gap-1.5 text-[10px] text-gray-400 mb-6">
|
{fetchError && (
|
||||||
{fetchError ? (
|
<div className="flex items-center gap-1.5 text-[10px] text-red-500 mb-6">
|
||||||
<>
|
|
||||||
<div className="w-1.5 h-1.5 rounded-full bg-red-400" />
|
<div className="w-1.5 h-1.5 rounded-full bg-red-400" />
|
||||||
{fetchError}
|
{fetchError}
|
||||||
</>
|
|
||||||
) : isDemo ? (
|
|
||||||
<>
|
|
||||||
<div className="w-1.5 h-1.5 rounded-full bg-amber-400 animate-pulse" />
|
|
||||||
Building your widget — showing demo
|
|
||||||
</>
|
|
||||||
) : fetchDone ? (
|
|
||||||
<>
|
|
||||||
<div className="w-1.5 h-1.5 rounded-full bg-emerald-400" />
|
|
||||||
Data ready
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<div className="w-1.5 h-1.5 rounded-full bg-amber-400 animate-pulse" />
|
|
||||||
Fetching data...
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Theme */}
|
{/* Theme */}
|
||||||
<div className="mb-5">
|
<div className="mb-5">
|
||||||
|
|||||||
Reference in New Issue
Block a user