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

address review (round 11): guard dirty layout switch, fix picker ARIA

Adam Eivy9eed3e8a0f6b
diff --git a/client/src/components/dashboard/LayoutEditor.jsx b/client/src/components/dashboard/LayoutEditor.jsx
index 8ee46b715e..ba0f8a0028 100644
--- a/client/src/components/dashboard/LayoutEditor.jsx
+++ b/client/src/components/dashboard/LayoutEditor.jsx
@@ -20,8 +20,9 @@ export default function LayoutEditor({ layouts, activeLayoutId, limits, onClose,
const [widgets, setWidgets] = useState(editing?.widgets ?? []);
const [name, setName] = useState(editing?.name ?? '');
const [dirty, setDirty] = useState(false);
- const [mode, setMode] = useState('idle'); // 'idle' | 'duplicate' | 'delete'
+ const [mode, setMode] = useState('idle'); // 'idle' | 'duplicate' | 'delete' | 'switch'
const [dupName, setDupName] = useState('');
+ const [pendingSwitchId, setPendingSwitchId] = useState(null);
const closeRef = useRef(null);
useScrollLock(true);
@@ -41,9 +42,32 @@ export default function LayoutEditor({ layouts, activeLayoutId, limits, onClose,
setDirty(false);
setMode('idle');
setDupName('');
+ setPendingSwitchId(null);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [editingId]);
+ // Guard layout switches when there are unsaved edits: instead of silently
+ // discarding the draft, surface an inline confirm in the footer.
+ const requestSwitch = (id) => {
+ if (id === editingId) return;
+ if (dirty) {
+ setPendingSwitchId(id);
+ setMode('switch');
+ return;
+ }
+ setEditingId(id);
+ };
+
+ const confirmSwitch = () => {
+ if (!pendingSwitchId) { setMode('idle'); return; }
+ setEditingId(pendingSwitchId); // rehydrate effect clears dirty/mode
+ };
+
+ const cancelSwitch = () => {
+ setPendingSwitchId(null);
+ setMode('idle');
+ };
+
const close = useCallback(() => { onClose(); }, [onClose]);
const onKeyDown = (e) => {
@@ -135,7 +159,7 @@ export default function LayoutEditor({ layouts, activeLayoutId, limits, onClose,
{layouts.map((l) => (
<button
key={l.id}
- onClick={() => setEditingId(l.id)}
+ onClick={() => requestSwitch(l.id)}
className={`w-full text-left px-4 py-2 text-sm border-l-2 ${
l.id === editingId ? 'border-port-accent bg-white/5 text-white' : 'border-transparent text-gray-400 hover:bg-white/5 hover:text-white'
}`}
@@ -226,6 +250,13 @@ export default function LayoutEditor({ layouts, activeLayoutId, limits, onClose,
<button onClick={() => setMode('idle')} className="px-3 py-1.5 text-sm text-gray-300 hover:text-white rounded-lg border border-port-border">Cancel</button>
</div>
)}
+ {mode === 'switch' && (
+ <div className="flex items-center gap-2">
+ <span className="flex-1 text-sm text-port-warning">Discard unsaved changes to &ldquo;{editing?.name}&rdquo;?</span>
+ <button onClick={confirmSwitch} className="px-3 py-1.5 text-sm rounded-lg bg-port-warning text-black hover:bg-port-warning/80">Discard</button>
+ <button onClick={cancelSwitch} className="px-3 py-1.5 text-sm text-gray-300 hover:text-white rounded-lg border border-port-border">Cancel</button>
+ </div>
+ )}
{mode === 'idle' && (
<div className="flex items-center justify-between gap-2">
<div className="flex items-center gap-2">
diff --git a/client/src/components/dashboard/LayoutPicker.jsx b/client/src/components/dashboard/LayoutPicker.jsx
index f8d9895dfa..fd8161b1a4 100644
--- a/client/src/components/dashboard/LayoutPicker.jsx
+++ b/client/src/components/dashboard/LayoutPicker.jsx
@@ -9,8 +9,13 @@ export default function LayoutPicker({ layouts, activeLayoutId, onSelect, onEdit
useEffect(() => {
if (!open) return;
const onDocClick = (e) => { if (!ref.current?.contains(e.target)) setOpen(false); };
+ const onKey = (e) => { if (e.key === 'Escape') setOpen(false); };
document.addEventListener('mousedown', onDocClick);
- return () => document.removeEventListener('mousedown', onDocClick);
+ document.addEventListener('keydown', onKey);
+ return () => {
+ document.removeEventListener('mousedown', onDocClick);
+ document.removeEventListener('keydown', onKey);
+ };
}, [open]);
return (
@@ -21,7 +26,7 @@ export default function LayoutPicker({ layouts, activeLayoutId, onSelect, onEdit
title="Switch dashboard layout"
aria-label={`Dashboard layout: ${active?.name || 'none'}`}
aria-expanded={open}
- aria-haspopup="menu"
+ aria-haspopup="true"
>
<LayoutGrid size={14} aria-hidden="true" />
<span className="hidden sm:inline">{active?.name || 'Layout'}</span>
@@ -29,7 +34,6 @@ export default function LayoutPicker({ layouts, activeLayoutId, onSelect, onEdit
{open && (
<div
- role="menu"
aria-label="Dashboard layout menu"
className="absolute right-0 mt-1 w-56 bg-port-card border border-port-border rounded-lg shadow-2xl overflow-hidden z-50"
>
@@ -37,8 +41,7 @@ export default function LayoutPicker({ layouts, activeLayoutId, onSelect, onEdit
{layouts.map((l) => (
<button
key={l.id}
- role="menuitemradio"
- aria-checked={l.id === activeLayoutId}
+ aria-current={l.id === activeLayoutId ? 'true' : undefined}
onClick={() => {
setOpen(false);
// onSelect performs an API write; request() toasts any
@@ -57,7 +60,6 @@ export default function LayoutPicker({ layouts, activeLayoutId, onSelect, onEdit
</div>
<div className="border-t border-port-border">
<button
- role="menuitem"
onClick={() => { setOpen(false); onEdit(); }}
className="w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-300 hover:bg-white/5 hover:text-white"
>