Lumen & Gesso / website · lumengesso.com / app / admin / images / CdnBrowser.tsx
| 1 | 'use client'; |
| 2 | |
| 3 | import { useEffect, useMemo, useRef, useState, type CSSProperties } from 'react'; |
| 4 | import type { CfImage } from '@/app/lib/cf-images'; |
| 5 | |
| 6 | // Admin CDN browser. Lazy on two axes so it scales to thousands of images: |
| 7 | // 1. DOM — only `limit` cards are mounted; an IntersectionObserver sentinel |
| 8 | // reveals the next BATCH as you scroll (so we never mount 5,000 nodes). |
| 9 | // 2. Bytes — each thumbnail is a plain <img loading="lazy">, so the browser |
| 10 | // only fetches images near the viewport. |
| 11 | const BATCH = 60; |
| 12 | |
| 13 | const btn: CSSProperties = { |
| 14 | padding: '5px 10px', borderRadius: 6, border: '1px solid var(--rule)', |
| 15 | background: 'transparent', cursor: 'pointer', fontSize: 11.5, color: 'var(--ink-soft)', |
| 16 | }; |
| 17 | |
| 18 | // "lifestyle-koda-named-v4.jpg" → "Koda · named" — used to prefill the pin |
| 19 | // title with something readable instead of the raw filename. |
| 20 | function prettifyName(filename: string): string { |
| 21 | const base = filename.replace(/\.(png|jpe?g|webp)$/i, '').replace(/-v\d+$/i, ''); |
| 22 | const parts = base.split('-').filter(Boolean); |
| 23 | if (parts.length === 0) return filename; |
| 24 | const cap = (s: string) => s.charAt(0).toUpperCase() + s.slice(1); |
| 25 | // Drop the leading "before/after/lifestyle/hero" prefix; capitalize the |
| 26 | // pet name; comma-separate any trailing style descriptors. |
| 27 | const known = new Set(['before', 'after', 'lifestyle', 'hero']); |
| 28 | const rest = known.has(parts[0]) ? parts.slice(1) : parts; |
| 29 | if (rest.length === 0) return cap(parts[0]); |
| 30 | if (rest.length === 1) return cap(rest[0]); |
| 31 | return `${cap(rest[0])} · ${rest.slice(1).map(cap).join(' ')}`; |
| 32 | } |
| 33 | |
| 34 | // Filename style-token → human descriptor. Used to compose a default pin |
| 35 | // description so we're not posting empty captions to Pinterest. |
| 36 | const STYLE_BLURBS: Record<string, string> = { |
| 37 | watercolor: 'watercolor', |
| 38 | popart: 'pop-art', |
| 39 | charcoal: 'charcoal', |
| 40 | lineart: 'line-drawing', |
| 41 | vector: 'vector-outline', |
| 42 | named: 'modern painted', |
| 43 | mixedmedia: 'impasto mixed-media', |
| 44 | impasto: 'impasto oil', |
| 45 | cubist: 'cubist', |
| 46 | ukiyoe: 'ukiyo-e', |
| 47 | thangka: 'thangka', |
| 48 | neoexpressionist: 'neo-expressionist', |
| 49 | risograph: 'risograph', |
| 50 | athome: 'mid-century home-portrait', |
| 51 | landscape: 'landscape oil', |
| 52 | }; |
| 53 | |
| 54 | // "lifestyle-koda-named-v4.jpg" → a brand-voiced default pin description |
| 55 | // that includes a style keyword (good for Pinterest's in-app search), |
| 56 | // the value proposition, and a CTA. ~250 chars, well under the 500 limit. |
| 57 | function defaultDescriptionFor(filename: string): string { |
| 58 | const base = filename.replace(/\.(png|jpe?g|webp)$/i, '').replace(/-v\d+$/i, '').toLowerCase(); |
| 59 | const tokens = new Set(base.split('-')); |
| 60 | let style = 'custom'; |
| 61 | for (const key of Object.keys(STYLE_BLURBS)) { |
| 62 | if (tokens.has(key)) { style = STYLE_BLURBS[key]; break; } |
| 63 | } |
| 64 | const article = /^[aeiou]/.test(style) ? 'An' : 'A'; |
| 65 | return `${article} ${style} pet portrait by Lumen & Gesso — a small studio crafting custom portraits of the family pet. Share a photo, pick a style, and we'll send a proof within one business day. Archival giclée prints on paper or canvas, framed if you like. Start yours at lumengesso.com.`; |
| 66 | } |
| 67 | |
| 68 | type PinBoard = { id: string; name: string }; |
| 69 | |
| 70 | export function CdnBrowser({ |
| 71 | images: initialImages, |
| 72 | deliveryBase, |
| 73 | pinterestReady, |
| 74 | }: { |
| 75 | images: CfImage[]; |
| 76 | deliveryBase: string; |
| 77 | pinterestReady: boolean; |
| 78 | }) { |
| 79 | // Track the displayed set in state so successful deletes can drop a tile |
| 80 | // without a full server refetch. Initialised from the server-fetched list. |
| 81 | const [images, setImages] = useState<CfImage[]>(initialImages); |
| 82 | const [scope, setScope] = useState<'portraits' | 'all'>('portraits'); |
| 83 | const [q, setQ] = useState(''); |
| 84 | const [limit, setLimit] = useState(BATCH); |
| 85 | const [copied, setCopied] = useState<string | null>(null); |
| 86 | const [deleting, setDeleting] = useState<string | null>(null); |
| 87 | const [error, setError] = useState<string | null>(null); |
| 88 | const sentinel = useRef<HTMLDivElement>(null); |
| 89 | |
| 90 | // Pinterest pin modal — opened from a per-tile button. Boards are lazy- |
| 91 | // loaded the first time the modal opens (and cached for the rest of the |
| 92 | // session) so we don't hit Pinterest until the admin actually pins. |
| 93 | const [pinTarget, setPinTarget] = useState<CfImage | null>(null); |
| 94 | const [boards, setBoards] = useState<PinBoard[] | null>(null); |
| 95 | const [boardsLoading, setBoardsLoading] = useState(false); |
| 96 | const [boardsError, setBoardsError] = useState<string | null>(null); |
| 97 | const [boardId, setBoardId] = useState(''); |
| 98 | const [pinTitle, setPinTitle] = useState(''); |
| 99 | const [pinDescription, setPinDescription] = useState(''); |
| 100 | const [pinLink, setPinLink] = useState('https://lumengesso.com/gallery'); |
| 101 | const [pinning, setPinning] = useState(false); |
| 102 | const [pinSuccess, setPinSuccess] = useState<{ id: string; url?: string } | null>(null); |
| 103 | // Pin-flow error displayed INSIDE the modal — separate from the page-level |
| 104 | // `error` (used for delete failures), which lives above the grid and would |
| 105 | // be hidden behind the modal overlay if a pin failed. |
| 106 | const [pinError, setPinError] = useState<string | null>(null); |
| 107 | |
| 108 | const portraitCount = useMemo( |
| 109 | () => images.filter((im) => im.id.startsWith('portraits/')).length, |
| 110 | [images], |
| 111 | ); |
| 112 | |
| 113 | const filtered = useMemo(() => { |
| 114 | const ql = q.trim().toLowerCase(); |
| 115 | return images |
| 116 | .filter((im) => (scope === 'portraits' ? im.id.startsWith('portraits/') : true)) |
| 117 | .filter((im) => (ql ? im.id.toLowerCase().includes(ql) : true)) |
| 118 | .sort((a, b) => a.id.localeCompare(b.id)); |
| 119 | }, [images, scope, q]); |
| 120 | |
| 121 | // Reset paging whenever the visible set changes. |
| 122 | useEffect(() => { setLimit(BATCH); }, [q, scope]); |
| 123 | |
| 124 | // Reveal more as the sentinel nears the viewport. |
| 125 | useEffect(() => { |
| 126 | const el = sentinel.current; |
| 127 | if (!el) return; |
| 128 | const io = new IntersectionObserver( |
| 129 | (entries) => { if (entries[0].isIntersecting) setLimit((l) => l + BATCH); }, |
| 130 | { rootMargin: '800px' }, |
| 131 | ); |
| 132 | io.observe(el); |
| 133 | return () => io.disconnect(); |
| 134 | }, [filtered.length]); |
| 135 | |
| 136 | const shown = filtered.slice(0, limit); |
| 137 | const fileName = (id: string) => id.replace(/^portraits\//, ''); |
| 138 | |
| 139 | const remove = async (id: string) => { |
| 140 | const name = fileName(id); |
| 141 | if (!confirm(`Delete "${name}" from the CDN?\n\nThis is permanent. Any page that uses this image will return 404 until the URL is updated.`)) return; |
| 142 | setDeleting(id); |
| 143 | setError(null); |
| 144 | try { |
| 145 | const res = await fetch('/api/admin/images/delete', { |
| 146 | method: 'POST', |
| 147 | headers: { 'content-type': 'application/json' }, |
| 148 | body: JSON.stringify({ id }), |
| 149 | }); |
| 150 | const json = (await res.json().catch(() => ({}))) as { ok?: boolean; error?: string }; |
| 151 | if (!res.ok || !json.ok) throw new Error(json.error || `HTTP ${res.status}`); |
| 152 | // Optimistic: drop the tile from the visible grid. |
| 153 | setImages((arr) => arr.filter((im) => im.id !== id)); |
| 154 | } catch (e) { |
| 155 | setError(`Couldn't delete ${name}: ${e instanceof Error ? e.message : 'unknown error'}`); |
| 156 | } finally { |
| 157 | setDeleting(null); |
| 158 | } |
| 159 | }; |
| 160 | |
| 161 | const openPin = (im: CfImage) => { |
| 162 | setPinTarget(im); |
| 163 | setPinSuccess(null); |
| 164 | setPinError(null); |
| 165 | const name = fileName(im.id); |
| 166 | setPinTitle(prettifyName(name)); |
| 167 | setPinDescription(defaultDescriptionFor(name)); |
| 168 | // Lazy-load boards on first open. |
| 169 | if (!boards && !boardsLoading) { |
| 170 | setBoardsLoading(true); setBoardsError(null); |
| 171 | fetch('/api/admin/pinterest/boards') |
| 172 | .then((r) => r.json().then((j) => ({ ok: r.ok, j }))) |
| 173 | .then(({ ok, j }) => { |
| 174 | if (!ok) throw new Error(j?.error || 'failed to load boards'); |
| 175 | const list: PinBoard[] = (j.boards || []).map((b: PinBoard) => ({ id: b.id, name: b.name })); |
| 176 | setBoards(list); |
| 177 | if (list.length > 0) setBoardId(list[0].id); |
| 178 | }) |
| 179 | .catch((e) => setBoardsError(e instanceof Error ? e.message : 'failed to load boards')) |
| 180 | .finally(() => setBoardsLoading(false)); |
| 181 | } |
| 182 | }; |
| 183 | |
| 184 | const submitPin = async () => { |
| 185 | if (!pinTarget || !boardId) return; |
| 186 | setPinning(true); setPinError(null); |
| 187 | try { |
| 188 | const url = `${deliveryBase}/${pinTarget.id}/public`; |
| 189 | const res = await fetch('/api/admin/pinterest/pin', { |
| 190 | method: 'POST', |
| 191 | headers: { 'content-type': 'application/json' }, |
| 192 | body: JSON.stringify({ |
| 193 | boardId, |
| 194 | imageUrl: url, |
| 195 | title: pinTitle, |
| 196 | description: pinDescription, |
| 197 | link: pinLink || undefined, |
| 198 | altText: pinTitle, |
| 199 | }), |
| 200 | }); |
| 201 | const json = (await res.json().catch(() => ({}))) as { ok?: boolean; error?: string; pin?: { id: string; url?: string } }; |
| 202 | if (!res.ok || !json.ok || !json.pin) throw new Error(json.error || `HTTP ${res.status}`); |
| 203 | setPinSuccess(json.pin); |
| 204 | } catch (e) { |
| 205 | setPinError(e instanceof Error ? e.message : 'unknown error'); |
| 206 | } finally { |
| 207 | setPinning(false); |
| 208 | } |
| 209 | }; |
| 210 | |
| 211 | const closePinModal = () => { setPinTarget(null); setPinSuccess(null); setPinError(null); }; |
| 212 | |
| 213 | const copy = async (text: string, key: string) => { |
| 214 | try { |
| 215 | await navigator.clipboard.writeText(text); |
| 216 | setCopied(key); |
| 217 | setTimeout(() => setCopied((c) => (c === key ? null : c)), 1300); |
| 218 | } catch { /* clipboard blocked — ignore */ } |
| 219 | }; |
| 220 | |
| 221 | return ( |
| 222 | <div> |
| 223 | <div style={{ display: 'flex', gap: 12, alignItems: 'center', flexWrap: 'wrap', margin: '8px 0 14px' }}> |
| 224 | <div style={{ flex: '1 1 300px', minWidth: 0, position: 'relative' }}> |
| 225 | <input |
| 226 | value={q} |
| 227 | onChange={(e) => setQ(e.target.value)} |
| 228 | onKeyDown={(e) => { if (e.key === 'Escape' && q) { e.preventDefault(); setQ(''); } }} |
| 229 | placeholder="Filter by filename… (e.g. lifestyle, before-, popart, ziggy)" |
| 230 | style={{ |
| 231 | width: '100%', padding: '10px 36px 10px 12px', borderRadius: 8, boxSizing: 'border-box', |
| 232 | border: '1px solid var(--rule)', font: 'inherit', color: 'var(--ink)', background: '#fff', |
| 233 | }} |
| 234 | /> |
| 235 | {q && ( |
| 236 | <button |
| 237 | type="button" |
| 238 | onClick={() => setQ('')} |
| 239 | aria-label="Clear search" |
| 240 | title="Clear (Esc)" |
| 241 | style={{ |
| 242 | position: 'absolute', top: '50%', right: 8, transform: 'translateY(-50%)', |
| 243 | width: 22, height: 22, borderRadius: '50%', border: 'none', padding: 0, |
| 244 | background: 'var(--rule)', color: 'var(--ink)', cursor: 'pointer', |
| 245 | display: 'flex', alignItems: 'center', justifyContent: 'center', |
| 246 | fontSize: 14, lineHeight: 1, |
| 247 | }} |
| 248 | onMouseEnter={(e) => { e.currentTarget.style.background = 'var(--ink-soft)'; e.currentTarget.style.color = '#fff'; }} |
| 249 | onMouseLeave={(e) => { e.currentTarget.style.background = 'var(--rule)'; e.currentTarget.style.color = 'var(--ink)'; }} |
| 250 | > |
| 251 | × |
| 252 | </button> |
| 253 | )} |
| 254 | </div> |
| 255 | <div style={{ display: 'flex', gap: 6 }}> |
| 256 | {(['portraits', 'all'] as const).map((s) => ( |
| 257 | <button |
| 258 | key={s} |
| 259 | type="button" |
| 260 | onClick={() => setScope(s)} |
| 261 | style={{ |
| 262 | padding: '9px 13px', borderRadius: 8, cursor: 'pointer', fontSize: 13, |
| 263 | border: '1px solid var(--rule)', |
| 264 | background: scope === s ? 'var(--ink)' : 'transparent', |
| 265 | color: scope === s ? 'var(--cream)' : 'var(--ink)', |
| 266 | }} |
| 267 | > |
| 268 | {s === 'portraits' ? `Portraits (${portraitCount})` : `All images (${images.length})`} |
| 269 | </button> |
| 270 | ))} |
| 271 | </div> |
| 272 | </div> |
| 273 | |
| 274 | <p style={{ color: 'var(--ink-soft)', fontSize: 13, margin: '0 0 16px' }}> |
| 275 | Showing {Math.min(limit, filtered.length)} of {filtered.length} |
| 276 | {q ? ` matching “${q}”` : ''}. Click a filename to copy it. |
| 277 | </p> |
| 278 | |
| 279 | {error && ( |
| 280 | <div |
| 281 | role="alert" |
| 282 | style={{ |
| 283 | margin: '0 0 14px', padding: '10px 12px', borderRadius: 8, |
| 284 | border: '1px solid var(--rose)', background: 'var(--blush)', color: 'var(--rose-deep)', |
| 285 | fontSize: 13, display: 'flex', gap: 12, alignItems: 'flex-start', |
| 286 | }} |
| 287 | > |
| 288 | <span style={{ flex: 1 }}>{error}</span> |
| 289 | <button type="button" onClick={() => setError(null)} style={{ ...btn, padding: '3px 8px' }}>dismiss</button> |
| 290 | </div> |
| 291 | )} |
| 292 | |
| 293 | <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(184px, 1fr))', gap: 16 }}> |
| 294 | {shown.map((im) => { |
| 295 | const name = fileName(im.id); |
| 296 | const url = `${deliveryBase}/${im.id}/public`; |
| 297 | return ( |
| 298 | <figure |
| 299 | key={im.id} |
| 300 | style={{ margin: 0, border: '1px solid var(--rule)', borderRadius: 10, overflow: 'hidden', background: 'var(--cream-light)', position: 'relative' }} |
| 301 | > |
| 302 | <a href={url} target="_blank" rel="noopener noreferrer" style={{ display: 'block' }}> |
| 303 | {/* eslint-disable-next-line @next/next/no-img-element */} |
| 304 | <img |
| 305 | src={url} |
| 306 | alt={name} |
| 307 | loading="lazy" |
| 308 | decoding="async" |
| 309 | style={{ display: 'block', width: '100%', height: 168, objectFit: 'contain', background: '#1d1a17' }} |
| 310 | /> |
| 311 | </a> |
| 312 | {/* Top-right delete affordance — small circle, semi-transparent so it |
| 313 | never fights with the image. Sits as a sibling of the link so the |
| 314 | button click doesn't bubble into the new-tab navigation. */} |
| 315 | <button |
| 316 | type="button" |
| 317 | onClick={() => remove(im.id)} |
| 318 | disabled={deleting === im.id} |
| 319 | title={`Delete ${name} from the CDN`} |
| 320 | aria-label={`Delete ${name}`} |
| 321 | style={{ |
| 322 | position: 'absolute', |
| 323 | top: 8, |
| 324 | right: 8, |
| 325 | width: 26, |
| 326 | height: 26, |
| 327 | borderRadius: '50%', |
| 328 | border: 'none', |
| 329 | background: deleting === im.id ? 'rgba(31, 26, 22, 0.55)' : 'rgba(31, 26, 22, 0.72)', |
| 330 | color: '#fff', |
| 331 | cursor: deleting === im.id ? 'wait' : 'pointer', |
| 332 | display: 'flex', |
| 333 | alignItems: 'center', |
| 334 | justifyContent: 'center', |
| 335 | fontSize: 17, |
| 336 | lineHeight: 1, |
| 337 | fontWeight: 400, |
| 338 | boxShadow: '0 2px 8px rgba(0, 0, 0, 0.35)', |
| 339 | padding: 0, |
| 340 | zIndex: 2, |
| 341 | }} |
| 342 | onMouseEnter={(e) => { if (deleting !== im.id) e.currentTarget.style.background = 'var(--rose-deep)'; }} |
| 343 | onMouseLeave={(e) => { if (deleting !== im.id) e.currentTarget.style.background = 'rgba(31, 26, 22, 0.72)'; }} |
| 344 | > |
| 345 | {deleting === im.id ? '…' : '×'} |
| 346 | </button> |
| 347 | {pinterestReady && ( |
| 348 | <button |
| 349 | type="button" |
| 350 | onClick={() => openPin(im)} |
| 351 | title={`Pin ${name} to Pinterest`} |
| 352 | aria-label={`Pin ${name} to Pinterest`} |
| 353 | style={{ |
| 354 | position: 'absolute', |
| 355 | top: 8, |
| 356 | right: 42, |
| 357 | width: 26, |
| 358 | height: 26, |
| 359 | borderRadius: '50%', |
| 360 | border: 'none', |
| 361 | background: 'rgba(31, 26, 22, 0.72)', |
| 362 | color: '#fff', |
| 363 | cursor: 'pointer', |
| 364 | display: 'flex', |
| 365 | alignItems: 'center', |
| 366 | justifyContent: 'center', |
| 367 | fontSize: 13, |
| 368 | lineHeight: 1, |
| 369 | fontWeight: 700, |
| 370 | boxShadow: '0 2px 8px rgba(0, 0, 0, 0.35)', |
| 371 | padding: 0, |
| 372 | zIndex: 2, |
| 373 | }} |
| 374 | onMouseEnter={(e) => { e.currentTarget.style.background = '#bd081c'; }} |
| 375 | onMouseLeave={(e) => { e.currentTarget.style.background = 'rgba(31, 26, 22, 0.72)'; }} |
| 376 | > |
| 377 | P |
| 378 | </button> |
| 379 | )} |
| 380 | <figcaption style={{ padding: '8px 10px' }}> |
| 381 | <button |
| 382 | type="button" |
| 383 | onClick={() => copy(name, im.id)} |
| 384 | title="Click to copy filename" |
| 385 | style={{ all: 'unset', cursor: 'pointer', display: 'block', width: '100%', fontSize: 12, lineHeight: 1.35, color: 'var(--ink)', wordBreak: 'break-all' }} |
| 386 | > |
| 387 | {name} |
| 388 | </button> |
| 389 | <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginTop: 7, gap: 6 }}> |
| 390 | <span style={{ fontSize: 11, color: copied === im.id ? 'var(--rose-deep)' : 'var(--ink-soft)' }}> |
| 391 | {copied === im.id ? 'name copied ✓' : 'click name ↑'} |
| 392 | </span> |
| 393 | <button type="button" onClick={() => copy(url, `${im.id}:url`)} style={btn} disabled={deleting === im.id}> |
| 394 | {copied === `${im.id}:url` ? 'copied ✓' : 'copy URL'} |
| 395 | </button> |
| 396 | </div> |
| 397 | </figcaption> |
| 398 | </figure> |
| 399 | ); |
| 400 | })} |
| 401 | </div> |
| 402 | |
| 403 | {limit < filtered.length && ( |
| 404 | <> |
| 405 | <div ref={sentinel} aria-hidden="true" style={{ height: 1 }} /> |
| 406 | <div style={{ textAlign: 'center', margin: '22px 0' }}> |
| 407 | <button type="button" onClick={() => setLimit((l) => l + BATCH)} style={{ ...btn, padding: '9px 16px', fontSize: 13 }}> |
| 408 | Load more ({filtered.length - limit} left) |
| 409 | </button> |
| 410 | </div> |
| 411 | </> |
| 412 | )} |
| 413 | |
| 414 | {filtered.length === 0 && ( |
| 415 | <p style={{ color: 'var(--ink-soft)', textAlign: 'center', margin: '40px 0' }}>No images match “{q}”.</p> |
| 416 | )} |
| 417 | |
| 418 | {/* Pinterest pin modal — small bottom-anchored sheet so the admin can |
| 419 | tweak title/description and pick a board before pinning. Boards are |
| 420 | fetched lazily the first time the modal opens. */} |
| 421 | {pinTarget && ( |
| 422 | <div |
| 423 | role="dialog" |
| 424 | aria-modal="true" |
| 425 | aria-label="Pin to Pinterest" |
| 426 | style={{ position: 'fixed', inset: 0, background: 'rgba(31, 26, 22, 0.55)', zIndex: 50, display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 20 }} |
| 427 | onClick={(e) => { if (e.target === e.currentTarget) closePinModal(); }} |
| 428 | > |
| 429 | <div style={{ background: 'var(--cream)', borderRadius: 12, maxWidth: 520, width: '100%', maxHeight: '92vh', overflow: 'auto', boxShadow: '0 24px 60px rgba(0,0,0,0.25)' }}> |
| 430 | <div style={{ display: 'flex', gap: 14, padding: '16px 18px', borderBottom: '1px solid var(--rule)', alignItems: 'center' }}> |
| 431 | {/* eslint-disable-next-line @next/next/no-img-element */} |
| 432 | <img src={`${deliveryBase}/${pinTarget.id}/public`} alt="" style={{ width: 56, height: 56, objectFit: 'contain', background: '#1d1a17', borderRadius: 6 }} /> |
| 433 | <div style={{ minWidth: 0, flex: 1 }}> |
| 434 | <div style={{ fontSize: 11, fontWeight: 700, letterSpacing: '0.14em', textTransform: 'uppercase', color: 'var(--ink-soft)' }}>Pin to Pinterest</div> |
| 435 | <div style={{ fontSize: 13, color: 'var(--ink)', wordBreak: 'break-all' }}>{fileName(pinTarget.id)}</div> |
| 436 | </div> |
| 437 | <button type="button" onClick={closePinModal} aria-label="Close" style={{ ...btn, padding: '4px 9px', fontSize: 14 }}>×</button> |
| 438 | </div> |
| 439 | |
| 440 | {pinSuccess ? ( |
| 441 | <div style={{ padding: '24px 22px' }}> |
| 442 | <p style={{ margin: 0 }}>Pinned ✓ <span style={{ color: 'var(--ink-soft)', fontSize: 12 }}>(id <code>{pinSuccess.id}</code>)</span></p> |
| 443 | {pinSuccess.url && <p style={{ margin: '10px 0 0' }}><a href={pinSuccess.url} target="_blank" rel="noopener noreferrer">Open on Pinterest →</a></p>} |
| 444 | <div style={{ marginTop: 22, textAlign: 'right' }}> |
| 445 | <button type="button" onClick={closePinModal} style={{ ...btn, padding: '8px 14px', fontSize: 13 }}>Done</button> |
| 446 | </div> |
| 447 | </div> |
| 448 | ) : ( |
| 449 | <div style={{ padding: '18px 22px', display: 'flex', flexDirection: 'column', gap: 14 }}> |
| 450 | {pinError && ( |
| 451 | <div |
| 452 | role="alert" |
| 453 | style={{ |
| 454 | padding: '10px 12px', borderRadius: 8, |
| 455 | border: '1px solid var(--rose)', background: 'var(--blush)', color: 'var(--rose-deep)', |
| 456 | fontSize: 13, lineHeight: 1.4, wordBreak: 'break-word', |
| 457 | }} |
| 458 | > |
| 459 | <strong style={{ display: 'block', marginBottom: 3 }}>Pinterest rejected the pin</strong> |
| 460 | {pinError} |
| 461 | </div> |
| 462 | )} |
| 463 | <label style={{ display: 'block' }}> |
| 464 | <span style={{ fontSize: 11, fontWeight: 700, letterSpacing: '0.14em', textTransform: 'uppercase', color: 'var(--ink-soft)' }}>Board</span> |
| 465 | {boardsLoading && <div style={{ color: 'var(--ink-soft)', fontSize: 13, padding: '8px 0' }}>Loading your boards…</div>} |
| 466 | {boardsError && <div style={{ color: 'var(--rose-deep)', fontSize: 13, padding: '8px 0' }}>{boardsError}</div>} |
| 467 | {boards && ( |
| 468 | <select |
| 469 | value={boardId} |
| 470 | onChange={(e) => setBoardId(e.target.value)} |
| 471 | disabled={pinning} |
| 472 | style={{ marginTop: 5, width: '100%', padding: '9px 10px', borderRadius: 8, border: '1px solid var(--rule)', font: 'inherit', background: '#fff' }} |
| 473 | > |
| 474 | {boards.length === 0 && <option value="">(no boards — create one on Pinterest first)</option>} |
| 475 | {boards.map((b) => <option key={b.id} value={b.id}>{b.name}</option>)} |
| 476 | </select> |
| 477 | )} |
| 478 | </label> |
| 479 | |
| 480 | <label style={{ display: 'block' }}> |
| 481 | <span style={{ fontSize: 11, fontWeight: 700, letterSpacing: '0.14em', textTransform: 'uppercase', color: 'var(--ink-soft)' }}>Title</span> |
| 482 | <input |
| 483 | value={pinTitle} |
| 484 | onChange={(e) => setPinTitle(e.target.value)} |
| 485 | maxLength={100} |
| 486 | disabled={pinning} |
| 487 | style={{ marginTop: 5, width: '100%', padding: '9px 10px', borderRadius: 8, border: '1px solid var(--rule)', font: 'inherit', boxSizing: 'border-box' }} |
| 488 | /> |
| 489 | </label> |
| 490 | |
| 491 | <label style={{ display: 'block' }}> |
| 492 | <span style={{ fontSize: 11, fontWeight: 700, letterSpacing: '0.14em', textTransform: 'uppercase', color: 'var(--ink-soft)' }}>Description</span> |
| 493 | <textarea |
| 494 | value={pinDescription} |
| 495 | onChange={(e) => setPinDescription(e.target.value)} |
| 496 | maxLength={500} |
| 497 | rows={3} |
| 498 | disabled={pinning} |
| 499 | style={{ marginTop: 5, width: '100%', padding: '9px 10px', borderRadius: 8, border: '1px solid var(--rule)', font: 'inherit', resize: 'vertical', boxSizing: 'border-box' }} |
| 500 | /> |
| 501 | </label> |
| 502 | |
| 503 | <label style={{ display: 'block' }}> |
| 504 | <span style={{ fontSize: 11, fontWeight: 700, letterSpacing: '0.14em', textTransform: 'uppercase', color: 'var(--ink-soft)' }}>Link</span> |
| 505 | <input |
| 506 | value={pinLink} |
| 507 | onChange={(e) => setPinLink(e.target.value)} |
| 508 | disabled={pinning} |
| 509 | placeholder="https://www.lumengesso.com/…" |
| 510 | style={{ marginTop: 5, width: '100%', padding: '9px 10px', borderRadius: 8, border: '1px solid var(--rule)', font: 'inherit', boxSizing: 'border-box' }} |
| 511 | /> |
| 512 | </label> |
| 513 | |
| 514 | <div style={{ display: 'flex', justifyContent: 'flex-end', gap: 8, marginTop: 4 }}> |
| 515 | <button type="button" onClick={closePinModal} disabled={pinning} style={{ ...btn, padding: '9px 14px', fontSize: 13 }}>Cancel</button> |
| 516 | <button |
| 517 | type="button" |
| 518 | onClick={submitPin} |
| 519 | disabled={pinning || !boardId || !boards || boards.length === 0} |
| 520 | style={{ padding: '9px 16px', borderRadius: 8, border: 'none', background: '#bd081c', color: '#fff', cursor: pinning ? 'wait' : 'pointer', fontSize: 13, fontWeight: 600, opacity: pinning || !boardId ? 0.6 : 1 }} |
| 521 | > |
| 522 | {pinning ? 'Pinning…' : 'Pin to Pinterest'} |
| 523 | </button> |
| 524 | </div> |
| 525 | </div> |
| 526 | )} |
| 527 | </div> |
| 528 | </div> |
| 529 | )} |
| 530 | </div> |
| 531 | ); |
| 532 | } |