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(media): portal the add-to-collection popover and add a search filter

Adam Eivydec7f656b3f7
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 75e89cd688..a2c73e0f80 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -42,6 +42,7 @@ A page-level run dock now slides up from the bottom of the Writers Room while im
## Fixed
- Media Gen cards no longer overflow their action button row at narrow widths (6-column `lg:` grid in Image/Video Gen recent-renders). The button strip now uses `flex-wrap` so excess icon buttons spill cleanly onto a second row instead of bleeding past the card border, and the Remix/Continue label truncates instead of forcing the row wider.
+- Media Gen "Add to collection" popover is now portalled into `<body>` with viewport-aware fixed positioning, so it stacks above the sidebar and is no longer clipped by the gallery grid's `overflow-auto` parent (previously the menu was getting visually cut off and ducking under the nav). Once a user has 6+ collections, a search filter appears at the top of the menu so big collection lists are addressable by typing instead of scrolling.
- Stale-chunk auto-reload now covers Safari ("Importing a module script failed") and Firefox ("error loading dynamically imported module") in addition to Chrome — previously iOS Safari users hit a "Something went wrong" error after a rebuild and had to tap Refresh manually. Detection is shared between `lazyWithReload` (the primary path) and `ErrorBoundary` (safety net), with a one-reload-per-session guard against infinite loops.
- `ErrorBoundary` now uses theme-aware `text-port-text` / `text-port-text-muted` / `text-port-on-accent` instead of hardcoded `text-white` / `text-gray-400`, so the fallback UI is readable on light themes (Lumen Glass, etc).
- App icon detection: ship `data.sample/apps.json` with PortOS's icon path pre-set to `client/public/portos-logo.png`, and harden `detectAppIcon()` to skip SVGs that embed external `<image href="…">` (the icon endpoint serves SVG with `default-src 'none'` CSP, so those embeds are blocked and the icon renders blank). Detector now also checks `apple-touch-icon.png` and `icon-{192,512}.png` so PWAs without a usable favicon still resolve to a high-res raster. Hit "Detect Icon" once on existing installs to repick.
diff --git a/client/src/components/media/AddToCollectionMenu.jsx b/client/src/components/media/AddToCollectionMenu.jsx
index 6ee013543c..991c0fce79 100644
--- a/client/src/components/media/AddToCollectionMenu.jsx
+++ b/client/src/components/media/AddToCollectionMenu.jsx
@@ -1,42 +1,115 @@
-import { useEffect, useRef, useState } from 'react';
-import { FolderPlus, Check, Plus } from 'lucide-react';
+import { useEffect, useLayoutEffect, useRef, useState, useCallback, useMemo } from 'react';
+import { createPortal } from 'react-dom';
+import { FolderPlus, Check, Plus, Search } from 'lucide-react';
import toast from '../ui/Toast';
import {
listMediaCollections, createMediaCollection,
addMediaCollectionItem, removeMediaCollectionItem,
} from '../../services/api';
-// Self-contained popover button used by MediaCard. Fetches collections
-// lazily on first open so an empty-state grid doesn't slam the API once
-// per card. Toggling membership both adds and removes the item, so the
-// menu doubles as a "what collections is this in" indicator.
+// Self-contained popover button used by MediaCard. The popover is portalled
+// into <body> with fixed positioning so it escapes the parent grid's
+// `overflow-auto` clip and stacks above the sidebar (which is z-50).
//
// `itemKey` is "<kind>:<ref>" — the same format the server uses for
// coverKey and for the DELETE /items/:key route.
+
+const MENU_WIDTH = 240;
+const MENU_GAP = 6;
+const VIEWPORT_PADDING = 8;
+// Show search affordance only when the list could meaningfully scroll.
+const SEARCH_THRESHOLD = 6;
+
export default function AddToCollectionMenu({ item }) {
const [open, setOpen] = useState(false);
const [collections, setCollections] = useState(null); // null = not loaded
const [creating, setCreating] = useState(false);
const [newName, setNewName] = useState('');
const [busyId, setBusyId] = useState(null);
- const wrapperRef = useRef(null);
+ const [query, setQuery] = useState('');
+ const [menuStyle, setMenuStyle] = useState(null);
+ const triggerRef = useRef(null);
+ const menuRef = useRef(null);
const itemKey = `${item.kind}:${item.kind === 'video' ? item.id : item.filename}`;
const itemRef = item.kind === 'video' ? item.id : item.filename;
+ const filtered = useMemo(() => {
+ if (!collections) return null;
+ const q = query.trim().toLowerCase();
+ if (!q) return collections;
+ return collections.filter((c) => c.name.toLowerCase().includes(q));
+ }, [collections, query]);
+
+ const updateMenuPosition = useCallback(() => {
+ const trigger = triggerRef.current;
+ const menu = menuRef.current;
+ if (!trigger || !menu) return;
+
+ const viewportWidth = window.innerWidth;
+ const viewportHeight = window.innerHeight;
+ const width = Math.min(MENU_WIDTH, Math.max(180, viewportWidth - VIEWPORT_PADDING * 2));
+ menu.style.width = `${width}px`;
+
+ const triggerRect = trigger.getBoundingClientRect();
+ const menuRect = menu.getBoundingClientRect();
+
+ const maxLeft = viewportWidth - width - VIEWPORT_PADDING;
+ const left = Math.min(
+ Math.max(triggerRect.right - width, VIEWPORT_PADDING),
+ Math.max(VIEWPORT_PADDING, maxLeft),
+ );
+
+ const aboveTop = triggerRect.top - menuRect.height - MENU_GAP;
+ const belowTop = triggerRect.bottom + MENU_GAP;
+ const wouldOverflowTop = aboveTop < VIEWPORT_PADDING;
+ let top = wouldOverflowTop ? belowTop : aboveTop;
+ const maxTop = Math.max(VIEWPORT_PADDING, viewportHeight - menuRect.height - VIEWPORT_PADDING);
+ top = Math.min(Math.max(top, VIEWPORT_PADDING), maxTop);
+
+ setMenuStyle((prev) => {
+ const next = { left: `${left}px`, top: `${top}px`, width: `${width}px` };
+ if (prev && prev.left === next.left && prev.top === next.top && prev.width === next.width) return prev;
+ return next;
+ });
+ }, []);
+
useEffect(() => {
if (!open) return undefined;
const onClickAway = (e) => {
- if (!wrapperRef.current?.contains(e.target)) setOpen(false);
+ const onTrigger = triggerRef.current?.contains(e.target);
+ const onMenu = menuRef.current?.contains(e.target);
+ if (!onTrigger && !onMenu) setOpen(false);
};
const onEsc = (e) => { if (e.key === 'Escape') setOpen(false); };
+ let rafId = null;
+ const onReposition = () => {
+ if (rafId !== null) return;
+ rafId = requestAnimationFrame(() => {
+ rafId = null;
+ updateMenuPosition();
+ });
+ };
document.addEventListener('mousedown', onClickAway);
document.addEventListener('keydown', onEsc);
+ window.addEventListener('resize', onReposition);
+ window.addEventListener('scroll', onReposition, true);
return () => {
+ if (rafId !== null) cancelAnimationFrame(rafId);
document.removeEventListener('mousedown', onClickAway);
document.removeEventListener('keydown', onEsc);
+ window.removeEventListener('resize', onReposition);
+ window.removeEventListener('scroll', onReposition, true);
};
- }, [open]);
+ }, [open, updateMenuPosition]);
+
+ useLayoutEffect(() => {
+ if (!open) {
+ setMenuStyle(null);
+ return;
+ }
+ updateMenuPosition();
+ }, [open, updateMenuPosition, collections, filtered, query]);
const ensureLoaded = async () => {
if (collections != null) return;
@@ -51,7 +124,10 @@ export default function AddToCollectionMenu({ item }) {
e.stopPropagation();
const next = !open;
setOpen(next);
- if (next) await ensureLoaded();
+ if (next) {
+ setQuery('');
+ await ensureLoaded();
+ }
};
const handleToggleMembership = async (collection) => {
@@ -82,9 +158,6 @@ export default function AddToCollectionMenu({ item }) {
return null;
});
if (!created) { setCreating(false); return; }
- // Auto-add the current item so the user doesn't have to click twice
- // after creating a brand-new collection for it. Track the add result
- // separately so a failure here doesn't masquerade as success.
let addError = null;
const withItem = await addMediaCollectionItem(created.id, { kind: item.kind, ref: itemRef }).catch((err) => {
addError = err;
@@ -100,44 +173,79 @@ export default function AddToCollectionMenu({ item }) {
}
};
+ const showSearch = (collections?.length || 0) >= SEARCH_THRESHOLD;
+ const list = filtered ?? collections;
+
return (
- <div ref={wrapperRef} className="relative shrink-0">
+ <>
<button
+ ref={triggerRef}
type="button"
onClick={handleToggleOpen}
- className="px-1.5 py-1 bg-port-border hover:bg-port-border/70 text-white text-[10px] rounded flex items-center justify-center"
+ className="shrink-0 px-1.5 py-1 bg-port-border hover:bg-port-border/70 text-white text-[10px] rounded flex items-center justify-center"
title="Add to collection"
+ aria-haspopup="menu"
+ aria-expanded={open}
>
<FolderPlus className="w-3 h-3" />
</button>
- {open && (
+ {open && createPortal(
<div
- className="absolute right-0 bottom-full mb-1 w-56 max-h-72 overflow-y-auto bg-port-card border border-port-border rounded-lg shadow-lg z-20 p-1.5"
+ ref={menuRef}
+ className="fixed bg-port-card border border-port-border rounded-lg shadow-xl z-[100] p-1.5 flex flex-col"
+ style={{
+ left: menuStyle?.left ?? `${VIEWPORT_PADDING}px`,
+ top: menuStyle?.top ?? `${VIEWPORT_PADDING}px`,
+ width: menuStyle?.width ?? `${MENU_WIDTH}px`,
+ maxHeight: 'min(360px, calc(100vh - 16px))',
+ visibility: menuStyle ? 'visible' : 'hidden',
+ }}
onClick={(e) => e.stopPropagation()}
+ role="menu"
>
- <div className="text-[10px] text-gray-500 uppercase tracking-wide px-1 pt-1 pb-1.5">Collections</div>
- {collections == null && (
- <div className="text-[11px] text-gray-500 px-2 py-2">Loading…</div>
- )}
- {collections != null && collections.length === 0 && (
- <div className="text-[11px] text-gray-500 px-2 py-2">No collections yet — create one below.</div>
+ <div className="text-[10px] text-gray-500 uppercase tracking-wide px-1 pt-1 pb-1.5 shrink-0">Collections</div>
+ {showSearch && (
+ <div className="relative shrink-0 mb-1.5">
+ <Search className="absolute left-2 top-1/2 -translate-y-1/2 w-3 h-3 text-gray-500 pointer-events-none" />
+ <input
+ type="text"
+ value={query}
+ onChange={(e) => setQuery(e.target.value)}
+ placeholder="Search collections…"
+ className="w-full bg-port-bg border border-port-border rounded pl-7 pr-2 py-1 text-[11px] text-white focus:outline-none focus:border-port-accent"
+ autoFocus
+ />
+ </div>
)}
- {collections != null && collections.map((c) => {
- const inIt = c.items.some((it) => `${it.kind}:${it.ref}` === itemKey);
- return (
- <button
- key={c.id}
- type="button"
- disabled={busyId === c.id}
- onClick={() => handleToggleMembership(c)}
- className="w-full flex items-center justify-between gap-2 px-2 py-1.5 text-left text-[12px] text-gray-200 hover:bg-port-border rounded disabled:opacity-50"
- >
- <span className="truncate">{c.name}</span>
- {inIt && <Check className="w-3.5 h-3.5 text-port-success shrink-0" />}
- </button>
- );
- })}
- <form onSubmit={handleCreate} className="mt-1.5 pt-1.5 border-t border-port-border flex gap-1">
+ <div className="flex-1 min-h-0 overflow-y-auto">
+ {collections == null && (
+ <div className="text-[11px] text-gray-500 px-2 py-2">Loading…</div>
+ )}
+ {collections != null && collections.length === 0 && (
+ <div className="text-[11px] text-gray-500 px-2 py-2">No collections yet — create one below.</div>
+ )}
+ {list != null && collections?.length > 0 && list.length === 0 && (
+ <div className="text-[11px] text-gray-500 px-2 py-2">No matches for &ldquo;{query}&rdquo;</div>
+ )}
+ {list != null && list.map((c) => {
+ const inIt = c.items.some((it) => `${it.kind}:${it.ref}` === itemKey);
+ return (
+ <button
+ key={c.id}
+ type="button"
+ disabled={busyId === c.id}
+ onClick={() => handleToggleMembership(c)}
+ className="w-full flex items-center justify-between gap-2 px-2 py-1.5 text-left text-[12px] text-gray-200 hover:bg-port-border rounded disabled:opacity-50"
+ role="menuitemcheckbox"
+ aria-checked={inIt}
+ >
+ <span className="truncate">{c.name}</span>
+ {inIt && <Check className="w-3.5 h-3.5 text-port-success shrink-0" />}
+ </button>
+ );
+ })}
+ </div>
+ <form onSubmit={handleCreate} className="mt-1.5 pt-1.5 border-t border-port-border flex gap-1 shrink-0">
<input
type="text"
value={newName}
@@ -155,8 +263,9 @@ export default function AddToCollectionMenu({ item }) {
<Plus className="w-3 h-3" />
</button>
</form>
- </div>
+ </div>,
+ document.body,
)}
- </div>
+ </>
);
}