Initial commit: Luminary photo catalog and RAW editor

Browser-based photo catalog with an optional team server (SQLite + LibRaw).
Local database, uploaded photos, build output and dependencies are gitignored.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
2026-11-23 15:19:25 +00:00
commit cd52a2f82f
121 changed files with 101872 additions and 0 deletions
+496
View File
@@ -0,0 +1,496 @@
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import {
addGalleryComment,
galleryDownloadAllUrl,
galleryDownloadUrl,
loadGallery,
setGalleryPick,
setGalleryReview,
} from '../lib/api';
import type { GalleryPayload, GalleryPhoto } from '../lib/api';
/**
* The page a client opens from a proofing link. It is entirely session-free:
* the token in the URL is the only credential, and the API only ever returns
* the shared event's live photos.
*/
function clientIdentity() {
const key = 'lumenroom.proof.client';
let id = '';
let name = '';
try {
id = localStorage.getItem(`${key}.id`) ?? '';
name = localStorage.getItem(`${key}.name`) ?? '';
} catch {
/* private mode */
}
if (!id) {
id = `c-${Math.random().toString(36).slice(2, 10)}${Date.now().toString(36)}`;
try {
localStorage.setItem(`${key}.id`, id);
} catch {
/* private mode */
}
}
return { id, name };
}
function fmtDate(ms: number | null) {
if (!ms) return '';
return new Date(ms).toLocaleDateString(undefined, {
year: 'numeric',
month: 'long',
day: 'numeric',
});
}
function Heart({ filled }: { filled: boolean }) {
return (
<svg viewBox="0 0 24 24" width="16" height="16" aria-hidden="true">
<path
d="M12 20.4l-1.5-1.36C5.4 14.44 2 11.36 2 7.9 2 5.2 4.2 3 6.9 3c1.6 0 3.1.75 4.1 1.95A5.4 5.4 0 0 1 15.1 3C17.8 3 20 5.2 20 7.9c0 3.46-3.4 6.54-8.5 11.14L12 20.4z"
fill={filled ? 'currentColor' : 'none'}
stroke="currentColor"
strokeWidth="1.6"
strokeLinejoin="round"
/>
</svg>
);
}
export default function ProofingGallery({ token }: { token: string }) {
const identity = useRef(clientIdentity());
const nameRef = useRef<HTMLInputElement>(null);
const [clientName, setClientName] = useState(identity.current.name);
const [data, setData] = useState<GalleryPayload | null>(null);
const [loading, setLoading] = useState(true);
const [fatal, setFatal] = useState<string | null>(null);
const [error, setError] = useState<string | null>(null);
const [picks, setPicks] = useState<Set<string>>(new Set());
const [counts, setCounts] = useState<Record<string, number>>({});
const [onlyPicks, setOnlyPicks] = useState(false);
const [lightbox, setLightbox] = useState<string | null>(null);
const [saving, setSaving] = useState<Set<string>>(new Set());
const [commentDraft, setCommentDraft] = useState('');
const [feedbackBusy, setFeedbackBusy] = useState(false);
const load = useCallback(async () => {
try {
const payload = await loadGallery(token, identity.current.id);
setData(payload);
setPicks(new Set(payload.photos.filter((p) => p.mine).map((p) => p.id)));
const next: Record<string, number> = {};
for (const photo of payload.photos) if (photo.pickCount) next[photo.id] = photo.pickCount;
setCounts(next);
setFatal(null);
setError(null);
} catch (err) {
setFatal(err instanceof Error ? err.message : 'Could not open this gallery');
} finally {
setLoading(false);
}
}, [token]);
useEffect(() => {
void load();
}, [load]);
useEffect(() => {
document.title = data ? `${data.event.name} — Proofing` : 'Proofing gallery';
return () => {
document.title = 'Luminary';
};
}, [data]);
const rememberName = (name: string) => {
setClientName(name);
try {
localStorage.setItem('lumenroom.proof.client.name', name);
} catch {
/* private mode */
}
};
const togglePick = useCallback(
async (photo: GalleryPhoto) => {
if (saving.has(photo.id)) return;
if (!clientName.trim()) {
nameRef.current?.focus();
setError('Add your name so the photographer knows whose picks these are.');
return;
}
const picked = !picks.has(photo.id);
// Optimistic: the heart responds immediately, then reconciles with the
// shared count once the server has recorded the pick.
setPicks((prev) => {
const next = new Set(prev);
if (picked) next.add(photo.id);
else next.delete(photo.id);
return next;
});
setCounts((prev) => {
const next = { ...prev };
const value = Math.max(0, (next[photo.id] ?? 0) + (picked ? 1 : -1));
if (value) next[photo.id] = value;
else delete next[photo.id];
return next;
});
setSaving((prev) => new Set(prev).add(photo.id));
try {
await setGalleryPick(token, {
photoId: photo.id,
picked,
clientId: identity.current.id,
clientName: clientName.trim(),
});
} catch {
setPicks((prev) => {
const next = new Set(prev);
if (picked) next.delete(photo.id);
else next.add(photo.id);
return next;
});
setCounts((prev) => {
const next = { ...prev };
const value = Math.max(0, (next[photo.id] ?? 0) + (picked ? -1 : 1));
if (value) next[photo.id] = value;
else delete next[photo.id];
return next;
});
setError('That pick did not save — check the connection and try again.');
setTimeout(() => setError(null), 4000);
} finally {
setSaving((prev) => {
const next = new Set(prev);
next.delete(photo.id);
return next;
});
}
},
[clientName, picks, saving, token],
);
const submitComment = useCallback(
async (photo: GalleryPhoto) => {
const body = commentDraft.trim();
if (!body || feedbackBusy) return;
setFeedbackBusy(true);
try {
await addGalleryComment(token, {
photoId: photo.id,
clientId: identity.current.id,
clientName: clientName.trim(),
body,
});
setCommentDraft('');
await load();
} catch {
setError('That comment did not save — check the connection and try again.');
} finally {
setFeedbackBusy(false);
}
},
[clientName, commentDraft, feedbackBusy, load, token],
);
const submitReview = useCallback(
async (photo: GalleryPhoto, status: 'approved' | 'changes' | 'none') => {
if (feedbackBusy) return;
if (!clientName.trim()) {
nameRef.current?.focus();
setError('Add your name before approving photos or requesting changes.');
return;
}
setFeedbackBusy(true);
try {
await setGalleryReview(token, {
photoId: photo.id,
clientId: identity.current.id,
clientName: clientName.trim(),
status,
});
await load();
} catch {
setError('That review did not save — check the connection and try again.');
} finally {
setFeedbackBusy(false);
}
},
[clientName, feedbackBusy, load, token],
);
const visible = useMemo(() => {
if (!data) return [];
return onlyPicks ? data.photos.filter((p) => picks.has(p.id)) : data.photos;
}, [data, onlyPicks, picks]);
const lightboxIndex = lightbox ? visible.findIndex((p) => p.id === lightbox) : -1;
const lightboxPhoto = lightboxIndex >= 0 ? visible[lightboxIndex] : null;
useEffect(() => {
if (!lightboxPhoto) return;
const onKey = (e: KeyboardEvent) => {
if (e.key === 'Escape') {
setLightbox(null);
return;
}
if (e.key === 'ArrowRight' || e.key === 'ArrowLeft') {
const next = visible[lightboxIndex + (e.key === 'ArrowRight' ? 1 : -1)];
if (next) setLightbox(next.id);
return;
}
if (e.key === ' ') {
e.preventDefault();
void togglePick(lightboxPhoto);
}
};
window.addEventListener('keydown', onKey);
return () => window.removeEventListener('keydown', onKey);
}, [lightboxIndex, lightboxPhoto, togglePick, visible]);
if (loading) {
return (
<div className="proof">
<div className="proof-splash">
<div className="logo large">Luminary</div>
<p>Loading your gallery…</p>
</div>
</div>
);
}
if (!data) {
return (
<div className="proof">
<div className="proof-splash">
<div className="logo large">Luminary</div>
<h1>This gallery isn’t available</h1>
<p>{fatal ?? 'The link may have expired, or the photographer turned it off.'}</p>
</div>
</div>
);
}
const pickedCount = picks.size;
return (
<div className="proof">
<header className="proof-head">
<div className="proof-head-main">
<div className="proof-brand">
<span className="dot" /> Luminary
</div>
<h1>{data.event.name}</h1>
<p className="proof-sub">
{fmtDate(data.event.date)}
{data.event.date ? ' · ' : ''}
{data.photos.length} photo{data.photos.length === 1 ? '' : 's'}
{data.event.notes ? ` · ${data.event.notes}` : ''}
</p>
</div>
<div className="proof-head-side">
<label className="proof-name">
<span>Your name</span>
<input
ref={nameRef}
value={clientName}
placeholder="Add your name"
maxLength={60}
onChange={(e) => rememberName(e.target.value)}
/>
</label>
<div className={`proof-count ${pickedCount ? 'on' : ''}`}>
<Heart filled={pickedCount > 0} />
{pickedCount} pick{pickedCount === 1 ? '' : 's'}
</div>
</div>
</header>
<div className="proof-intro">
<p>
Tap the heart on the photos you love. Your picks are saved as you go — no account
needed, and you can come back to this link any time.
</p>
<div className="proof-tools">
<button
className={`chip ${onlyPicks ? 'on' : ''}`}
onClick={() => setOnlyPicks((v) => !v)}
disabled={!pickedCount && !onlyPicks}
>
My picks {pickedCount ? `(${pickedCount})` : ''}
</button>
{pickedCount > 0 && (
<a
className="btn ghost small"
href={galleryDownloadAllUrl(token, identity.current.id)}
download
>
Download picks
</a>
)}
<span className="proof-subtle">
{data.picks.total
? `${data.picks.total} pick${data.picks.total === 1 ? '' : 's'} from ${
data.picks.clients
} client${data.picks.clients === 1 ? '' : 's'} so far`
: 'Be the first to choose'}
</span>
</div>
</div>
{error && <div className="proof-toast">{error}</div>}
{onlyPicks && !visible.length ? (
<div className="proof-empty">
<Heart filled={false} />
<h2>No picks yet</h2>
<p>Tap a heart on any photo and it will show up here.</p>
<button className="btn" onClick={() => setOnlyPicks(false)}>
Back to all photos
</button>
</div>
) : (
<div className="proof-grid">
{visible.map((photo, i) => {
const picked = picks.has(photo.id);
return (
<figure
key={photo.id}
className={`proof-card ${picked ? 'picked' : ''}`}
style={{ animationDelay: `${Math.min(i, 16) * 28}ms` }}
>
<button
className="proof-shot"
onClick={() => setLightbox(photo.id)}
title={photo.name}
>
<img
src={photo.thumbUrl}
alt={photo.name}
loading={i < 12 ? 'eager' : 'lazy'}
draggable={false}
/>
</button>
<button
className={`proof-heart ${picked ? 'on' : ''}`}
onClick={() => void togglePick(photo)}
aria-pressed={picked}
title={picked ? 'Remove from picks' : 'Pick this photo'}
>
<Heart filled={picked} />
{counts[photo.id] ? <span>{counts[photo.id]}</span> : null}
</button>
<div className="proof-feedback-badges">
{photo.reviewStatus === 'approved' && <span className="proof-review approved">✓ Approved</span>}
{photo.reviewStatus === 'changes' && <span className="proof-review changes">! Changes</span>}
{photo.comments.length > 0 && <span className="proof-comment-count">💬 {photo.comments.length}</span>}
</div>
</figure>
);
})}
</div>
)}
<footer className="proof-foot">
<span>Proofing gallery by Luminary</span>
<span>{clientName.trim() ? `Picks saved for ${clientName.trim()}` : 'Your picks save automatically'}</span>
</footer>
{lightboxPhoto && (
<div className="proof-lb" onClick={() => setLightbox(null)}>
<button className="proof-lb-close" onClick={() => setLightbox(null)} title="Close (Esc)">
×
</button>
<button
className="proof-lb-nav prev"
onClick={(e) => {
e.stopPropagation();
const prev = visible[lightboxIndex - 1];
if (prev) setLightbox(prev.id);
}}
disabled={lightboxIndex <= 0}
title="Previous"
>
‹
</button>
<div className="proof-lb-body" onClick={(e) => e.stopPropagation()}>
<img src={lightboxPhoto.previewUrl} alt={lightboxPhoto.name} draggable={false} />
<div className="proof-lb-bar">
<div className="proof-lb-title">
<span className="proof-lb-name">{lightboxPhoto.name}</span>
<a className="btn ghost small" href={galleryDownloadUrl(token, lightboxPhoto.id)} download>
Download
</a>
</div>
<button
className={`proof-lb-pick ${picks.has(lightboxPhoto.id) ? 'on' : ''}`}
onClick={() => void togglePick(lightboxPhoto)}
>
<Heart filled={picks.has(lightboxPhoto.id)} />
{picks.has(lightboxPhoto.id) ? 'Picked' : 'Pick this photo'}
</button>
</div>
<div className="proof-review-bar">
<span className="muted small">Review</span>
<button
className={`chip ${lightboxPhoto.reviewStatus === 'approved' ? 'on' : ''}`}
onClick={() => void submitReview(lightboxPhoto, lightboxPhoto.reviewStatus === 'approved' ? 'none' : 'approved')}
disabled={feedbackBusy}
>
✓ Approve
</button>
<button
className={`chip ${lightboxPhoto.reviewStatus === 'changes' ? 'on' : ''}`}
onClick={() => void submitReview(lightboxPhoto, lightboxPhoto.reviewStatus === 'changes' ? 'none' : 'changes')}
disabled={feedbackBusy}
>
! Needs changes
</button>
</div>
<div className="proof-comments">
<div className="proof-comments-head">Comments · {lightboxPhoto.comments.length}</div>
{lightboxPhoto.comments.map((comment) => (
<div key={comment.id} className="proof-comment">
<strong>{comment.clientName || 'Client'}</strong>
<span>{comment.body}</span>
</div>
))}
<div className="proof-comment-add">
<input
value={commentDraft}
placeholder={clientName.trim() ? 'Add a note…' : 'Add your name above, then comment'}
maxLength={1200}
onChange={(e) => setCommentDraft(e.target.value)}
onKeyDown={(e) => {
if (e.key === 'Enter') void submitComment(lightboxPhoto);
}}
disabled={!clientName.trim() || feedbackBusy}
/>
<button
className="btn primary small"
onClick={() => void submitComment(lightboxPhoto)}
disabled={!commentDraft.trim() || !clientName.trim() || feedbackBusy}
>
Send
</button>
</div>
</div>
</div>
<button
className="proof-lb-nav next"
onClick={(e) => {
e.stopPropagation();
const next = visible[lightboxIndex + 1];
if (next) setLightbox(next.id);
}}
disabled={lightboxIndex >= visible.length - 1}
title="Next"
>
›
</button>
</div>
)}
</div>
);
}