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

Mood boards: pins first, board tools in one rail

Claudea7afd3ae61e0
diff --git a/client/src/components/moodBoard/MoodBoardCollagePanel.jsx b/client/src/components/moodBoard/MoodBoardCollagePanel.jsx
index bf2e5d2e1c..2b91f64fc6 100644
--- a/client/src/components/moodBoard/MoodBoardCollagePanel.jsx
+++ b/client/src/components/moodBoard/MoodBoardCollagePanel.jsx
@@ -17,7 +17,9 @@ export default function MoodBoardCollagePanel({ board, onBoardChange }) {
const [building, setBuilding] = useState(false);
const [result, setResult] = useState(null);
- if (!hasVisual) return null;
+ if (!hasVisual) {
+ return <p className="text-sm text-gray-400 bg-port-card border border-port-border rounded-md p-3">Pin an image or video to build a collage.</p>;
+ }
const shownSrc = result?.url || moodBoardCollageSrc(board);
const handleBuild = async () => {
diff --git a/client/src/components/moodBoard/MoodBoardGeneratePanel.jsx b/client/src/components/moodBoard/MoodBoardGeneratePanel.jsx
index bc2f26642a..06c8a5e7e8 100644
--- a/client/src/components/moodBoard/MoodBoardGeneratePanel.jsx
+++ b/client/src/components/moodBoard/MoodBoardGeneratePanel.jsx
@@ -19,9 +19,11 @@ const presets = RESOLUTIONS.filter((r) => !r.compatible);
const fieldClass = 'w-full min-w-0 bg-port-bg border border-port-border rounded px-2 py-2 text-sm text-white';
/** The parent keys this panel by board id, keeping pending requests scoped. */
-export default function MoodBoardGeneratePanel({ board, disabled = false }) {
+export default function MoodBoardGeneratePanel({ board, disabled = false, embedded = false }) {
const mounted = useMounted();
- const [open, setOpen] = useState(false);
+ const [expanded, setOpen] = useState(false);
+ // Embedded in the board tool rail, the tool tab already names it.
+ const open = embedded || expanded;
const [direction, setDirection] = useState('');
const [count, setCount] = useState(1);
const [size, setSize] = useState({ width: 1024, height: 576 });
@@ -108,13 +110,13 @@ export default function MoodBoardGeneratePanel({ board, disabled = false }) {
return (
<section className="min-w-0 bg-port-card border border-port-border rounded-md p-3 space-y-3">
- <button type="button" onClick={() => setOpen((v) => !v)} aria-expanded={open}
+ {!embedded && <button type="button" onClick={() => setOpen((v) => !v)} aria-expanded={open}
className="flex w-full min-h-[44px] items-center gap-2 text-left text-sm font-medium text-white">
<Sparkles className="w-4 h-4 shrink-0 text-port-accent" aria-hidden="true" />
Generate more
- </button>
+ </button>}
{open && <div className="min-w-0 space-y-3">
- <p className="text-xs text-gray-400">Create new images from this board’s saved analyses, prompts, captions and notes. The prompt writer receives text, not image pixels. Use Analyze board above for references that need visual descriptions. Existing references stay in place.</p>
+ <p className="text-xs text-gray-400">Create new images from this board’s saved analyses, prompts, captions and notes. The prompt writer receives text, not image pixels. Use Analyze in the Style tool for references that need visual descriptions. Existing references stay in place.</p>
<div>
<p className="text-xs text-gray-400 mb-1">Prompt-writing LLM</p>
<ProviderModelSelector providers={providers.providers}
diff --git a/client/src/components/moodBoard/MoodBoardStylePanel.jsx b/client/src/components/moodBoard/MoodBoardStylePanel.jsx
index e1c027987c..db5fe4da74 100644
--- a/client/src/components/moodBoard/MoodBoardStylePanel.jsx
+++ b/client/src/components/moodBoard/MoodBoardStylePanel.jsx
@@ -10,7 +10,7 @@
*/
import { useCallback, useEffect, useRef, useState } from 'react';
import socket from '../../services/socket';
-import { ScanEye, Sparkles, ImageIcon, ChevronDown, ChevronRight, X } from 'lucide-react';
+import { ScanEye, Sparkles, ImageIcon, ChevronDown, Cpu, X } from 'lucide-react';
import Modal from '../ui/Modal';
import ProviderModelSelector from '../ProviderModelSelector';
import MediaJobThumb from '../pipeline/MediaJobThumb';
@@ -51,8 +51,9 @@ export default function MoodBoardStylePanel({ board, onBoardChange }) {
setNegative(savedNegative);
}
- // Collapsed once a style exists so the pinned items sit above the fold.
- const [open, setOpen] = useState(!savedPrompt);
+ const [aiOpen, setAiOpen] = useState(false);
+ const [negativeOpen, setNegativeOpen] = useState(false);
+ const negativeShown = negativeOpen || Boolean(negative);
const [composing, setComposing] = useState(false);
const [job, setJob] = useState(null);
const jobRunning = job?.status === 'running';
@@ -258,160 +259,190 @@ export default function MoodBoardStylePanel({ board, onBoardChange }) {
const showAnalyze = plan.pending.length > 0;
const showCompose = plan.analyzed > 0;
+ const analyzable = plan.analyzed + plan.pending.length;
+ const progressPct = jobRunning && job.total > 0
+ ? Math.round((Math.min(job.done, job.total) / job.total) * 100)
+ : analyzable > 0 ? Math.round((plan.analyzed / analyzable) * 100) : 0;
+ const providerName = providers.find((p) => p.id === selectedProviderId)?.name || selectedProviderId;
+ const aiSummary = [providerName || 'Choose a provider', selectedModel, effort ? `${effort} effort` : null].filter(Boolean).join(' · ');
return (
- <section className="@container/board-style min-w-0 bg-port-card border border-port-border rounded-md p-3">
- <button
- type="button"
- onClick={() => setOpen((v) => !v)}
- aria-expanded={open}
- className={`flex w-full min-w-0 items-center gap-2 text-left ${open ? 'mb-2' : ''}`}
- >
- {open ? <ChevronDown className="w-4 h-4 text-gray-400 shrink-0" aria-hidden="true" /> : <ChevronRight className="w-4 h-4 text-gray-400 shrink-0" aria-hidden="true" />}
- <ScanEye className="w-4 h-4 text-port-accent shrink-0" aria-hidden="true" />
- <h2 className="text-sm font-medium text-white">Board style</h2>
- <span className="text-[11px] text-gray-500 truncate" title="Prompt from media for each gallery item, then one composite style from those prompts. The poster is this board’s canonical reference image.">
- Analyze pins → composite style → poster
- </span>
- </button>
- <div className={`flex-col @xl/board-style:flex-row gap-3 ${open ? 'flex' : 'hidden'}`}>
- <div className="w-full @xl/board-style:w-36 shrink-0">
- <div className="aspect-[3/2] w-full rounded-md overflow-hidden border border-port-border bg-port-bg">
- {jobId ? (
- <MediaJobThumb jobId={jobId} onFilename={handleComplete} size="fill" label="Board poster" />
- ) : posterSrc ? (
- <button
- type="button"
- onClick={() => setPreviewOpen(true)}
- aria-label="Preview board poster"
- className="block w-full h-full cursor-zoom-in"
- >
- <img src={posterSrc} alt="Board poster" className="w-full h-full object-cover" />
- </button>
- ) : (
- <div className="w-full h-full flex flex-col items-center justify-center text-gray-600 gap-1">
- <ImageIcon className="w-6 h-6" aria-hidden="true" />
- <span className="text-[11px]">No poster yet</span>
- </div>
- )}
+ <section aria-label="Board style" className="min-w-0 bg-port-card border border-port-border rounded-md p-3 space-y-3">
+ <div className="aspect-[3/2] w-full rounded-md overflow-hidden border border-port-border bg-port-bg">
+ {jobId ? (
+ <MediaJobThumb jobId={jobId} onFilename={handleComplete} size="fill" label="Board poster" />
+ ) : posterSrc ? (
+ <button
+ type="button"
+ onClick={() => setPreviewOpen(true)}
+ aria-label="Preview board poster"
+ className="block w-full h-full cursor-zoom-in"
+ >
+ <img src={posterSrc} alt="Board poster" className="w-full h-full object-cover" />
+ </button>
+ ) : (
+ <div className="w-full h-full flex flex-col items-center justify-center text-gray-600 gap-1">
+ <ImageIcon className="w-6 h-6" aria-hidden="true" />
+ <span className="text-[11px]">No poster yet</span>
</div>
- </div>
- <div className="flex-1 min-w-0 space-y-2">
- <ProviderModelSelector
- providers={providers}
- selectedProviderId={selectedProviderId}
- selectedModel={selectedModel}
- availableModels={availableModels}
- onProviderChange={setSelectedProviderId}
- onModelChange={setSelectedModel}
- effort={effort}
- onEffortChange={setEffort}
- disabled={busy || providersLoading}
- layout="row"
- />
- {providers.length === 0 && !providersLoading ? (
- <p className="text-xs text-port-warning">No vision-capable provider is enabled. Add one under Settings → Providers to analyze items. Composing from analyses you already have still works.</p>
- ) : null}
- <div className="flex flex-wrap items-center gap-2">
- {showAnalyze ? (
- <button
- type="button"
- onClick={analyzeBoard}
- disabled={busy || !selectedProviderId}
- className="inline-flex items-center gap-1.5 px-3 py-1.5 text-sm rounded bg-port-accent text-white hover:bg-port-accent/80 disabled:opacity-50 transition-colors"
- >
- <ScanEye className="w-4 h-4" aria-hidden="true" />
- {jobRunning ? jobProgress : 'Analyze board'}
- </button>
- ) : null}
- {showCompose ? (
- <button
- type="button"
- onClick={composeOnly}
- disabled={busy}
- className="inline-flex items-center gap-1.5 px-3 py-1.5 text-sm rounded bg-port-bg border border-port-border text-gray-200 hover:text-white disabled:opacity-50 transition-colors"
- >
- Compose board style
- </button>
- ) : null}
- {!showAnalyze && !showCompose ? (
- <p className="text-xs text-gray-500">Pin an image or video to analyze this board.</p>
- ) : null}
+ )}
+ </div>
+
+ {analyzable > 0 ? (
+ <div className="space-y-1.5">
+ <p className="text-xs text-gray-400">
+ {jobRunning ? jobProgress : `${formatCount(plan.analyzed)} of ${formatCount(analyzable)} pins analyzed`}
+ </p>
+ <div
+ role="progressbar"
+ aria-label="Pins analyzed"
+ aria-valuemin={0}
+ aria-valuemax={100}
+ aria-valuenow={progressPct}
+ className="h-1.5 rounded-full bg-port-bg overflow-hidden"
+ >
+ <div className="h-full bg-port-accent transition-[width]" style={{ width: `${progressPct}%` }} />
</div>
- {plan.skipped > 0 ? (
- <p className="text-[11px] text-gray-500">
- {formatCount(plan.skipped)} pin{plan.skipped === 1 ? '' : 's'} couldn’t be imported from {plan.skipped === 1 ? 'its' : 'their'} source URL and can’t be analyzed yet.
- </p>
- ) : null}
- <details className="group" open={!savedPrompt}>
- <summary className="cursor-pointer text-xs text-gray-400 hover:text-white select-none">
- Style prompt{savedPrompt ? `: ${savedPrompt.slice(0, 90)}${savedPrompt.length > 90 ? '…' : ''}` : ''}
- </summary>
- <div className="space-y-2 mt-2">
- <div>
- <label htmlFor="board-style-prompt" className="block text-xs text-gray-400 mb-1">Style prompt</label>
- <textarea
- id="board-style-prompt"
- value={prompt}
- rows={4}
- maxLength={8000}
- onChange={(e) => setPrompt(e.target.value)}
- placeholder="Compose a style from the item analyses, or write one."
- className="w-full bg-port-bg border border-port-border rounded px-2 py-1.5 text-white text-sm focus:border-port-accent outline-none resize-y"
- />
- </div>
- <div>
- <label htmlFor="board-style-negative" className="block text-xs text-gray-400 mb-1">Negative prompt</label>
- <textarea
- id="board-style-negative"
- value={negative}
- rows={2}
- maxLength={8000}
- onChange={(e) => setNegative(e.target.value)}
- className="w-full bg-port-bg border border-port-border rounded px-2 py-1.5 text-white text-sm focus:border-port-accent outline-none resize-y"
- />
- </div>
- </div>
- </details>
- {board?.style?.rationale ? (
- <p className="text-xs text-gray-400">{board.style.rationale}</p>
- ) : null}
- <div className="flex flex-wrap items-end gap-2">
- <div className="min-w-0">
- <label htmlFor="board-poster-renderer" className="block text-xs text-gray-400 mb-1">Image renderer</label>
- <select
- id="board-poster-renderer"
- value={resolvedMode}
- onChange={(e) => setRendererMode(e.target.value)}
- disabled={Boolean(jobId) || rendererOptions.length === 0}
- className="bg-port-bg border border-port-border rounded px-2 py-1.5 text-white text-sm focus:border-port-accent outline-none max-w-full"
- >
- {rendererOptions.length === 0 ? <option value="">Loading renderers…</option> : null}
- {rendererOptions.map((backend) => (
- <option key={backend.id} value={backend.id}>{backend.label}</option>
- ))}
- </select>
- </div>
- <button
- type="button"
- onClick={saveStyle}
- disabled={!styleDirty || savingStyle || busy}
- className="px-3 py-1.5 text-sm rounded bg-port-bg border border-port-border text-gray-200 hover:text-white disabled:opacity-50 transition-colors"
- >
- {savingStyle ? 'Saving…' : 'Save style'}
- </button>
- <button
- type="button"
- onClick={renderPoster}
- disabled={!canRender || Boolean(jobId)}
- title={styleDirty ? 'Save the board style first' : (savedPrompt.trim() ? 'Render the poster on the selected image service' : 'Compose a board style first')}
- className="inline-flex items-center gap-1.5 px-3 py-1.5 text-sm rounded bg-port-success text-white hover:bg-port-success/80 disabled:opacity-50 transition-colors"
- >
- <Sparkles className="w-4 h-4" aria-hidden="true" />
- {posterSrc ? 'Regenerate poster' : 'Generate poster'}
- </button>
+ </div>
+ ) : null}
+
+ <div className="flex flex-wrap items-center gap-2">
+ {showAnalyze ? (
+ <button
+ type="button"
+ onClick={analyzeBoard}
+ disabled={busy || !selectedProviderId}
+ className="min-h-[40px] inline-flex items-center gap-1.5 px-3 py-1.5 text-sm rounded bg-port-accent text-white hover:bg-port-accent/80 disabled:opacity-50 transition-colors"
+ >
+ <ScanEye className="w-4 h-4" aria-hidden="true" />
+ {jobRunning ? jobProgress : `Analyze ${formatCount(plan.pending.length)} new`}
+ </button>
+ ) : null}
+ {showCompose ? (
+ <button
+ type="button"
+ onClick={composeOnly}
+ disabled={busy}
+ className="min-h-[40px] inline-flex items-center gap-1.5 px-3 py-1.5 text-sm rounded bg-port-bg border border-port-border text-gray-200 hover:text-white disabled:opacity-50 transition-colors"
+ >
+ Compose board style
+ </button>
+ ) : null}
+ {!showAnalyze && !showCompose ? (
+ <p className="text-xs text-gray-500">Pin an image or video to analyze this board.</p>
+ ) : null}
+ </div>
+
+ {/* Provider, model and effort fold into one summary line until changed. */}
+ <div>
+ <button
+ type="button"
+ onClick={() => setAiOpen((v) => !v)}
+ aria-expanded={aiOpen}
+ aria-label={`Analysis AI: ${aiSummary}`}
+ className="flex w-full min-h-[40px] items-center gap-2 px-2.5 rounded border border-port-border bg-port-bg text-left text-xs text-gray-300 hover:text-white"
+ >
+ <Cpu className="w-3.5 h-3.5 shrink-0 text-gray-400" aria-hidden="true" />
+ <span className="flex-1 min-w-0 truncate">{aiSummary}</span>
+ <ChevronDown className={`w-3.5 h-3.5 shrink-0 transition-transform ${aiOpen ? 'rotate-180' : ''}`} aria-hidden="true" />
+ </button>
+ {aiOpen ? (
+ <div className="mt-2">
+ <ProviderModelSelector
+ providers={providers}
+ selectedProviderId={selectedProviderId}
+ selectedModel={selectedModel}
+ availableModels={availableModels}
+ onProviderChange={setSelectedProviderId}
+ onModelChange={setSelectedModel}
+ effort={effort}
+ onEffortChange={setEffort}
+ disabled={busy || providersLoading}
+ />
</div>
+ ) : null}
+ </div>
+ {providers.length === 0 && !providersLoading ? (
+ <p className="text-xs text-port-warning">No vision-capable provider is enabled. Add one under Settings → Providers to analyze items. Composing from analyses you already have still works.</p>
+ ) : null}
+ {plan.skipped > 0 ? (
+ <p className="text-[11px] text-gray-500">
+ {formatCount(plan.skipped)} pin{plan.skipped === 1 ? '' : 's'} couldn’t be imported from {plan.skipped === 1 ? 'its' : 'their'} source URL and can’t be analyzed yet.
+ </p>
+ ) : null}
+
+ <div>
+ <label htmlFor="board-style-prompt" className="block text-xs text-gray-400 mb-1">Style prompt</label>
+ <textarea
+ id="board-style-prompt"
+ value={prompt}
+ rows={5}
+ maxLength={8000}
+ onChange={(e) => setPrompt(e.target.value)}
+ placeholder="Compose a style from the item analyses, or write one."
+ className="w-full bg-port-bg border border-port-border rounded px-2 py-1.5 text-white text-sm focus:border-port-accent outline-none resize-y"
+ />
+ </div>
+ {negativeShown ? (
+ <div>
+ <label htmlFor="board-style-negative" className="block text-xs text-gray-400 mb-1">Negative prompt (optional)</label>
+ <textarea
+ id="board-style-negative"
+ value={negative}
+ rows={2}
+ maxLength={8000}
+ onChange={(e) => setNegative(e.target.value)}
+ className="w-full bg-port-bg border border-port-border rounded px-2 py-1.5 text-white text-sm focus:border-port-accent outline-none resize-y"
+ />
</div>
+ ) : (
+ <button
+ type="button"
+ onClick={() => setNegativeOpen(true)}
+ className="min-h-[36px] text-xs text-port-accent hover:underline"
+ >
+ + Negative prompt (optional)
+ </button>
+ )}
+ {board?.style?.rationale ? (
+ <p className="text-xs text-gray-400">{board.style.rationale}</p>
+ ) : null}
+ <div className="flex flex-wrap items-end gap-2">
+ {styleDirty ? (
+ <button
+ type="button"
+ onClick={saveStyle}
+ disabled={savingStyle || busy}
+ className="min-h-[40px] px-3 py-1.5 text-sm rounded bg-port-accent text-white hover:bg-port-accent/80 disabled:opacity-50 transition-colors"
+ >
+ {savingStyle ? 'Saving…' : 'Save style'}
+ </button>
+ ) : null}
+ <div className="min-w-0 flex-1">
+ <label htmlFor="board-poster-renderer" className="block text-xs text-gray-400 mb-1">Poster renderer</label>
+ <select
+ id="board-poster-renderer"
+ value={resolvedMode}
+ onChange={(e) => setRendererMode(e.target.value)}
+ disabled={Boolean(jobId) || rendererOptions.length === 0}
+ className="w-full min-h-[40px] bg-port-bg border border-port-border rounded px-2 py-1.5 text-white text-sm focus:border-port-accent outline-none"
+ >
+ {rendererOptions.length === 0 ? <option value="">Loading renderers…</option> : null}
+ {rendererOptions.map((backend) => (
+ <option key={backend.id} value={backend.id}>{backend.label}</option>
+ ))}
+ </select>
+ </div>
+ <button
+ type="button"
+ onClick={renderPoster}
+ disabled={!canRender || Boolean(jobId)}
+ title={styleDirty ? 'Save the board style first' : (savedPrompt.trim() ? 'Render the poster on the selected image service' : 'Compose a board style first')}
+ className="min-h-[40px] inline-flex items-center gap-1.5 px-3 py-1.5 text-sm rounded bg-port-success text-white hover:bg-port-success/80 disabled:opacity-50 transition-colors"
+ >
+ <Sparkles className="w-4 h-4" aria-hidden="true" />
+ {posterSrc ? 'Regenerate poster' : 'Generate poster'}
+ </button>
</div>
{posterSrc ? (
<Modal
diff --git a/client/src/components/moodBoard/MoodBoardStylePanel.test.jsx b/client/src/components/moodBoard/MoodBoardStylePanel.test.jsx
index 72b2a73d1c..e4d4e07f3e 100644
--- a/client/src/components/moodBoard/MoodBoardStylePanel.test.jsx
+++ b/client/src/components/moodBoard/MoodBoardStylePanel.test.jsx
@@ -97,7 +97,7 @@ describe('MoodBoardStylePanel', () => {
it('composes from saved analyses without running prompt-from-media again', async () => {
const onBoardChange = vi.fn();
render(<MoodBoardStylePanel board={analyzedBoard} onBoardChange={onBoardChange} />);
- expect(screen.queryByRole('button', { name: 'Analyze board' })).toBeNull();
+ expect(screen.queryByRole('button', { name: /^Analyze/ })).toBeNull();
await userEvent.click(screen.getByRole('button', { name: 'Compose board style' }));
await waitFor(() => expect(mockCompose).toHaveBeenCalledWith('mb-1', { providerId: 'vision-1', model: 'vlm' }, { silent: true }));
expect(mockStart).not.toHaveBeenCalled();
@@ -110,7 +110,7 @@ describe('MoodBoardStylePanel', () => {
const board = { id: 'mb-1', items: [{ id: 'b', type: 'image', mediaKey: 'image:b.png' }] };
render(<MoodBoardStylePanel board={board} onBoardChange={vi.fn()} />);
expect(screen.queryByRole('button', { name: 'Compose board style' })).toBeNull();
- await userEvent.click(screen.getByRole('button', { name: 'Analyze board' }));
+ await userEvent.click(screen.getByRole('button', { name: 'Analyze 1 new' }));
expect(mockStart).toHaveBeenCalledWith('mb-1', { providerId: 'vision-1', model: 'vlm' }, { silent: true });
await act(async () => {
socketHandlers.get('mood-board:analyze')({ boardId: 'mb-1', status: 'running', phase: 'analyzing', total: 4, done: 1 });
diff --git a/client/src/pages/MoodBoardDetail.jsx b/client/src/pages/MoodBoardDetail.jsx
index b4d7003f18..2196fb1289 100644
--- a/client/src/pages/MoodBoardDetail.jsx
+++ b/client/src/pages/MoodBoardDetail.jsx
@@ -11,7 +11,7 @@
import { useEffect, useState, useCallback, useMemo, useRef } from 'react';
import { useParams, useNavigate, useSearchParams, Link } from 'react-router';
-import { ArrowLeft, ChevronDown, ImageIcon, FileText, Trash2, Plus, Save, Link2, Unlink, RefreshCw, Images, Film, Play, ScanEye, Copy, AtSign, Download, Sparkles, Clapperboard, Paintbrush, Wand2, GalleryHorizontal } from 'lucide-react';
+import { ArrowLeft, ImageIcon, FileText, Trash2, Plus, Save, Link2, Unlink, RefreshCw, Images, Film, Play, ScanEye, Copy, AtSign, Download, Sparkles, Clapperboard, Paintbrush, Wand2, GalleryHorizontal, Palette, LayoutGrid, X } from 'lucide-react';
import PageSkeleton from '../components/ui/PageSkeleton';
import toast from '../components/ui/Toast';
import TabPills from '../components/ui/TabPills';
@@ -25,6 +25,11 @@ import MoodBoardStylePanel from '../components/moodBoard/MoodBoardStylePanel';
import MoodBoardCollagePanel from '../components/moodBoard/MoodBoardCollagePanel';
import VideoFramePicker from '../components/moodBoard/VideoFramePicker';
import usePreviewRoute from '../hooks/usePreviewRoute';
+import useContainerWidth from '../hooks/useContainerWidth';
+import useFocusTrap from '../hooks/useFocusTrap.js';
+import { useScrollLock } from '../hooks/useScrollLock';
+import { useEscLayer } from '../components/ui/Modal';
+import { safeReadStorage, safeWriteStorage } from '../lib/safeStorage';
import { copyToClipboard } from '../lib/clipboard';
import {
getMoodBoard,
@@ -43,7 +48,7 @@ import {
renderMoodBoardItem,
} from '../services/api';
import socket from '../services/socket';
-import { moodBoardItemSrc, moodBoardItemVideoSrc, moodBoardItemAnalysisSource } from '../lib/moodBoardItemSrc';
+import { moodBoardItemSrc, moodBoardItemVideoSrc, moodBoardItemAnalysisSource, moodBoardPosterSrc } from '../lib/moodBoardItemSrc';
import {
moodBoardAnalysisFromResult,
moodBoardItemPrompt,
@@ -51,9 +56,23 @@ import {
moodBoardItemHasPrompt,
moodBoardItemSendLinks,
} from '../lib/moodBoardAnalysis';
-import { timeAgo } from '../utils/formatters';
+import { formatCount, timeAgo } from '../utils/formatters';
import useMounted from '../hooks/useMounted';
+// Board tools share one panel: a side rail on wide boards, a sheet on phones.
+// The open tool is `?tool=` so it is linkable; the last one used is remembered.
+const BOARD_TOOLS = [
+ { id: 'add', label: 'Add', icon: Plus },
+ { id: 'import', label: 'Import', icon: Download },
+ { id: 'style', label: 'Style', icon: Palette },
+ { id: 'generate', label: 'Generate', icon: Sparkles },
+ { id: 'collage', label: 'Collage', icon: LayoutGrid },
+];
+const BOARD_TOOL_IDS = BOARD_TOOLS.map((t) => t.id);
+const BOARD_TOOL_STORAGE_KEY = 'portos.moodBoard.tool';
+// Matches `@4xl/board` (56rem), where the rail column appears.
+const WIDE_BOARD_PX = 896;
+
export default function MoodBoardDetail() {
const { id } = useParams();
// Route changes replace the editor so every draft, modal and pending-action
@@ -116,9 +135,38 @@ function MoodBoardEditor({ id }) {
// X.com (Twitter) post import — one-shot, no persisted link.
const [xPostUrl, setXPostUrl] = useState('');
const [importingXPost, setImportingXPost] = useState(false);
- // Closed on the stacked layout so Pinterest + X cost one row until asked for.
- // Wide boards force the panels open with `@4xl/board:block` and hide this toggle.
- const [importsOpen, setImportsOpen] = useState(false);
+
+ // Before the first measurement, guess from the viewport so a phone never
+ // flashes the rail.
+ const [rootRef, rootWidth] = useContainerWidth();
+ const wide = rootWidth ? rootWidth >= WIDE_BOARD_PX : (typeof window === 'undefined' || window.innerWidth >= 1024);
+ const toolParam = searchParams.get('tool');
+ const urlTool = BOARD_TOOL_IDS.includes(toolParam) ? toolParam : null;
+ const [lastTool, setLastTool] = useState(() => {
+ const saved = safeReadStorage(BOARD_TOOL_STORAGE_KEY);
+ return BOARD_TOOL_IDS.includes(saved) ? saved : 'add';
+ });
+ const activeTool = urlTool || lastTool;
+ const sheetOpen = !wide && Boolean(urlTool);
+ const selectTool = useCallback((tool) => {
+ setLastTool(tool);
+ safeWriteStorage(BOARD_TOOL_STORAGE_KEY, tool);
+ // Opening the phone sheet pushes history so Back closes it.
+ setSearchParams((prev) => {
+ const next = new URLSearchParams(prev);
+ next.set('tool', tool);
+ return next;
+ }, { replace: wide || Boolean(urlTool) });
+ }, [setSearchParams, wide, urlTool]);
+ const closeSheet = useCallback(() => setSearchParams((prev) => {
+ const next = new URLSearchParams(prev);
+ next.delete('tool');
+ return next;
+ }, { replace: true }), [setSearchParams]);
+ const toolsRef = useRef(null);
+ useScrollLock(sheetOpen);
+ useFocusTrap(sheetOpen, toolsRef);
+ useEscLayer(sheetOpen, closeSheet);
// The keyed editor isolates board state. Also guard async continuations and
// delayed child callbacks so the old editor cannot toast or start a mutation
@@ -538,301 +586,312 @@ function MoodBoardEditor({ id }) {
</div>
);
- return (
- <div className="@container/board min-w-0 max-w-7xl mx-auto space-y-4">
- <button
- type="button"
- onClick={() => navigate('/mood-boards')}
- className="flex items-center gap-1 text-sm text-gray-400 hover:text-white transition-colors"
- >
- <ArrowLeft className="w-4 h-4" aria-hidden="true" /> Boards
- </button>
+ const analyzedCount = items.filter(isMoodBoardItemAnalyzed).length;
+ const posterSrc = moodBoardPosterSrc(board);
- {/* Board metadata — one compact row on desktop */}
- <div className="bg-port-card border border-port-border rounded-md p-3">
- <div className="flex flex-wrap items-end gap-3">
- <div className="min-w-0 flex-[1_1_16rem]">
- <label htmlFor="board-name" className="block text-xs text-gray-400 mb-1">Name</label>
+ const addPanel = (
+ <div className="@container/add-form bg-port-card border border-port-border rounded-md p-4">
+ <div className="flex items-center gap-2 mb-3">
+ <Plus className="w-4 h-4 text-port-accent" aria-hidden="true" />
+ <h2 className="text-sm font-medium text-white">Add item</h2>
+ </div>
+ <div className="flex flex-wrap items-center gap-2 mb-3">
+ {/* The shared TabPills owns the roving tabindex + arrow-key
+ contract — never roll a tab bar (client/src/AGENTS.md). */}
+ <TabPills
+ variant="pills"
+ size="sm"
+ tabs={[
+ { id: 'image', label: 'Image', icon: ImageIcon },
+ { id: 'text', label: 'Note', icon: FileText },
+ ]}
+ activeTab={itemType}
+ onChange={setItemType}
+ ariaLabel="Item type"
+ />
+ {/* Gallery pins (#4188) — pick or upload, added to the board immediately. */}
+ <div className="flex min-w-0 flex-wrap items-center gap-2">
+ <button
+ type="button"
+ onClick={() => setImagePickerOpen(true)}
+ className="flex items-center gap-1.5 px-3 py-1.5 text-sm rounded bg-port-bg text-gray-400 hover:text-white transition-colors"
+ >
+ <Images className="w-4 h-4" aria-hidden="true" /> Pick from gallery
+ </button>
+ <button
+ type="button"
+ onClick={() => setVideoPickerOpen(true)}
+ className="flex items-center gap-1.5 px-3 py-1.5 text-sm rounded bg-port-bg text-gray-400 hover:text-white transition-colors"
+ >
+ <Film className="w-4 h-4" aria-hidden="true" /> Pick video
+ </button>
+ </div>
+ </div>
+
+ <div className="space-y-3">
+ {itemType === 'image' ? (
+ <div>
+ <label htmlFor="item-image-url" className="block text-xs text-gray-400 mb-1">Image URL</label>
<input
- id="board-name"
+ id="item-image-url"
type="text"
- value={name}
- maxLength={200}
- onChange={(e) => setName(e.target.value)}
- className="block w-full bg-port-bg border border-port-border rounded px-2 py-1.5 text-white text-sm focus:border-port-accent outline-none"
+ value={imageUrl}
+ maxLength={2048}
+ placeholder="https://… or /data/images/…"
+ onChange={(e) => setImageUrl(e.target.value)}
+ className="w-full bg-port-bg border border-port-border rounded px-2 py-1.5 text-white text-sm focus:border-port-accent outline-none"
/>
</div>
- <div className="min-w-0 flex-[2_1_20rem]">
- <label htmlFor="board-description" className="block text-xs text-gray-400 mb-1">Description</label>
+ ) : (
+ <div>
+ <label htmlFor="item-text" className="block text-xs text-gray-400 mb-1">Note</label>
<textarea
- id="board-description"
- value={description}
- maxLength={5000}
- rows={1}
- onChange={(e) => setDescription(e.target.value)}
- className="block w-full h-[34px] min-h-[34px] bg-port-bg border border-port-border rounded px-2 py-1.5 text-white text-sm focus:border-port-accent outline-none resize-y"
+ id="item-text"
+ value={text}
+ maxLength={10000}
+ rows={2}
+ onChange={(e) => setText(e.target.value)}
+ className="w-full bg-port-bg border border-port-border rounded px-2 py-1.5 text-white text-sm focus:border-port-accent outline-none resize-y"
+ />
+ </div>
+ )}
+ <div className="grid grid-cols-1 @sm/add-form:grid-cols-2 gap-3">
+ <div>
+ <label htmlFor="item-caption" className="block text-xs text-gray-400 mb-1">Caption (optional)</label>
+ <input
+ id="item-caption"
+ type="text"
+ value={caption}
+ maxLength={2000}
+ onChange={(e) => setCaption(e.target.value)}
+ className="w-full bg-port-bg border border-port-border rounded px-2 py-1.5 text-white text-sm focus:border-port-accent outline-none"
/>
</div>
+ <div>
+ <label htmlFor="item-source" className="block text-xs text-gray-400 mb-1">Source (optional)</label>
+ <input
+ id="item-source"
+ type="text"
+ value={source}
+ maxLength={2048}
+ placeholder="where it came from"
+ onChange={(e) => setSource(e.target.value)}
+ className="w-full bg-port-bg border border-port-border rounded px-2 py-1.5 text-white text-sm focus:border-port-accent outline-none"
+ />
+ </div>
+ </div>
+ <div className="flex justify-end">
<button
type="button"
- onClick={handleSaveMeta}
- disabled={!metaDirty || savingMeta}
- className="flex items-center justify-center gap-1.5 px-3 py-1.5 text-sm rounded bg-port-accent text-white hover:bg-port-accent/80 disabled:opacity-50 transition-colors"
+ onClick={handleAddItem}
+ disabled={adding}
+ className="flex items-center gap-1.5 px-3 py-1.5 text-sm rounded bg-port-success text-white hover:bg-port-success/80 disabled:opacity-50 transition-colors"
>
- <Save className="w-4 h-4" aria-hidden="true" /> Save
+ <Plus className="w-4 h-4" aria-hidden="true" /> Pin to board
</button>
</div>
</div>
+ </div>
+ );
- {/* Style + collage share a row on wide boards so pinned items stay above the fold */}
- <div className="grid grid-cols-1 @4xl/board:grid-cols-[minmax(0,2fr)_minmax(0,1fr)] gap-4 items-start">
- <MoodBoardStylePanel board={board} onBoardChange={setBoard} />
- <MoodBoardGeneratePanel key={id} board={board} disabled={Boolean(metaDirty || savingMeta)} />
- <MoodBoardCollagePanel board={board} onBoardChange={setBoard} />
- </div>
-
- {/* Use board width, including space lost to the app sidebar.
- Source order is the stacked order (add, then items) so a phone
- keyboard reaches Add item before the pin list. `@4xl/board:order-last`
- paints the aside in the right column, and `reading-flow: grid-order`
- makes tab order follow that visual order where the browser supports it. */}
- <div className="grid grid-cols-1 @4xl/board:grid-cols-[minmax(0,1fr)_22rem] @4xl/board:[reading-flow:grid-order] gap-6 items-start">
- {/* Right column on wide boards; first on a stacked board. */}
- <aside aria-label="Add to mood board" className="@4xl/board:order-last @container/add-form min-w-0 w-full space-y-6">
- {/* Add item */}
- <div className="bg-port-card border border-port-border rounded-md p-4">
- <div className="flex items-center gap-2 mb-3">
- <Plus className="w-4 h-4 text-port-accent" aria-hidden="true" />
- <h2 className="text-sm font-medium text-white">Add item</h2>
+ const importPanel = (
+ <div className="space-y-4">
+ {/* Pinterest link + sync */}
+ <div className="bg-port-card border border-port-border rounded-md p-4">
+ <div className="flex items-center gap-2 mb-3">
+ <Link2 className="w-4 h-4 text-port-accent" aria-hidden="true" />
+ <h2 className="text-sm font-medium text-white">Pinterest board</h2>
+ </div>
+ {linkedFeedUrl ? (
+ <div className="space-y-3">
+ <div className="flex flex-wrap items-center gap-x-3 gap-y-1 text-xs">
+ <a
+ href={linkedBoardUrl}
+ target="_blank"
+ rel="noopener noreferrer"
+ className="text-port-accent hover:underline truncate max-w-full"
+ >
+ {linkedBoardUrl}
+ </a>
+ <span className="text-gray-500">
+ {lastSyncedAt ? `Last synced ${timeAgo(lastSyncedAt)}` : 'Not synced yet'}
+ </span>
</div>
- <div className="flex flex-wrap items-center gap-2 mb-3">
- {/* The shared TabPills owns the roving tabindex + arrow-key
- contract — never roll a tab bar (client/src/AGENTS.md). */}
- <TabPills
- variant="pills"
- size="sm"
- tabs={[
- { id: 'image', label: 'Image', icon: ImageIcon },
- { id: 'text', label: 'Note', icon: FileText },
- ]}
- activeTab={itemType}
- onChange={setItemType}
- ariaLabel="Item type"
- />
- {/* Gallery pins (#4188) — pick or upload, added to the board immediately. */}
- <div className="flex min-w-0 flex-wrap items-center gap-2">
- <button
- type="button"
- onClick={() => setImagePickerOpen(true)}
- className="flex items-center gap-1.5 px-3 py-1.5 text-sm rounded bg-port-bg text-gray-400 hover:text-white transition-colors"
- >
- <Images className="w-4 h-4" aria-hidden="true" /> Pick from gallery
- </button>
+ <p className="text-[11px] text-gray-500">
+ Pinterest’s feed exposes only the most-recent ~25 pins, so a sync pulls those — not the entire board.
+ </p>
+ <p className="text-[11px] text-gray-500">
+ Use “Import pins” below to read the full board from your signed-in PortOS browser.
+ </p>
+ <div className="flex flex-wrap items-center gap-2">
+ <button
+ type="button"
+ onClick={handleSyncPinterest}
+ disabled={syncing || linking || importingPinterest || pinDirty}
+ title={pinDirty ? 'Link the new URL before syncing' : undefined}
+ className="flex items-center gap-1.5 px-3 py-1.5 text-sm rounded bg-port-accent text-white hover:bg-port-accent/80 disabled:opacity-50 transition-colors"
+ >
+ <RefreshCw className={`w-4 h-4 ${syncing ? 'animate-spin' : ''}`} aria-hidden="true" />
+ {syncing ? 'Syncing…' : 'Sync now'}
+ </button>
+ {confirmingUnlink ? (
+ <InlineConfirmRow
+ question="Unlink this board?"
+ confirmText="Unlink"
+ onConfirm={handleUnlinkPinterest}
+ onCancel={() => setConfirmingUnlink(false)}
+ />
+ ) : (
<button
type="button"
- onClick={() => setVideoPickerOpen(true)}
+ onClick={() => setConfirmingUnlink(true)}
className="flex items-center gap-1.5 px-3 py-1.5 text-sm rounded bg-port-bg text-gray-400 hover:text-white transition-colors"
>
- <Film className="w-4 h-4" aria-hidden="true" /> Pick video
+ <Unlink className="w-4 h-4" aria-hidden="true" /> Unlink
</button>
- </div>
- </div>
-
- <div className="space-y-3">
- {itemType === 'image' ? (
- <div>
- <label htmlFor="item-image-url" className="block text-xs text-gray-400 mb-1">Image URL</label>
- <input
- id="item-image-url"
- type="text"
- value={imageUrl}
- maxLength={2048}
- placeholder="https://… or /data/images/…"
- onChange={(e) => setImageUrl(e.target.value)}
- className="w-full bg-port-bg border border-port-border rounded px-2 py-1.5 text-white text-sm focus:border-port-accent outline-none"
- />
- </div>
- ) : (
- <div>
- <label htmlFor="item-text" className="block text-xs text-gray-400 mb-1">Note</label>
- <textarea
- id="item-text"
- value={text}
- maxLength={10000}
- rows={2}
- onChange={(e) => setText(e.target.value)}
- className="w-full bg-port-bg border border-port-border rounded px-2 py-1.5 text-white text-sm focus:border-port-accent outline-none resize-y"
- />
- </div>
)}
- <div className="grid grid-cols-1 @sm/add-form:grid-cols-2 gap-3">
- <div>
- <label htmlFor="item-caption" className="block text-xs text-gray-400 mb-1">Caption (optional)</label>
- <input
- id="item-caption"
- type="text"
- value={caption}
- maxLength={2000}
- onChange={(e) => setCaption(e.target.value)}
- className="w-full bg-port-bg border border-port-border rounded px-2 py-1.5 text-white text-sm focus:border-port-accent outline-none"
- />
- </div>
- <div>
- <label htmlFor="item-source" className="block text-xs text-gray-400 mb-1">Source (optional)</label>
- <input
- id="item-source"
- type="text"
- value={source}
- maxLength={2048}
- placeholder="where it came from"
- onChange={(e) => setSource(e.target.value)}
- className="w-full bg-port-bg border border-port-border rounded px-2 py-1.5 text-white text-sm focus:border-port-accent outline-none"
- />
- </div>
- </div>
- <div className="flex justify-end">
- <button
- type="button"
- onClick={handleAddItem}
- disabled={adding}
- className="flex items-center gap-1.5 px-3 py-1.5 text-sm rounded bg-port-success text-white hover:bg-port-success/80 disabled:opacity-50 transition-colors"
- >
- <Plus className="w-4 h-4" aria-hidden="true" /> Pin to board
- </button>
- </div>
</div>
+ {renderPinUrlForm('Change board URL', 'Update')}
</div>
+ ) : (
+ <div>
+ {renderPinUrlForm('Board URL', 'Link')}
+ <p className="text-[11px] text-gray-500 mt-2">
+ Link a public board to sync its newest ~25 pins. “Import pins” reads the full board from your signed-in PortOS browser and saves the images here.
+ </p>
+ </div>
+ )}
+ </div>
- {/* Stacked boards hide Pinterest and X behind one tap. The wide
- column always shows both cards; `hidden` loses to `@4xl/board:block`. */}
+ {/* X.com (Twitter) post import */}
+ <div className="bg-port-card border border-port-border rounded-md p-4">
+ <div className="flex items-center gap-2 mb-3">
+ <AtSign className="w-4 h-4 text-port-accent" aria-hidden="true" />
+ <h2 className="text-sm font-medium text-white">Import from an X post</h2>
+ </div>
+ <div>
+ <label htmlFor="x-post-url" className="block text-xs text-gray-400 mb-1">Post URL</label>
+ <div className="flex flex-wrap gap-2">
+ <input
+ id="x-post-url"
+ type="text"
+ value={xPostUrl}
+ maxLength={2048}
+ placeholder="https://x.com/user/status/1234567890"
+ onChange={(e) => setXPostUrl(e.target.value)}
+ className="flex-[1_1_12rem] min-w-0 bg-port-bg border border-port-border rounded px-2 py-1.5 text-white text-sm focus:border-port-accent outline-none"
+ />
+ <button
+ type="button"
+ onClick={handleImportXPost}
+ disabled={importingXPost || !xPostUrl.trim()}
+ className="px-3 py-1.5 text-sm rounded bg-port-success text-white hover:bg-port-success/80 disabled:opacity-50 transition-colors"
+ >
+ {importingXPost ? 'Importing…' : 'Import'}
+ </button>
+ </div>
+ </div>
+ <p className="text-[11px] text-gray-500 mt-2">
+ Paste a public x.com/twitter.com post URL. Pulls every attached photo (or its video) into this board.
+ </p>
+ </div>
+ </div>
+ );
+
+ const toolPanels = {
+ add: addPanel,
+ import: importPanel,
+ style: <MoodBoardStylePanel board={board} onBoardChange={setBoard} />,
+ generate: <MoodBoardGeneratePanel key={id} board={board} disabled={Boolean(metaDirty || savingMeta)} embedded />,
+ collage: <MoodBoardCollagePanel board={board} onBoardChange={setBoard} />,
+ };
+
+ return (
+ <div ref={rootRef} className="@container/board min-w-0 max-w-7xl mx-auto space-y-4">
+ {/* One compact header: the pins start right below it. */}
+ <header className="flex flex-wrap items-center gap-x-3 gap-y-2">
+ <button
+ type="button"
+ onClick={() => navigate('/mood-boards')}
+ aria-label="Back to boards"
+ className="min-h-[44px] min-w-[44px] -ml-2 flex items-center justify-center rounded text-gray-400 hover:text-white transition-colors"
+ >
+ <ArrowLeft className="w-5 h-5" aria-hidden="true" />
+ </button>
+ <button
+ type="button"
+ onClick={() => selectTool('style')}
+ aria-label="Board style and poster"
+ className="w-11 h-11 shrink-0 rounded overflow-hidden border border-port-border bg-port-bg flex items-center justify-center text-gray-600"
+ >
+ {posterSrc
+ ? <img src={posterSrc} alt="" className="w-full h-full object-cover" />
+ : <ImageIcon className="w-5 h-5" aria-hidden="true" />}
+ </button>
+ <div className="min-w-0 flex-[1_1_14rem]">
+ <label htmlFor="board-name" className="sr-only">Name</label>
+ <input
+ id="board-name"
+ type="text"
+ value={name}
+ maxLength={200}
+ onChange={(e) => setName(e.target.value)}
+ className="block w-full bg-transparent border border-transparent hover:border-port-border focus:border-port-accent rounded px-1.5 py-0.5 -ml-1.5 text-lg font-semibold text-white outline-none"
+ />
+ <p className="text-xs text-gray-400">
+ {formatCount(items.length)} item{items.length === 1 ? '' : 's'} · {formatCount(analyzedCount)} analyzed
+ </p>
+ </div>
+ <div className="min-w-0 flex-[2_1_20rem]">
+ <label htmlFor="board-description" className="sr-only">Description</label>
+ <textarea
+ id="board-description"
+ value={description}
+ maxLength={5000}
+ rows={1}
+ placeholder="Add a description…"
+ onChange={(e) => setDescription(e.target.value)}
+ className="block w-full h-[34px] focus:h-28 bg-transparent border border-transparent hover:border-port-border focus:border-port-accent focus:bg-port-bg rounded px-2 py-1.5 text-sm text-gray-300 outline-none resize-none transition-[height]"
+ />
+ </div>
+ {metaDirty || savingMeta ? (
<button
type="button"
- aria-expanded={importsOpen}
- aria-controls="mood-board-import-panels"
- onClick={() => setImportsOpen((open) => !open)}
- className="@4xl/board:hidden flex w-full items-center gap-2 bg-port-card border border-port-border rounded-md p-4 text-left text-sm font-medium text-white"
+ onClick={handleSaveMeta}
+ disabled={savingMeta}
+ className="min-h-[40px] flex items-center justify-center gap-1.5 px-3 py-1.5 text-sm rounded bg-port-accent text-white hover:bg-port-accent/80 disabled:opacity-50 transition-colors"
>
- <ChevronDown className={`w-4 h-4 text-port-accent shrink-0 transition-transform ${importsOpen ? 'rotate-180' : ''}`} aria-hidden="true" />
- Import from Pinterest or X
+ <Save className="w-4 h-4" aria-hidden="true" /> Save
</button>
- <div
- id="mood-board-import-panels"
- className={importsOpen ? 'space-y-6' : 'hidden space-y-6 @4xl/board:block'}
- >
- {/* Pinterest link + sync */}
- <div className="bg-port-card border border-port-border rounded-md p-4">
- <div className="flex items-center gap-2 mb-3">
- <Link2 className="w-4 h-4 text-port-accent" aria-hidden="true" />
- <h2 className="text-sm font-medium text-white">Pinterest board</h2>
- </div>
- {linkedFeedUrl ? (
- <div className="space-y-3">
- <div className="flex flex-wrap items-center gap-x-3 gap-y-1 text-xs">
- <a
- href={linkedBoardUrl}
- target="_blank"
- rel="noopener noreferrer"
- className="text-port-accent hover:underline truncate max-w-full"
- >
- {linkedBoardUrl}
- </a>
- <span className="text-gray-500">
- {lastSyncedAt ? `Last synced ${timeAgo(lastSyncedAt)}` : 'Not synced yet'}
- </span>
- </div>
- <p className="text-[11px] text-gray-500">
- Pinterest’s feed exposes only the most-recent ~25 pins, so a sync pulls those — not the entire board.
- </p>
- <p className="text-[11px] text-gray-500">
- Use “Import pins” below to read the full board from your signed-in PortOS browser.
- </p>
- <div className="flex flex-wrap items-center gap-2">
- <button
- type="button"
- onClick={handleSyncPinterest}
- disabled={syncing || linking || importingPinterest || pinDirty}
- title={pinDirty ? 'Link the new URL before syncing' : undefined}
- className="flex items-center gap-1.5 px-3 py-1.5 text-sm rounded bg-port-accent text-white hover:bg-port-accent/80 disabled:opacity-50 transition-colors"
- >
- <RefreshCw className={`w-4 h-4 ${syncing ? 'animate-spin' : ''}`} aria-hidden="true" />
- {syncing ? 'Syncing…' : 'Sync now'}
- </button>
- {confirmingUnlink ? (
- <InlineConfirmRow
- question="Unlink this board?"
- confirmText="Unlink"
- onConfirm={handleUnlinkPinterest}
- onCancel={() => setConfirmingUnlink(false)}
- />
- ) : (
- <button
- type="button"
- onClick={() => setConfirmingUnlink(true)}
- className="flex items-center gap-1.5 px-3 py-1.5 text-sm rounded bg-port-bg text-gray-400 hover:text-white transition-colors"
- >
- <Unlink className="w-4 h-4" aria-hidden="true" /> Unlink
- </button>
- )}
- </div>
- {renderPinUrlForm('Change board URL', 'Update')}
- </div>
- ) : (
- <div>
- {renderPinUrlForm('Board URL', 'Link')}
- <p className="text-[11px] text-gray-500 mt-2">
- Link a public board to sync its newest ~25 pins. “Import pins” reads the full board from your signed-in PortOS browser and saves the images here.
- </p>
- </div>
- )}
- </div>
+ ) : null}
+ </header>
- {/* X.com (Twitter) post import */}
- <div className="bg-port-card border border-port-border rounded-md p-4">
- <div className="flex items-center gap-2 mb-3">
- <AtSign className="w-4 h-4 text-port-accent" aria-hidden="true" />
- <h2 className="text-sm font-medium text-white">Import from an X post</h2>
- </div>
- <div>
- <label htmlFor="x-post-url" className="block text-xs text-gray-400 mb-1">Post URL</label>
- <div className="flex flex-wrap gap-2">
- <input
- id="x-post-url"
- type="text"
- value={xPostUrl}
- maxLength={2048}
- placeholder="https://x.com/user/status/1234567890"
- onChange={(e) => setXPostUrl(e.target.value)}
- className="flex-[1_1_12rem] min-w-0 bg-port-bg border border-port-border rounded px-2 py-1.5 text-white text-sm focus:border-port-accent outline-none"
- />
- <button
- type="button"
- onClick={handleImportXPost}
- disabled={importingXPost || !xPostUrl.trim()}
- className="px-3 py-1.5 text-sm rounded bg-port-success text-white hover:bg-port-success/80 disabled:opacity-50 transition-colors"
- >
- {importingXPost ? 'Importing…' : 'Import'}
- </button>
- </div>
- </div>
- <p className="text-[11px] text-gray-500 mt-2">
- Paste a public x.com/twitter.com post URL. Pulls every attached photo (or its video) into this board.
- </p>
- </div>
- </div>
- </aside>
+ {!wide ? (
+ // Phones reach every tool from one row that stays put while pins scroll.
+ <nav aria-label="Board tools" className="sticky top-0 z-20 -mx-1 flex bg-port-bg/95 border-b border-port-border">
+ {BOARD_TOOLS.map(({ id: toolId, label, icon: Icon }) => (
+ <button
+ key={toolId}
+ type="button"
+ onClick={() => selectTool(toolId)}
+ className="flex-1 min-h-[52px] flex flex-col items-center justify-center gap-0.5 text-[11px] text-gray-400 hover:text-white"
+ >
+ <Icon className="w-5 h-5" aria-hidden="true" />
+ {label}
+ </button>
+ ))}
+ </nav>
+ ) : null}
- {/* Left column: Mood board items */}
+ <div className="grid grid-cols-1 @4xl/board:grid-cols-[minmax(0,1fr)_24rem] gap-6 items-start">
<section aria-label="Mood board items" className="min-w-0 space-y-3">
- <div className="flex items-center justify-between">
- <h2 className="text-sm font-medium text-white">Items ({items.length})</h2>
- </div>
{items.length === 0 ? (
<div className="text-gray-400 text-sm py-12 text-center border border-dashed border-port-border rounded">
No items yet. Pin an image or note to get started.
</div>
) : (
- <div className="grid grid-cols-[repeat(auto-fill,minmax(min(100%,14rem),1fr))] gap-3">
+ <div className="grid grid-cols-2 gap-2 sm:gap-3 sm:grid-cols-[repeat(auto-fill,minmax(min(100%,11rem),1fr))]">
{items.map((item) => {
const src = moodBoardItemSrc(item);
const videoSrc = moodBoardItemVideoSrc(item);
@@ -950,7 +1009,7 @@ function MoodBoardEditor({ id }) {
</div>
)}
</div>
- <div className="min-w-0 p-3 flex flex-col gap-2">
+ <div className="min-w-0 p-2 sm:p-3 flex flex-col gap-2">
<div className="min-w-0 flex items-center gap-2">
<span className="text-[10px] font-medium text-gray-400 flex items-center gap-1">
{isAnalyzed ? (
@@ -1093,6 +1152,54 @@ function MoodBoardEditor({ id }) {
</div>
)}
</section>
+
+ {sheetOpen ? (
+ <div className="fixed inset-0 z-40 bg-black/60" onClick={closeSheet} aria-hidden="true" />
+ ) : null}
+ {/* One element in both layouts, and every tool stays mounted while
+ hidden, so a running analysis, poster render or generation keeps its
+ state when the tool or the screen width changes. */}
+ <aside
+ ref={toolsRef}
+ aria-label="Board tools"
+ role={sheetOpen ? 'dialog' : undefined}
+ aria-modal={sheetOpen ? 'true' : undefined}
+ className={wide
+ ? 'min-w-0 sticky top-0 max-h-[calc(100dvh-2rem)] overflow-y-auto space-y-3'
+ : sheetOpen
+ ? 'port-opaque-surface fixed inset-x-0 bottom-0 z-50 max-h-[88dvh] overflow-y-auto rounded-t-xl bg-port-card border-t border-port-border shadow-2xl p-3 pb-6 space-y-3'
+ : 'hidden'}
+ >
+ <div className="flex items-center gap-1">
+ <TabPills
+ variant="pills"
+ size="xs"
+ stretch
+ mobileCompact
+ className="flex-1"
+ tabs={BOARD_TOOLS}
+ activeTab={activeTool}
+ onChange={selectTool}
+ ariaLabel="Board tool"
+ controlsIdPrefix="board-tool"
+ />
+ {sheetOpen ? (
+ <button
+ type="button"
+ onClick={closeSheet}
+ aria-label="Close board tools"
+ className="min-h-[44px] min-w-[44px] shrink-0 flex items-center justify-center rounded text-gray-400 hover:text-white"
+ >
+ <X className="w-5 h-5" aria-hidden="true" />
+ </button>
+ ) : null}
+ </div>
+ {BOARD_TOOLS.map(({ id: toolId }) => (
+ <div key={toolId} id={`board-tool-${toolId}`} role="tabpanel" aria-labelledby={`tab-${toolId}`} hidden={activeTool !== toolId}>
+ {toolPanels[toolId]}
+ </div>
+ ))}
+ </aside>
</div>
<GalleryImagePicker
diff --git a/client/src/pages/MoodBoardDetail.test.jsx b/client/src/pages/MoodBoardDetail.test.jsx
index 0d5e03ab9f..01e7192012 100644
--- a/client/src/pages/MoodBoardDetail.test.jsx
+++ b/client/src/pages/MoodBoardDetail.test.jsx
@@ -124,9 +124,11 @@ const renderPage = (initialEntries = ['/mood-boards/a']) => render(
);
const boardNameValue = () => screen.getByLabelText('Name').value;
+const openTool = (name) => fireEvent.click(screen.getByRole('tab', { name }));
beforeEach(() => {
vi.clearAllMocks();
+ localStorage.clear();
mockLocalizeMoodBoardMedia.mockResolvedValue({ board: null, localized: 0, failed: 0 });
currentId = 'a';
analysisDelay = null;
@@ -275,6 +277,7 @@ describe('MoodBoardDetail stale-response guards', () => {
mockSyncMoodBoardPinterest.mockReturnValueOnce(oldSync.promise);
const { rerender } = renderPage();
await waitFor(() => expect(boardNameValue()).toBe('Board A'));
+ openTool('Import');
fireEvent.click(screen.getByRole('button', { name: 'Sync now' }));
currentId = 'missing';
@@ -310,6 +313,7 @@ describe('MoodBoardDetail private Pinterest import', () => {
renderPage();
await waitFor(() => expect(boardNameValue()).toBe('Board A'));
+ openTool('Import');
fireEvent.change(screen.getByLabelText('Board URL'), { target: { value: boardUrl } });
fireEvent.click(screen.getByRole('button', { name: 'Import pins' }));
@@ -357,6 +361,7 @@ describe('MoodBoardDetail X post import', () => {
renderPage();
await waitFor(() => expect(boardNameValue()).toBe('Board A'));
+ openTool('Import');
fireEvent.change(screen.getByLabelText('Post URL'), { target: { value: 'https://x.com/user/status/1' } });
fireEvent.click(screen.getByRole('button', { name: 'Import' }));
@@ -371,6 +376,7 @@ describe('MoodBoardDetail X post import', () => {
renderPage();
await waitFor(() => expect(boardNameValue()).toBe('Board A'));
+ openTool('Import');
fireEvent.change(screen.getByLabelText('Post URL'), { target: { value: 'https://x.com/user/status/1' } });
fireEvent.click(screen.getByRole('button', { name: 'Import' }));
@@ -634,8 +640,8 @@ describe('MoodBoardDetail item analysis (#4188 Phase 3)', () => {
});
});
-describe('MoodBoardDetail desktop layout', () => {
- it('puts the add panel before the items list in the single-column source order', async () => {
+describe('MoodBoardDetail layout', () => {
+ it('shows pins first with every board tool one tap away in the side rail', async () => {
mockGetMoodBoard.mockResolvedValueOnce({
id: 'a',
name: 'Board A',
@@ -645,47 +651,31 @@ describe('MoodBoardDetail desktop layout', () => {
await waitFor(() => expect(boardNameValue()).toBe('Board A'));
const itemsSection = screen.getByRole('region', { name: 'Mood board items' });
- const addAside = screen.getByRole('complementary', { name: 'Add to mood board' });
-
- const parentGrid = itemsSection.parentElement;
- expect(parentGrid).toBe(addAside.parentElement);
- // Wide boards keep the 22rem side column. Source order is the stacked
- // order; order-last plus reading-flow put the aside on the right and
- // keep tab order with that visual column.
- expect(parentGrid.className).toContain('@4xl/board:grid-cols-[minmax(0,1fr)_22rem]');
- expect(parentGrid.className).toContain('[reading-flow:grid-order]');
- expect(parentGrid.firstElementChild).toBe(addAside);
- expect(parentGrid.lastElementChild).toBe(itemsSection);
- expect(addAside.className).toContain('@4xl/board:order-last');
- expect(addAside.compareDocumentPosition(itemsSection) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
-
- expect(addAside).toContainElement(screen.getByRole('heading', { name: 'Add item' }));
- expect(addAside).toContainElement(screen.getByRole('button', { name: 'Pin to board' }));
-
- const disclosure = screen.getByRole('button', { name: 'Import from Pinterest or X' });
- expect(disclosure).toHaveAttribute('aria-expanded', 'false');
- expect(disclosure.className).toContain('@4xl/board:hidden');
- const imports = document.getElementById('mood-board-import-panels');
- expect(addAside).toContainElement(imports);
- expect(imports.className).toContain('hidden');
- expect(imports.className).toContain('@4xl/board:block');
- expect(imports).toContainElement(screen.getByRole('button', { name: 'Import pins' }));
- expect(imports).toContainElement(screen.getByRole('button', { name: 'Import' }));
- expect(disclosure.compareDocumentPosition(itemsSection) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
+ const tools = screen.getByRole('complementary', { name: 'Board tools' });
+ expect(itemsSection.parentElement).toBe(tools.parentElement);
+ expect(itemsSection.compareDocumentPosition(tools) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
+ expect(itemsSection.parentElement.className).toContain('@4xl/board:grid-cols-[minmax(0,1fr)_24rem]');
+
+ // Add is the default tool; the others stay mounted but hidden.
+ expect(tools).toContainElement(screen.getByRole('button', { name: 'Pin to board' }));
+ expect(screen.queryByRole('button', { name: 'Import pins' })).toBeNull();
+ openTool('Import');
+ expect(screen.getByRole('heading', { name: 'Pinterest board' })).toBeInTheDocument();
+ expect(screen.getByRole('heading', { name: 'Import from an X post' })).toBeInTheDocument();
+ expect(screen.queryByRole('button', { name: 'Pin to board' })).toBeNull();
+ expect(screen.getByTestId('generate-more-panel')).toBeInTheDocument();
});
- it('reveals Pinterest and X import in one click on the stacked layout', async () => {
- mockGetMoodBoard.mockResolvedValueOnce({ id: 'a', name: 'Board A', items: [] });
+ it('remembers the last tool used for the next board', async () => {
+ mockGetMoodBoard.mockResolvedValue({ id: 'a', name: 'Board A', items: [] });
+ const { unmount } = renderPage();
+ await waitFor(() => expect(boardNameValue()).toBe('Board A'));
+ openTool('Import');
+ unmount();
renderPage();
await waitFor(() => expect(boardNameValue()).toBe('Board A'));
-
- fireEvent.click(screen.getByRole('button', { name: 'Import from Pinterest or X' }));
- const disclosure = screen.getByRole('button', { name: 'Import from Pinterest or X' });
- expect(disclosure).toHaveAttribute('aria-expanded', 'true');
- const imports = document.getElementById('mood-board-import-panels');
- expect(imports.className).not.toContain('hidden');
- expect(screen.getByRole('heading', { name: 'Pinterest board' })).toBeInTheDocument();
- expect(screen.getByRole('heading', { name: 'Import from an X post' })).toBeInTheDocument();
+ expect(screen.getByRole('tab', { name: 'Import' })).toHaveAttribute('aria-selected', 'true');
+ expect(screen.getByRole('button', { name: 'Import pins' })).toBeInTheDocument();
});
});