Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: unite casting references with their visuals

[._.]/ Adam Eivyc73b6e2c4796
diff --git a/client/src/components/catalog/CatalogReferenceLibrary.jsx b/client/src/components/catalog/CatalogReferenceLibrary.jsx
index 503b283c9b..17abbcfd68 100644
--- a/client/src/components/catalog/CatalogReferenceLibrary.jsx
+++ b/client/src/components/catalog/CatalogReferenceLibrary.jsx
@@ -1,27 +1,30 @@
-import { useMemo, useState } from 'react';
+import { useId, useMemo, useState } from 'react';
import { Compass, Star } from 'lucide-react';
+import CatalogMediaTile from './CatalogMediaTile';
+import { formatCount } from '../../utils/formatters';
import { updateCatalogIngredientMediaLibrary, attachCatalogIngredientMediaFromMoodBoard } from '../../services/apiCatalog';
-// Casting reference library: tag each reference/sheet/still/clip of a cast
-// member with the variant it shows (which of the record's saved ages/looks —
-// `forms`, canonical when untagged — plus age, era) and tags, mark up to four
-// as render guides, and filter the library by those fields. The media grid
-// below still owns attach/upload/detach/portrait.
export const MAX_CAST_GUIDES = 4;
const ERAS = ['child', 'teen', 'adult', 'elder'];
const LIBRARY_KINDS = new Set(['portrait', 'reference', 'video']);
const eraFor = (m) => m.library?.variant?.era
|| (Number.isInteger(m.library?.variant?.age) ? (m.library.variant.age < 13 ? 'child' : m.library.variant.age < 20 ? 'teen' : m.library.variant.age < 65 ? 'adult' : 'elder') : '');
-export default function CatalogReferenceLibrary({ ingredientId, media = [], forms = [], readOnly = false, onChanged }) {
+export default function CatalogReferenceLibrary({ ingredientId, media = [], forms = [], readOnly = false, onChanged, guideMedia = media, missingMedia = new Set(), onSetPortrait, onDetach }) {
+ const id = useId();
+ const [armedDetach, setArmedDetach] = useState(null);
const [filter, setFilter] = useState({ form: '', age: '', era: '', tag: '', guides: false });
const [error, setError] = useState('');
const [busyKey, setBusyKey] = useState('');
const [boardId, setBoardId] = useState('');
const [itemIds, setItemIds] = useState('');
- const rows = useMemo(() => media.filter((m) => !m.deleted && LIBRARY_KINDS.has(m.kind)), [media]);
- const guideCount = rows.filter((m) => m.library?.guide === true).length;
+ const rows = useMemo(() => {
+ const portraits = new Set(media.filter((m) => !m.deleted && m.kind === 'portrait').map((m) => m.mediaKey));
+ return media.filter((m) => !m.deleted && LIBRARY_KINDS.has(m.kind) && !(m.kind === 'reference' && portraits.has(m.mediaKey)));
+ }, [media]);
+ // Sheets and looks in other tabs still consume the character-wide guide limit.
+ const guideCount = guideMedia.filter((m) => !m.deleted && LIBRARY_KINDS.has(m.kind) && m.library?.guide === true).length;
const ages = [...new Set(rows.map((m) => m.library?.variant?.age).filter(Number.isInteger))].sort((a, b) => a - b);
const tags = [...new Set(rows.flatMap((m) => m.library?.tags || []))].sort();
const formKey = (m) => m.library?.variant?.formId || 'canonical';
@@ -35,7 +38,7 @@ export default function CatalogReferenceLibrary({ ingredientId, media = [], form
setError('');
setBusyKey(`${m.kind}:${m.mediaKey}`);
try {
- await updateCatalogIngredientMediaLibrary(ingredientId, { mediaKey: m.mediaKey, kind: m.kind, ...patch });
+ await updateCatalogIngredientMediaLibrary(ingredientId, { mediaKey: m.mediaKey, kind: m.kind, ...patch }, { silent: true });
onChanged?.();
} catch (err) {
setError(err?.message || 'Could not update reference');
@@ -49,7 +52,7 @@ export default function CatalogReferenceLibrary({ ingredientId, media = [], form
if (!boardId.trim() || ids.length === 0) return;
setError('');
try {
- await attachCatalogIngredientMediaFromMoodBoard(ingredientId, { boardId: boardId.trim(), itemIds: ids, inferAge: true });
+ await attachCatalogIngredientMediaFromMoodBoard(ingredientId, { boardId: boardId.trim(), itemIds: ids, inferAge: true }, { silent: true });
setItemIds('');
onChanged?.();
} catch (err) {
@@ -57,103 +60,136 @@ export default function CatalogReferenceLibrary({ ingredientId, media = [], form
}
};
+ const fieldClass = 'min-h-11 min-w-0 w-full rounded border border-port-border bg-port-bg px-2 text-sm';
+
return (
- <section aria-label="Reference library" className="space-y-3 rounded border border-port-border p-3">
- <header className="flex flex-wrap items-center gap-2 text-sm">
+ <section aria-label="Reference library" className="min-w-0 space-y-3">
+ <header className="flex flex-wrap items-center justify-between gap-2 text-sm">
<h3 className="font-semibold">Reference library</h3>
- <span data-testid="guide-count" className="text-gray-400">{guideCount}/{MAX_CAST_GUIDES} render guides</span>
+ <span data-testid="guide-count" className="text-gray-400">{formatCount(guideCount)}/{MAX_CAST_GUIDES} render guides</span>
+ </header>
+ <div className="grid grid-cols-[repeat(auto-fit,minmax(min(100%,9rem),1fr))] items-end gap-2 text-xs">
{forms.length > 0 && (
- <label className="ml-auto flex items-center gap-1">Form
- <select aria-label="Filter by age or look" value={filter.form} onChange={(e) => setFilter({ ...filter, form: e.target.value })} className="bg-port-card">
+ <label htmlFor={`${id}-form`} className="min-w-0 space-y-1"><span>Age or look</span>
+ <select id={`${id}-form`} aria-label="Filter by age or look" value={filter.form} onChange={(e) => setFilter({ ...filter, form: e.target.value })} className={fieldClass}>
<option value="">All</option>
<option value="canonical">Canonical</option>
{forms.map((f) => <option key={f.id} value={f.id}>{f.label}</option>)}
</select>
</label>
)}
- <label className={`${forms.length > 0 ? '' : 'ml-auto '}flex items-center gap-1`}>Age
- <select aria-label="Filter by age" value={filter.age} onChange={(e) => setFilter({ ...filter, age: e.target.value })} className="bg-port-card">
+ <label htmlFor={`${id}-age`} className="min-w-0 space-y-1"><span>Age</span>
+ <select id={`${id}-age`} aria-label="Filter by age" value={filter.age} onChange={(e) => setFilter({ ...filter, age: e.target.value })} className={fieldClass}>
<option value="">All</option>
- {ages.map((a) => <option key={a} value={a}>{a}</option>)}
+ {ages.map((age) => <option key={age} value={age}>{age}</option>)}
</select>
</label>
- <label className="flex items-center gap-1">Era
- <select aria-label="Filter by era" value={filter.era} onChange={(e) => setFilter({ ...filter, era: e.target.value })} className="bg-port-card">
+ <label htmlFor={`${id}-era`} className="min-w-0 space-y-1"><span>Era</span>
+ <select id={`${id}-era`} aria-label="Filter by era" value={filter.era} onChange={(e) => setFilter({ ...filter, era: e.target.value })} className={fieldClass}>
<option value="">All</option>
{ERAS.map((era) => <option key={era} value={era}>{era}</option>)}
</select>
</label>
{tags.length > 0 && (
- <label className="flex items-center gap-1">Tag
- <select aria-label="Filter by tag" value={filter.tag} onChange={(e) => setFilter({ ...filter, tag: e.target.value })} className="bg-port-card">
+ <label htmlFor={`${id}-tag`} className="min-w-0 space-y-1"><span>Tag</span>
+ <select id={`${id}-tag`} aria-label="Filter by tag" value={filter.tag} onChange={(e) => setFilter({ ...filter, tag: e.target.value })} className={fieldClass}>
<option value="">All</option>
- {tags.map((t) => <option key={t} value={t}>{t}</option>)}
+ {tags.map((tag) => <option key={tag} value={tag}>{tag}</option>)}
</select>
</label>
)}
- <label className="flex items-center gap-1">
- <input type="checkbox" checked={filter.guides} onChange={(e) => setFilter({ ...filter, guides: e.target.checked })} /> Guides only
+ <label htmlFor={`${id}-guides`} className="flex min-h-11 items-center gap-2">
+ <input id={`${id}-guides`} type="checkbox" checked={filter.guides} onChange={(e) => setFilter({ ...filter, guides: e.target.checked })} /> Guides only
</label>
- </header>
+ </div>
{error && <p role="alert" className="text-sm text-port-error">{error}</p>}
- {visible.length === 0 ? <p className="text-sm text-gray-400">No references match.</p> : (
- <ul className="grid gap-2 sm:grid-cols-2 lg:grid-cols-3">
+ {visible.length === 0 ? <p className="text-sm text-gray-400">{rows.length ? 'No references match. Change the filters to see more.' : 'No references yet. Add an image or video to start your library.'}</p> : (
+ <ul className="grid items-start grid-cols-[repeat(auto-fill,minmax(min(100%,16rem),1fr))] gap-3">
{visible.map((m) => {
const key = `${m.kind}:${m.mediaKey}`;
const lib = m.library || {};
const isGuide = lib.guide === true;
- const busy = busyKey === key;
+ const editable = !readOnly && !m.readOnly;
+ const title = lib.variant?.label || m.caption || m.mediaKey;
+ const summary = [forms.find((f) => f.id === lib.variant?.formId)?.label || 'Canonical',
+ Number.isInteger(lib.variant?.age) ? `Age ${lib.variant.age}` : '', eraFor(m), ...(lib.tags || [])].filter(Boolean).join(' · ');
return (
- <li key={key} data-testid="library-row" className="space-y-1 rounded bg-port-card p-2 text-xs">
- <div className="flex items-center gap-1">
- {m.kind === 'portrait' && <Star size={12} aria-label="Primary" />}
- <span className="truncate" title={m.mediaKey}>{lib.variant?.label || m.caption || m.mediaKey}</span>
- <span className="ml-auto text-gray-500">{m.kind}</span>
- </div>
- {!readOnly && (
- <div className="flex flex-wrap items-center gap-1">
- {forms.length > 0 && (
- <select aria-label={`Age or look for ${m.mediaKey}`} value={lib.variant?.formId || ''} className="bg-port-bg"
- onChange={(e) => save(m, { variant: { ...(lib.variant || {}), formId: e.target.value || undefined } })}>
- <option value="">Canonical</option>
- {forms.map((f) => <option key={f.id} value={f.id}>{f.label}</option>)}
- </select>
- )}
- <input aria-label={`Age for ${m.mediaKey}`} type="number" min="0" max="150" defaultValue={lib.variant?.age ?? ''} className="w-14 bg-port-bg"
- onBlur={(e) => {
- const age = e.target.value === '' ? undefined : Number(e.target.value);
- if (age !== lib.variant?.age) save(m, { variant: { ...(lib.variant || {}), age } });
- }} />
- <select aria-label={`Era for ${m.mediaKey}`} value={lib.variant?.era || ''} className="bg-port-bg"
- onChange={(e) => save(m, { variant: { ...(lib.variant || {}), era: e.target.value || undefined } })}>
- <option value="">era</option>
- {ERAS.map((era) => <option key={era} value={era}>{era}</option>)}
- </select>
- <input aria-label={`Tags for ${m.mediaKey}`} defaultValue={(lib.tags || []).join(', ')} placeholder="tags" className="w-24 bg-port-bg"
- onBlur={(e) => {
- const next = e.target.value.split(',').map((t) => t.trim()).filter(Boolean);
- if (next.join(',') !== (lib.tags || []).join(',')) save(m, { tags: next });
- }} />
- {m.kind !== 'video' && (
- <button type="button" disabled={busy || (!isGuide && guideCount >= MAX_CAST_GUIDES)} aria-pressed={isGuide}
- title={!isGuide && guideCount >= MAX_CAST_GUIDES ? `At most ${MAX_CAST_GUIDES} render guides` : 'Use as a render guide'}
- onClick={() => save(m, { guide: !isGuide })} className="flex items-center gap-1">
- <Compass size={12} /> {isGuide ? 'Guide' : 'Make guide'}
- </button>
- )}
+ <li key={key} data-testid="library-row" className="min-w-0 rounded-lg border border-port-border bg-port-bg">
+ <CatalogMediaTile m={m} missing={missingMedia.has(m.mediaKey)} contain
+ isPortrait={m.kind === 'portrait'} onSetPortrait={editable ? onSetPortrait : undefined}
+ onDetach={editable ? onDetach : undefined} armedDetach={armedDetach} onArmDetach={setArmedDetach} />
+ <div className="min-w-0 space-y-2 p-3">
+ <div className="flex min-w-0 items-start gap-2">
+ {m.kind === 'portrait' && <Star size={14} aria-label="Primary" className="mt-0.5 shrink-0 text-port-warning" />}
+ <h4 className="min-w-0 flex-1 text-sm font-medium [overflow-wrap:anywhere]">{title}</h4>
+ <span className="shrink-0 text-xs text-gray-500">{m.kind}</span>
</div>
- )}
+ <p className="text-xs text-gray-400 [overflow-wrap:anywhere]">{summary}</p>
+ {m.kind !== 'video' && (editable ? (
+ <button type="button" disabled={!!busyKey || (!isGuide && guideCount >= MAX_CAST_GUIDES)} aria-pressed={isGuide}
+ title={!isGuide && guideCount >= MAX_CAST_GUIDES ? `At most ${MAX_CAST_GUIDES} render guides` : 'Use as a render guide'}
+ onClick={() => save(m, { guide: !isGuide })}
+ className={`flex min-h-11 w-full items-center justify-center gap-2 rounded border px-3 text-sm disabled:opacity-40 ${isGuide ? 'border-port-accent bg-port-accent/10 text-port-accent' : 'border-port-border text-gray-300 hover:border-port-accent'}`}>
+ <Compass size={16} aria-hidden="true" /> {busyKey === key ? 'Saving…' : isGuide ? 'Guide' : 'Make guide'}
+ </button>
+ ) : isGuide && <p className="text-xs text-port-accent">Render guide</p>)}
+ {editable && (
+ <details>
+ <summary className="flex min-h-11 cursor-pointer items-center text-xs text-port-accent">Edit reference details</summary>
+ <fieldset disabled={!!busyKey} className="grid min-w-0 grid-cols-[repeat(auto-fit,minmax(min(100%,7rem),1fr))] gap-2 text-xs disabled:opacity-50">
+ {forms.length > 0 && (
+ <label htmlFor={`${id}-${key}-form`} className="min-w-0 space-y-1"><span>Age or look</span>
+ <select id={`${id}-${key}-form`} aria-label={`Age or look for ${m.mediaKey}`} value={lib.variant?.formId || ''} className={fieldClass}
+ onChange={(e) => save(m, { variant: { ...(lib.variant || {}), formId: e.target.value || undefined } })}>
+ <option value="">Canonical</option>
+ {forms.map((f) => <option key={f.id} value={f.id}>{f.label}</option>)}
+ </select>
+ </label>
+ )}
+ <label htmlFor={`${id}-${key}-age`} className="min-w-0 space-y-1"><span>Age</span>
+ <input id={`${id}-${key}-age`} aria-label={`Age for ${m.mediaKey}`} type="number" min="0" max="150" defaultValue={lib.variant?.age ?? ''} className={fieldClass}
+ onBlur={(e) => {
+ if (!e.target.validity.valid) return;
+ const age = e.target.value === '' ? undefined : Number(e.target.value);
+ if (age !== lib.variant?.age) save(m, { variant: { ...(lib.variant || {}), age } });
+ }} />
+ </label>
+ <label htmlFor={`${id}-${key}-era`} className="min-w-0 space-y-1"><span>Era</span>
+ <select id={`${id}-${key}-era`} aria-label={`Era for ${m.mediaKey}`} value={lib.variant?.era || ''} className={fieldClass}
+ onChange={(e) => save(m, { variant: { ...(lib.variant || {}), era: e.target.value || undefined } })}>
+ <option value="">From age</option>
+ {ERAS.map((era) => <option key={era} value={era}>{era}</option>)}
+ </select>
+ </label>
+ <label htmlFor={`${id}-${key}-tags`} className="col-span-full min-w-0 space-y-1"><span>Tags (comma separated)</span>
+ <input id={`${id}-${key}-tags`} aria-label={`Tags for ${m.mediaKey}`} defaultValue={(lib.tags || []).join(', ')} placeholder="e.g. studio, winter" className={fieldClass}
+ onBlur={(e) => {
+ const next = e.target.value.split(',').map((tag) => tag.trim()).filter(Boolean);
+ if (next.join(',') !== (lib.tags || []).join(',')) save(m, { tags: next });
+ }} />
+ </label>
+ </fieldset>
+ </details>
+ )}
+ </div>
</li>
);
})}
</ul>
)}
{!readOnly && (
- <div className="flex flex-wrap items-center gap-2 text-xs">
- <input aria-label="Mood board id" value={boardId} onChange={(e) => setBoardId(e.target.value)} placeholder="mood board id" className="bg-port-bg" />
- <input aria-label="Mood board item ids" value={itemIds} onChange={(e) => setItemIds(e.target.value)} placeholder="item ids (comma separated)" className="min-w-[12rem] flex-1 bg-port-bg" />
- <button type="button" onClick={importBoard}>Add from mood board</button>
- </div>
+ <details className="rounded border border-port-border p-3 text-xs">
+ <summary className="min-h-11 cursor-pointer content-center text-gray-400">Add from mood board</summary>
+ <div className="grid grid-cols-[repeat(auto-fit,minmax(min(100%,12rem),1fr))] items-end gap-2">
+ <label htmlFor={`${id}-board`} className="min-w-0 space-y-1"><span>Mood board id</span>
+ <input id={`${id}-board`} value={boardId} onChange={(e) => setBoardId(e.target.value)} className={fieldClass} />
+ </label>
+ <label htmlFor={`${id}-items`} className="min-w-0 space-y-1"><span>Mood board item ids</span>
+ <input id={`${id}-items`} value={itemIds} onChange={(e) => setItemIds(e.target.value)} placeholder="Comma separated" className={fieldClass} />
+ </label>
+ <button type="button" onClick={importBoard} className="min-h-11 rounded border border-port-border px-3 text-port-accent">Add from mood board</button>
+ </div>
+ </details>
)}
</section>
);
diff --git a/client/src/components/catalog/CatalogReferenceLibrary.test.jsx b/client/src/components/catalog/CatalogReferenceLibrary.test.jsx
index 70868e8c22..34c81856df 100644
--- a/client/src/components/catalog/CatalogReferenceLibrary.test.jsx
+++ b/client/src/components/catalog/CatalogReferenceLibrary.test.jsx
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
-import { render, screen, fireEvent, waitFor } from '@testing-library/react';
+import { render, screen, fireEvent, waitFor, within } from '@testing-library/react';
vi.mock('../../services/apiCatalog', () => ({
updateCatalogIngredientMediaLibrary: vi.fn(async () => ({})),
@@ -34,7 +34,7 @@ describe('CatalogReferenceLibrary', () => {
render(<CatalogReferenceLibrary ingredientId="cat-chr-1" media={media} onChanged={onChanged} />);
fireEvent.click(screen.getByRole('button', { name: /make guide/i }));
await waitFor(() => expect(onChanged).toHaveBeenCalled());
- expect(api.updateCatalogIngredientMediaLibrary).toHaveBeenCalledWith('cat-chr-1', { mediaKey: 'seventeen.png', kind: 'reference', guide: true });
+ expect(api.updateCatalogIngredientMediaLibrary).toHaveBeenCalledWith('cat-chr-1', { mediaKey: 'seventeen.png', kind: 'reference', guide: true }, { silent: true });
});
it('disables new guides at the cap of four', () => {
@@ -49,7 +49,7 @@ describe('CatalogReferenceLibrary', () => {
fireEvent.change(screen.getByLabelText('Mood board item ids'), { target: { value: 'a, b' } });
fireEvent.click(screen.getByRole('button', { name: /add from mood board/i }));
await waitFor(() => expect(api.attachCatalogIngredientMediaFromMoodBoard)
- .toHaveBeenCalledWith('cat-chr-1', { boardId: 'mb-1', itemIds: ['a', 'b'], inferAge: true }));
+ .toHaveBeenCalledWith('cat-chr-1', { boardId: 'mb-1', itemIds: ['a', 'b'], inferAge: true }, { silent: true }));
});
it('tags a reference with one of the saved ages/looks and filters by it', async () => {
@@ -63,7 +63,36 @@ describe('CatalogReferenceLibrary', () => {
expect(screen.getAllByTestId('library-row')).toHaveLength(1);
fireEvent.change(screen.getByLabelText('Age or look for now.png'), { target: { value: 'form-kid' } });
await waitFor(() => expect(api.updateCatalogIngredientMediaLibrary)
- .toHaveBeenCalledWith('cat-chr-1', { mediaKey: 'now.png', kind: 'reference', variant: { formId: 'form-kid' } }));
+ .toHaveBeenCalledWith('cat-chr-1', { mediaKey: 'now.png', kind: 'reference', variant: { formId: 'form-kid' } }, { silent: true }));
+ });
+
+ it('keeps each preview with its metadata and filters the visuals with the cards', () => {
+ render(<CatalogReferenceLibrary ingredientId="cat-chr-1" media={media} />);
+ const cards = screen.getAllByTestId('library-row');
+ expect(within(cards[0]).getByRole('img')).toHaveAttribute('src', '/data/image-thumbnails/seven.webp');
+ expect(within(cards[0]).getByText(/Age 7/)).toHaveTextContent('Canonical · Age 7 · child · vhs');
+ expect(cards[2].querySelector('video')).toHaveAttribute('src', '/data/videos/clip.mp4');
+ fireEvent.click(screen.getByLabelText('Guides only'));
+ expect(screen.getAllByTestId('library-row')).toHaveLength(1);
+ expect(screen.getByRole('img')).toHaveAttribute('src', '/data/image-thumbnails/seven.webp');
+ });
+
+ it('preserves per-attachment read-only provenance and counts guides outside this tab', () => {
+ render(<CatalogReferenceLibrary ingredientId="cat-chr-1"
+ media={[{ ...media[0], readOnly: true }, media[1]]}
+ guideMedia={[...media, ...[1, 2, 3].map((n) => ({ kind: 'reference', mediaKey: `sheet-${n}.png`, library: { guide: true } }))]} />);
+ expect(within(screen.getAllByTestId('library-row')[0]).queryByText('Edit reference details')).toBeNull();
+ expect(screen.getByRole('button', { name: /make guide/i })).toBeDisabled();
+ expect(screen.getByTestId('guide-count')).toHaveTextContent('4/4');
+ });
+
+ it('keeps an update failure visible beside the gallery', async () => {
+ api.updateCatalogIngredientMediaLibrary.mockRejectedValueOnce(new Error('Reference update failed'));
+ render(<CatalogReferenceLibrary ingredientId="cat-chr-1" media={media} />);
+ fireEvent.click(screen.getByRole('button', { name: /make guide/i }));
+ expect(await screen.findByRole('alert')).toHaveTextContent('Reference update failed');
+ expect(screen.getAllByTestId('library-row')).toHaveLength(3);
+ expect(screen.getByRole('button', { name: /make guide/i })).not.toBeDisabled();
});
it('hides editing controls when read-only', () => {
diff --git a/client/src/pages/CatalogIngredient.jsx b/client/src/pages/CatalogIngredient.jsx
index 3fce70f8fb..a45f66f373 100644
--- a/client/src/pages/CatalogIngredient.jsx
+++ b/client/src/pages/CatalogIngredient.jsx
@@ -883,13 +883,10 @@ function IngredientEditor() {
/>
)}
- {activeTab === 'references' && record.type === 'character' && (
- <CatalogReferenceLibrary ingredientId={record.id} media={media} forms={formsOf(record.payload)} readOnly={identityReadOnly} onChanged={refreshMedia} />
- )}
-
{(activeTab === 'profile' ? !tabs : activeTab === 'references' || activeTab === 'images') && (
<MediaPanel
readOnly={identityReadOnly}
+ referenceLibrary={record.type === 'character' ? { ingredientId: record.id, forms: formsOf(record.payload), guideMedia: media, onChanged: refreshMedia } : null}
media={(tabs ? media.filter(isReferenceTabRow) : media).map(protectMedia)}
canonImageRefs={[payload.primaryImageRef, ...(Array.isArray(payload.imageRefs) ? payload.imageRefs : [])].filter((ref) =>
!media.some((m) => (m.kind === 'portrait' || m.kind === 'reference') && m.mediaKey === ref))}
@@ -1484,7 +1481,7 @@ function GenerateImageControl({ ingredientId, name, description, universeId, onC
);
}
-function MediaPanel({ readOnly = false, media, canonImageRefs = [], primaryImageRef, missingMedia, onAttach, onSetPortrait, onDetach, onUploadFile, onRecordVoice, genIngredientId, genName, genDescription, genUniverseId, onGenerated }) {
+function MediaPanel({ readOnly = false, referenceLibrary = null, media, canonImageRefs = [], primaryImageRef, missingMedia, onAttach, onSetPortrait, onDetach, onUploadFile, onRecordVoice, genIngredientId, genName, genDescription, genUniverseId, onGenerated }) {
const [pickerOpen, setPickerOpen] = useState(false);
const [dragOver, setDragOver] = useState(false);
const [busy, setBusy] = useState(false); // upload or transcription in flight
@@ -1500,6 +1497,7 @@ function MediaPanel({ readOnly = false, media, canonImageRefs = [], primaryImage
seenImageKeys.add(m.mediaKey);
return true;
});
+ const tileMedia = referenceLibrary ? others.filter((m) => !['reference', 'video'].includes(m.kind)) : others;
const canonImages = [...new Set(canonImageRefs.filter((ref) => typeof ref === 'string' && ref.trim()))];
const doUpload = async (file) => {
@@ -1590,7 +1588,10 @@ function MediaPanel({ readOnly = false, media, canonImageRefs = [], primaryImage
: 'Drag a gallery image or a file here to attach it (image, audio, or video).'}
</div>}
- {portrait && (
+ {referenceLibrary && <CatalogReferenceLibrary {...referenceLibrary} media={list} readOnly={readOnly}
+ missingMedia={missingMedia} onSetPortrait={onSetPortrait} onDetach={onDetach} />}
+
+ {!referenceLibrary && portrait && (
<div className="mb-3">
<div className="text-[10px] uppercase tracking-wider text-gray-500 mb-1">Portrait</div>
<CatalogMediaTile m={portrait} missing={missingMedia.has(portrait.mediaKey)} isPortrait
@@ -1599,9 +1600,9 @@ function MediaPanel({ readOnly = false, media, canonImageRefs = [], primaryImage
</div>
)}
- {others.length > 0 && (
+ {tileMedia.length > 0 && (
<div className="grid grid-cols-2 sm:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 gap-3">
- {others.map((m) => (
+ {tileMedia.map((m) => (
<CatalogMediaTile key={`${m.mediaKey}:${m.kind}`} m={m} missing={missingMedia.has(m.mediaKey)}
onSetPortrait={onSetPortrait} onDetach={onDetach} armedDetach={armedDetach}
onArmDetach={setArmedDetach} />
@@ -1628,7 +1629,7 @@ function MediaPanel({ readOnly = false, media, canonImageRefs = [], primaryImage
</div>
)}
- {list.length === 0 && canonImages.length === 0 && (
+ {!referenceLibrary && list.length === 0 && canonImages.length === 0 && (
<p className="text-xs text-gray-500">No media yet. Attach a generated portrait, a mood/reference image, an uploaded file, or a recorded voice memo.</p>
)}
diff --git a/client/src/pages/CatalogIngredient.test.jsx b/client/src/pages/CatalogIngredient.test.jsx
index 295f708c83..a0ee4f06ac 100644
--- a/client/src/pages/CatalogIngredient.test.jsx
+++ b/client/src/pages/CatalogIngredient.test.jsx
@@ -1038,6 +1038,27 @@ describe('CatalogIngredient — tabbed library record pages', () => {
expect(screen.getAllByRole('img').filter((image) => image.getAttribute('src') === '/data/image-thumbnails/chosen.webp')).toHaveLength(1);
});
+ it('filters the unified character gallery without leaving a second unfiltered image list', async () => {
+ getCatalogIngredientDetails.mockResolvedValue({
+ ...detailsOf({ ...HERO, payload: {} }),
+ media: [
+ { kind: 'portrait', mediaKey: 'studio.png', caption: 'Studio portrait', library: { guide: true, variant: { age: 27 } } },
+ { kind: 'reference', mediaKey: 'winter.png', caption: 'Winter reference', library: { variant: { age: 7 } } },
+ { kind: 'reference', mediaKey: 'sheet.png', role: 'sheet:front', caption: 'Sheet in its own tab', library: { guide: true } },
+ ],
+ });
+ await renderPage('/casting/cat-chr-hero/references');
+ const library = screen.getByRole('region', { name: 'Reference library' });
+ expect(within(library).getAllByTestId('library-row')).toHaveLength(2);
+ expect(within(library).getByTestId('guide-count')).toHaveTextContent('2/4');
+ const winter = within(library).getByText('Winter reference').closest('li');
+ expect(within(winter).getByRole('img')).toHaveAttribute('src', '/data/image-thumbnails/winter.webp');
+ fireEvent.change(within(library).getByLabelText('Filter by age'), { target: { value: '27' } });
+ expect(screen.queryByAltText('Winter reference')).not.toBeInTheDocument();
+ expect(screen.getByAltText('Studio portrait')).toBeInTheDocument();
+ expect(screen.queryByAltText('Sheet in its own tab')).not.toBeInTheDocument();
+ });
+
it('keeps archive-only reference media visible on References without using it as a profile cover', async () => {
getCatalogIngredientDetails.mockResolvedValue({
...detailsOf({ ...HERO, payload: {}, thumbnailKey: null }),