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:
@@ -0,0 +1,203 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import type { Health, SessionUser } from '../lib/api';
|
||||
|
||||
interface Props {
|
||||
health: Health | null;
|
||||
user: SessionUser | null;
|
||||
busy: boolean;
|
||||
note: string | null;
|
||||
error: string | null;
|
||||
onLogin: (email: string, password: string) => void;
|
||||
onRegister: (input: { email: string; password: string; name: string; invite: string }) => void;
|
||||
onLogout: () => void;
|
||||
onSync: () => void;
|
||||
onAdmin: () => void;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
function fmtBytes(bytes: number) {
|
||||
if (bytes > 1024 ** 3) return `${(bytes / 1024 ** 3).toFixed(1)} GB`;
|
||||
if (bytes > 1024 ** 2) return `${(bytes / 1024 ** 2).toFixed(0)} MB`;
|
||||
return `${Math.round(bytes / 1024)} KB`;
|
||||
}
|
||||
|
||||
export default function CloudPanel({
|
||||
health,
|
||||
user,
|
||||
busy,
|
||||
note,
|
||||
error,
|
||||
onLogin,
|
||||
onRegister,
|
||||
onLogout,
|
||||
onSync,
|
||||
onAdmin,
|
||||
onClose,
|
||||
}: Props) {
|
||||
const [mode, setMode] = useState<'signin' | 'signup'>('signin');
|
||||
const [email, setEmail] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [name, setName] = useState('');
|
||||
const [invite, setInvite] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.key !== 'Escape') return;
|
||||
e.preventDefault();
|
||||
e.stopImmediatePropagation();
|
||||
if (!busy) onClose();
|
||||
};
|
||||
window.addEventListener('keydown', onKey, true);
|
||||
return () => window.removeEventListener('keydown', onKey, true);
|
||||
}, [busy, onClose]);
|
||||
|
||||
const submit = () => {
|
||||
if (busy) return;
|
||||
if (mode === 'signin') onLogin(email.trim(), password);
|
||||
else onRegister({ email: email.trim(), password, name: name.trim(), invite: invite.trim() });
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="modal-backdrop" onPointerDown={(e) => e.target === e.currentTarget && onClose()}>
|
||||
<div className="modal cloud-modal">
|
||||
<header className="modal-head">
|
||||
<h2>Team server</h2>
|
||||
<button className="icon-btn" onClick={onClose}>
|
||||
✕
|
||||
</button>
|
||||
</header>
|
||||
|
||||
<div className="modal-body">
|
||||
{!health ? (
|
||||
<div className="cloud-offline">
|
||||
<strong>No server detected</strong>
|
||||
<p className="muted small">
|
||||
The library is running fully in this browser. To share photos with the team, start the
|
||||
server and reload:
|
||||
</p>
|
||||
<pre className="code-block">npm run server</pre>
|
||||
<p className="muted small">
|
||||
Originals, edits and ratings are then stored on disk under <code>server/data</code>.
|
||||
</p>
|
||||
</div>
|
||||
) : user ? (
|
||||
<div className="cloud-account">
|
||||
<div className="cloud-hero">
|
||||
<div className="cloud-avatar">{(user.name || user.email).slice(0, 1).toUpperCase()}</div>
|
||||
<div>
|
||||
<strong>{user.name || user.email}</strong>
|
||||
<div className="muted small">
|
||||
{user.email} · {user.role}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<dl className="cloud-stats">
|
||||
<div>
|
||||
<dt>Photos on server</dt>
|
||||
<dd>{health.photos}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>Storage used</dt>
|
||||
<dd>{fmtBytes(health.bytes)}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>Raw engine</dt>
|
||||
<dd>{health.raw.libraw ? 'LibRaw demosaic' : 'Embedded previews'}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>Server version</dt>
|
||||
<dd>{health.version}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
<div className="btn-row">
|
||||
<button className="btn primary" onClick={onSync} disabled={busy}>
|
||||
{busy ? 'Syncing…' : 'Sync library'}
|
||||
</button>
|
||||
<button className="btn ghost" onClick={onLogout} disabled={busy}>
|
||||
Sign out
|
||||
</button>
|
||||
{user.role === 'admin' && (
|
||||
<button className="btn ghost" onClick={onAdmin} disabled={busy}>
|
||||
Administration
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{note && <div className="banner ok">{note}</div>}
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="tabs">
|
||||
<button className={`tab ${mode === 'signin' ? 'on' : ''}`} onClick={() => setMode('signin')}>
|
||||
Sign in
|
||||
</button>
|
||||
<button className={`tab ${mode === 'signup' ? 'on' : ''}`} onClick={() => setMode('signup')}>
|
||||
{health.needsSetup ? 'Create admin' : 'Join team'}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<label className="field">
|
||||
<span>Email</span>
|
||||
<input
|
||||
type="email"
|
||||
autoComplete="username"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
onKeyDown={(e) => e.key === 'Enter' && submit()}
|
||||
/>
|
||||
</label>
|
||||
|
||||
{mode === 'signup' && (
|
||||
<label className="field">
|
||||
<span>Display name</span>
|
||||
<input value={name} onChange={(e) => setName(e.target.value)} placeholder="Optional" />
|
||||
</label>
|
||||
)}
|
||||
|
||||
<label className="field">
|
||||
<span>Password</span>
|
||||
<input
|
||||
type="password"
|
||||
autoComplete={mode === 'signin' ? 'current-password' : 'new-password'}
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
onKeyDown={(e) => e.key === 'Enter' && submit()}
|
||||
/>
|
||||
</label>
|
||||
|
||||
{mode === 'signup' && !health.needsSetup && (
|
||||
<label className="field">
|
||||
<span>Invite link or code</span>
|
||||
<input
|
||||
value={invite}
|
||||
onChange={(e) => setInvite(e.target.value)}
|
||||
placeholder="Paste the link from your admin"
|
||||
/>
|
||||
</label>
|
||||
)}
|
||||
|
||||
{mode === 'signup' && health.needsSetup && (
|
||||
<p className="muted small">
|
||||
The first account becomes the team admin. After that, create single-use invite links under
|
||||
Administration → Invites.
|
||||
</p>
|
||||
)}
|
||||
|
||||
<button className="btn primary wide" onClick={submit} disabled={busy || !email || !password}>
|
||||
{busy ? 'Working…' : mode === 'signin' ? 'Sign in' : 'Create account'}
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
|
||||
{error && <div className="banner error">{error}</div>}
|
||||
|
||||
{health && (
|
||||
<p className="muted small cloud-foot">
|
||||
Server sharing the folder <code>{health.storage?.root ?? 'server/data'}</code> · raw formats:{' '}
|
||||
{health.raw.formats.length} · {health.raw.sharp ? 'JPEG encoder ready' : 'PNG fallback'}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user