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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
keep the mobile notifications panel on screen by placing it with usePopoverPosition
[._.]/ Adam Eivy537b3c3a5c31
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdnew file mode 100644index 0000000000..90cf5d8fee--- /dev/null+++ b/.changelog/NEXT.md@@ -0,0 +1,10 @@+## Fixed++- Tapping the notifications bell on a phone now opens a panel that stays on screen. It was anchored to the bell — which sits mid-screen in the sidebar — so the panel ran off the right edge, clipping notification titles and putting every per-item dismiss button and the mark-all/clear-all controls out of reach with nothing to scroll to them.+- The notification panel's "+N more notifications" line is now a "Show N more" button, so the notifications past the first ten can be read and dismissed instead of being permanently unreachable.+- Notification dismiss and "Mark read" buttons are now full-size, always-visible tap targets on touch devices — they were sized to their bare icon, and the dismiss button was only revealed on hover, which a phone has no way to do.+- The notification panel now closes on Escape, and long notification descriptions wrap to two lines instead of being cut off mid-word.++## Changed++- Notification panel placement now goes through the shared popover-positioning hook that the theme switcher beside it already used, so it clamps into the viewport and flips above/below on its own instead of relying on hand-written positioning.diff --git a/client/src/components/NotificationDropdown.jsx b/client/src/components/NotificationDropdown.jsxindex 1b14f66c6f..608bf20e3d 100644--- a/client/src/components/NotificationDropdown.jsx+++ b/client/src/components/NotificationDropdown.jsx@@ -1,8 +1,11 @@import { useState, useRef, useEffect } from 'react';+import { createPortal } from 'react-dom';import { useNavigate } from 'react-router';import { Bell, X, CheckCheck, Trash2, Brain, ListTodo, AlertTriangle, Code, HelpCircle, BellRing, Sparkles } from 'lucide-react';import { timeAgo } from '../utils/formatters';import { clickableProps } from '../lib/a11yKeyboard';+import useClickOutside from '../hooks/useClickOutside.js';+import usePopoverPosition, { VIEWPORT_PADDING } from '../hooks/usePopoverPosition.js';const NOTIFICATION_TYPE_CONFIG = {memory_approval: {@@ -47,6 +50,9 @@ const NOTIFICATION_TYPE_CONFIG = {}};+const COLLAPSED_LIMIT = 10;+const PANEL_WIDTH = 320;+const PRIORITY_COLORS = {low: 'border-gray-500/30',medium: 'border-yellow-500/30',@@ -61,23 +67,45 @@ export default function NotificationDropdown({onMarkAllAsRead,onRemove,onClearAll,- position = 'bottom' // 'bottom' opens upward, 'top' opens downward+ position = 'above' // 'above' prefers opening upward, 'below' downward}) {const [isOpen, setIsOpen] = useState(false);- const dropdownRef = useRef(null);+ const [showAll, setShowAll] = useState(false);+ const containerRef = useRef(null);const navigate = useNavigate();- // Close dropdown when clicking outside+ // The panel is portaled to <body> and placed in viewport coordinates. That is+ // what keeps it on-screen from this trigger: the bell sits mid-screen in the+ // sidebar footer, so an absolutely-positioned 320px panel ran off the right+ // edge on a phone — titles clipped, dismiss and mark-all/clear-all controls+ // unreachable with nothing to scroll. The hook clamps into the viewport and+ // flips above/below, so there is no breakpoint branch to keep in sync. Height+ // changes (expanding the list) re-measure via contentDeps.+ const { triggerRef, popoverRef, style: panelStyle } = usePopoverPosition({+ open: isOpen,+ width: PANEL_WIDTH,+ minWidth: 260,+ position,+ contentDeps: [showAll, notifications.length]+ });++ // Both refs: the panel lives outside the trigger's subtree once portaled, so a+ // trigger-only containment check would read clicks on the panel as outside.+ useClickOutside([containerRef, popoverRef], isOpen, () => setIsOpen(false));+useEffect(() => {- const handleClickOutside = (event) => {- if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {- setIsOpen(false);- }+ if (!isOpen) return undefined;+ const onKeyDown = (e) => {+ if (e.key === 'Escape') setIsOpen(false);};+ document.addEventListener('keydown', onKeyDown);+ return () => document.removeEventListener('keydown', onKeyDown);+ }, [isOpen]);- document.addEventListener('mousedown', handleClickOutside);- return () => document.removeEventListener('mousedown', handleClickOutside);- }, []);+ // Collapse back to the first page each time the panel is dismissed+ useEffect(() => {+ if (!isOpen) setShowAll(false);+ }, [isOpen]);const handleNotificationClick = (notification) => {if (!notification.read) {@@ -89,10 +117,14 @@ export default function NotificationDropdown({}};+ const visible = showAll ? notifications : notifications.slice(0, COLLAPSED_LIMIT);+ const hiddenCount = notifications.length - visible.length;+return (- <div className="relative" ref={dropdownRef}>+ <div className="relative" ref={containerRef}>{/* Bell button with badge */}<button+ ref={triggerRef}onClick={() => setIsOpen(!isOpen)}className="relative inline-flex items-center justify-center min-w-[44px] min-h-[44px] sm:min-w-0 sm:min-h-0 sm:p-2 rounded-lg hover:bg-port-card transition-colors focus:outline-hidden focus:ring-2 focus:ring-port-accent focus:ring-offset-2 focus:ring-offset-port-bg"title="Notifications"@@ -108,16 +140,18 @@ export default function NotificationDropdown({)}</button>- {/* Dropdown panel - position determines direction */}- {isOpen && (+ {isOpen && createPortal(<div+ ref={popoverRef}role="menu"aria-label="Notifications menu"- className={`absolute w-80 max-w-[calc(100vw-2rem)] bg-port-card border border-port-border rounded-lg shadow-xl z-50 overflow-hidden ${- position === 'bottom'- ? 'left-0 bottom-full mb-2' // Opens upward from sidebar footer- : 'right-0 top-full mt-2' // Opens downward from header- }`}+ className="fixed bg-port-card border border-port-border rounded-lg shadow-xl z-[100] overflow-hidden"+ style={{+ left: panelStyle?.left ?? `${VIEWPORT_PADDING}px`,+ top: panelStyle?.top ?? `${VIEWPORT_PADDING}px`,+ width: panelStyle?.width ?? `${PANEL_WIDTH}px`,+ visibility: panelStyle ? 'visible' : 'hidden'+ }}>{/* Header */}<div className="flex items-center justify-between px-4 py-3 border-b border-port-border">@@ -145,17 +179,28 @@ export default function NotificationDropdown({<Trash2 className="w-4 h-4 text-gray-400" aria-hidden="true" /></button>)}+ {/* Touch has no Escape key, and a tall panel can be clamped over the+ bell, so mobile needs an explicit dismiss it can always reach. */}+ <button+ type="button"+ onClick={() => setIsOpen(false)}+ className="inline-flex items-center justify-center min-w-[44px] min-h-[44px] rounded hover:bg-port-border transition-colors focus:outline-hidden focus:ring-2 focus:ring-port-accent sm:hidden"+ title="Close"+ aria-label="Close notifications"+ >+ <X className="w-4 h-4 text-gray-400" aria-hidden="true" />+ </button></div></div>{/* Notification list */}- <div className="max-h-96 overflow-y-auto">+ <div className="max-h-[60dvh] overflow-y-auto sm:max-h-96">{notifications.length === 0 ? (<div className="px-4 py-8 text-center text-gray-500">No notifications</div>) : (- notifications.slice(0, 10).map(notification => {+ visible.map(notification => {const config = NOTIFICATION_TYPE_CONFIG[notification.type] || NOTIFICATION_TYPE_CONFIG.task_approval;const Icon = config.icon;@@ -176,8 +221,8 @@ export default function NotificationDropdown({<Icon className={`w-4 h-4 ${config.color}`} /></div><div className="flex-1 min-w-0">- <div className="flex items-center justify-between">- <span className={`text-sm font-medium ${!notification.read ? 'text-white' : 'text-gray-300'}`}>+ <div className="flex items-start justify-between gap-2">+ <span className={`min-w-0 flex-1 text-sm font-medium break-words ${!notification.read ? 'text-white' : 'text-gray-300'}`}>{notification.title}</span><button@@ -186,18 +231,18 @@ export default function NotificationDropdown({e.stopPropagation();onRemove(notification.id);}}- className="p-1 rounded hover:bg-port-border transition-colors opacity-40 sm:opacity-0 sm:group-hover:opacity-100 focus:opacity-100 focus:outline-hidden focus:ring-2 focus:ring-port-accent"+ className="shrink-0 inline-flex items-center justify-center min-w-[44px] min-h-[44px] -my-2 rounded hover:bg-port-border transition-colors sm:min-w-0 sm:min-h-0 sm:my-0 sm:p-1 sm:opacity-0 sm:group-hover:opacity-100 focus:opacity-100 focus:outline-hidden focus:ring-2 focus:ring-port-accent"aria-label={`Remove notification: ${notification.title}`}>- <X className="w-3 h-3 text-gray-500" aria-hidden="true" />+ <X className="w-4 h-4 text-gray-500 sm:w-3 sm:h-3" aria-hidden="true" /></button></div>{notification.description && (- <p className="text-xs text-gray-500 mt-0.5 truncate">+ <p className="text-xs text-gray-500 mt-0.5 line-clamp-2">{notification.description}</p>)}- <div className="flex items-center gap-2 mt-1">+ <div className="flex items-center gap-3 mt-1 sm:gap-2"><span className="text-[10px] text-gray-600">{timeAgo(notification.timestamp)}</span>@@ -208,7 +253,7 @@ export default function NotificationDropdown({e.stopPropagation();onMarkAsRead(notification.id);}}- className="text-[10px] text-port-accent hover:underline"+ className="text-[10px] text-port-accent hover:underline py-2 -my-2 sm:py-0 sm:my-0">Mark read</button>@@ -222,15 +267,20 @@ export default function NotificationDropdown({)}</div>- {/* Footer */}- {notifications.length > 10 && (- <div className="px-4 py-2 border-t border-port-border text-center">- <span className="text-xs text-gray-500">- +{notifications.length - 10} more notifications- </span>+ {/* Actionable, so the overflow is reachable rather than merely counted */}+ {hiddenCount > 0 && (+ <div className="border-t border-port-border text-center">+ <button+ type="button"+ onClick={() => setShowAll(true)}+ className="w-full px-4 py-3 text-xs text-port-accent hover:bg-port-border/50 transition-colors focus:outline-hidden focus:ring-2 focus:ring-port-accent sm:py-2"+ >+ Show {hiddenCount} more notification{hiddenCount === 1 ? '' : 's'}+ </button></div>)}- </div>+ </div>,+ document.body)}</div>);diff --git a/client/src/components/NotificationDropdown.test.jsx b/client/src/components/NotificationDropdown.test.jsxnew file mode 100644index 0000000000..9b4edb8e2d--- /dev/null+++ b/client/src/components/NotificationDropdown.test.jsx@@ -0,0 +1,180 @@+import { describe, it, expect, vi } from 'vitest';+import { render, screen, fireEvent } from '@testing-library/react';+import { MemoryRouter } from 'react-router';+import NotificationDropdown from './NotificationDropdown';++const makeNotifications = (count) =>+ Array.from({ length: count }, (_, i) => ({+ id: `n${i}`,+ type: 'agent_warning',+ title: `Notification ${i}`,+ description: `Description ${i}`,+ priority: 'medium',+ read: false,+ timestamp: new Date('2026-01-01T00:00:00Z').toISOString()+ }));++const renderDropdown = ({ notifications = makeNotifications(3), ...overrides } = {}) => {+ const handlers = {+ onMarkAsRead: vi.fn(),+ onMarkAllAsRead: vi.fn(),+ onRemove: vi.fn(),+ onClearAll: vi.fn(),+ ...overrides+ };+ render(+ <MemoryRouter>+ <NotificationDropdown+ notifications={notifications}+ unreadCount={notifications.filter((n) => !n.read).length}+ {...handlers}+ />+ </MemoryRouter>+ );+ return handlers;+};++const openPanel = () => {+ fireEvent.click(screen.getByRole('button', { name: /^Notifications/ }));+ return screen.getByRole('menu', { name: 'Notifications menu' });+};++const queryPanel = () => screen.queryByRole('menu', { name: 'Notifications menu' });++describe('NotificationDropdown', () => {+ describe('placement', () => {+ // The bell sits mid-screen in the sidebar footer. An absolutely-positioned+ // panel ran off the right edge of a phone; placement now comes from the+ // shared viewport-clamping hook, which owns the measure/flip/clamp plumbing.+ it('portals the panel out of the trigger subtree and places it in viewport coordinates', () => {+ renderDropdown();+ const panel = openPanel();++ expect(panel.closest('[role="menu"]').parentElement).toBe(document.body);+ expect(panel.className).toContain('fixed');+ expect(panel.style.left).not.toBe('');+ expect(panel.style.top).not.toBe('');+ expect(panel.style.width).not.toBe('');+ });++ it('carries no trigger-anchored positioning classes that would fight the hook', () => {+ renderDropdown();+ const classes = openPanel().className.split(/\s+/);++ // Placement is inline style from the hook. Any leftover `absolute` or inset+ // utility would silently override it at whatever breakpoint it applies to.+ const anchored = classes.filter((c) => /^(sm:|md:|lg:)?(absolute|inset|left|right|top|bottom)(-|$)/.test(c));+ expect(anchored).toEqual([]);+ });+ });++ describe('dismissal', () => {+ it('closes on Escape', () => {+ renderDropdown();+ openPanel();++ fireEvent.keyDown(document, { key: 'Escape' });++ expect(queryPanel()).toBeNull();+ });++ it('closes on an outside click but not on a click inside the portaled panel', () => {+ renderDropdown();+ const panel = openPanel();++ // Regression guard: the panel is not a DOM descendant of the trigger, so a+ // trigger-only containment check would read this as an outside click.+ fireEvent.mouseDown(panel);+ expect(queryPanel()).not.toBeNull();++ fireEvent.mouseDown(document.body);+ expect(queryPanel()).toBeNull();+ });++ it('offers a close control below sm, where there is no Escape key', () => {+ renderDropdown();+ openPanel();++ const close = screen.getByRole('button', { name: 'Close notifications' });+ expect(close.className).toContain('sm:hidden');++ fireEvent.click(close);+ expect(queryPanel()).toBeNull();+ });+ });++ describe('touch targets', () => {+ it('gives each dismiss button a real tap target that is visible without hover', () => {+ renderDropdown();+ openPanel();++ const remove = screen.getByRole('button', { name: 'Remove notification: Notification 0' });+ expect(remove.className).toContain('min-w-[44px]');+ expect(remove.className).toContain('min-h-[44px]');+ expect(remove.className).toContain('shrink-0');+ // Hover-to-reveal is sm+ only — touch has no hover to reveal it with.+ expect(remove.className).toContain('sm:opacity-0');+ expect(remove.className).not.toMatch(/(^|\s)opacity-/);+ });+ });++ describe('overflow beyond the collapsed limit', () => {+ it('caps the list at 10 and reveals the rest on demand', () => {+ renderDropdown({ notifications: makeNotifications(24) });+ openPanel();++ expect(screen.getByText('Notification 9')).toBeTruthy();+ expect(screen.queryByText('Notification 10')).toBeNull();++ fireEvent.click(screen.getByRole('button', { name: 'Show 14 more notifications' }));++ expect(screen.getByText('Notification 23')).toBeTruthy();+ expect(screen.queryByRole('button', { name: /Show \d+ more/ })).toBeNull();+ });++ it('singularizes the overflow control for a single hidden notification', () => {+ renderDropdown({ notifications: makeNotifications(11) });+ openPanel();++ expect(screen.getByRole('button', { name: 'Show 1 more notification' })).toBeTruthy();+ });++ it('collapses back to the first page once the panel is dismissed', () => {+ renderDropdown({ notifications: makeNotifications(24) });+ openPanel();+ fireEvent.click(screen.getByRole('button', { name: 'Show 14 more notifications' }));++ fireEvent.click(screen.getByRole('button', { name: 'Close notifications' }));+ openPanel();++ expect(screen.queryByText('Notification 10')).toBeNull();+ expect(screen.getByRole('button', { name: 'Show 14 more notifications' })).toBeTruthy();+ });++ it('shows no overflow control when everything already fits', () => {+ renderDropdown({ notifications: makeNotifications(10) });+ openPanel();++ expect(screen.queryByRole('button', { name: /Show \d+ more/ })).toBeNull();+ });+ });++ it('dismisses a single notification without triggering its click-through', () => {+ const { onRemove, onMarkAsRead } = renderDropdown();+ openPanel();++ fireEvent.click(screen.getByRole('button', { name: 'Remove notification: Notification 0' }));++ expect(onRemove).toHaveBeenCalledWith('n0');+ expect(onMarkAsRead).not.toHaveBeenCalled();+ });++ it('clears every notification from the header', () => {+ const { onClearAll } = renderDropdown();+ openPanel();++ fireEvent.click(screen.getByRole('button', { name: 'Clear all notifications' }));++ expect(onClearAll).toHaveBeenCalled();+ });+});diff --git a/client/src/hooks/README.md b/client/src/hooks/README.mdindex c8b74562d8..b4914da3f0 100644--- a/client/src/hooks/README.md+++ b/client/src/hooks/README.md@@ -92,7 +92,7 @@ grep -i "what you want to do" client/src/hooks/README.md| `useAutoRefetch` | Poll-based refetch on an interval. `{ pollOnly: true }` skips internal data/loading state for side-effect-only callers (returns `{ refetch }` only). | Data needs periodic refresh (no socket / SSE available). || `useAutoSizeTextarea` | `[ref, resize]` — grows a `<textarea>` to fit its content (no scroll / hand-resize); recomputes before paint on value change. | A textarea that should auto-fit content. Prefer the `AutoSizeTextarea` UI component, which wraps this. || `useChartColors` | Resolves the `--port-*` theme tokens (accent/success/warning/error, `chart-1..4`, grid, axis, tooltip surfaces) to concrete `rgb()` strings via `getComputedStyle`, re-resolving on theme switch. | A recharts card needs theme-following colors — SVG `fill`/`stroke` props can't read CSS vars, so pass these resolved strings instead of hardcoded hex. |-| `useClickOutside` | Fire `onOutside` on mousedown outside a ref. | Popovers, menus, drawers. |+| `useClickOutside` | Fire `onOutside` on mousedown outside a ref — or outside *every* ref in an array. | Popovers, menus, drawers. Pass `[triggerRef, panelRef]` for a portaled panel, which is outside the trigger's subtree. || `useConfirmDelete` | Single-at-a-time `{ confirmingId, isConfirming, requestDelete, cancelDelete, confirmDelete }` for arming one list/card row at a time. | New destructive list action — pair with `<InlineConfirmRow>` / `<ConfirmButtonPair>` instead of deleting on the raw trash click. || `useEscapeKey` | `useEscapeKey(active, handler)` — call `handler` on Escape while `active`. | Non-modal dismissables (in-context popovers/cards); Modal owns Esc for true modals. || `useFocusTrap` | `useFocusTrap(active, containerRef, { initialFocusRef? })` — moves focus into the container on open, traps Tab/Shift+Tab so it can't escape to the page behind, and restores focus to the opener on close (WCAG 2.4.3 / 2.1.2). | Modal surfaces (dialogs, drawers, lightboxes). Already wired into `Modal` and `Drawer` — reach for it when hand-rolling a new overlay. |diff --git a/client/src/hooks/useClickOutside.js b/client/src/hooks/useClickOutside.jsindex 3d151a644d..fcab21892c 100644--- a/client/src/hooks/useClickOutside.js+++ b/client/src/hooks/useClickOutside.js@@ -1,21 +1,35 @@import { useEffect, useRef } from 'react';-// Calls onOutside when a mousedown lands outside the ref'd element.+// Calls onOutside when a mousedown lands outside the ref'd element(s).// Listener only attaches while `active` is true so closed menus don't pay// the per-click cost.//+// `ref` accepts a single ref OR an array of refs, and fires only when the click+// missed every one of them. The array form is what a portaled popover needs: its+// panel renders into <body>, so it is NOT inside the trigger's DOM subtree and a+// single-ref containment check would treat every click on the panel itself as an+// outside click and close it. Pass [triggerRef, panelRef] instead of hand-rolling+// the two-ref effect.+//// `onOutside` is read through a ref, so an inline arrow recreated every parent// render (the common call-site shape) doesn't tear down + re-add the global// mousedown listener on each render — only `active`/`ref` flip the subscription.export default function useClickOutside(ref, active, onOutside) {const onOutsideRef = useRef(onOutside);onOutsideRef.current = onOutside;+ // Depend on the array's *contents*, not its identity — an inline+ // `[triggerRef, panelRef]` literal is a new array every render and would+ // otherwise resubscribe the global listener on each one.+ const refs = Array.isArray(ref) ? ref : [ref];+ const refsKey = refs;useEffect(() => {if (!active) return undefined;const onDown = (e) => {- if (!ref.current?.contains(e.target)) onOutsideRef.current();+ if (refsKey.some((r) => r.current?.contains(e.target))) return;+ onOutsideRef.current();};window.addEventListener('mousedown', onDown);return () => window.removeEventListener('mousedown', onDown);- }, [active, ref]);+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [active, ...refsKey]);}diff --git a/client/src/hooks/useClickOutside.test.jsx b/client/src/hooks/useClickOutside.test.jsxindex 89dbe0d5d4..56d48f795f 100644--- a/client/src/hooks/useClickOutside.test.jsx+++ b/client/src/hooks/useClickOutside.test.jsx@@ -62,6 +62,61 @@ describe('useClickOutside', () => {expect(addSpy.mock.calls.filter(([type]) => type === 'mousedown').length).toBe(subs);});+ // The array form exists for portaled popovers: the panel renders into <body>,+ // so it is not inside the trigger's subtree and a single-ref check would treat+ // every click on the panel as an outside click and close it.+ describe('multiple refs', () => {+ it('treats a click in any of the refs as inside', () => {+ const { inside: trigger, outside } = setupDom();+ const panel = document.createElement('div');+ document.body.append(panel);+ const onOutside = vi.fn();+ renderHook(() => {+ const triggerRef = useRef(trigger);+ const panelRef = useRef(panel);+ useClickOutside([triggerRef, panelRef], true, onOutside);+ });++ fireEvent.mouseDown(trigger);+ fireEvent.mouseDown(panel);+ expect(onOutside).not.toHaveBeenCalled();++ fireEvent.mouseDown(outside);+ expect(onOutside).toHaveBeenCalledTimes(1);+ });++ it('tolerates a ref that has not attached yet', () => {+ const { inside: trigger, outside } = setupDom();+ const onOutside = vi.fn();+ renderHook(() => {+ const triggerRef = useRef(trigger);+ const unattachedRef = useRef(null);+ useClickOutside([triggerRef, unattachedRef], true, onOutside);+ });++ fireEvent.mouseDown(outside);+ expect(onOutside).toHaveBeenCalledTimes(1);+ });++ it('does not resubscribe when the caller passes a fresh array literal each render', () => {+ const { inside: trigger } = setupDom();+ const panel = document.createElement('div');+ document.body.append(panel);+ const addSpy = vi.spyOn(window, 'addEventListener');+ const { rerender } = renderHook(() => {+ const triggerRef = useRef(trigger);+ const panelRef = useRef(panel);+ // A new array every render — the common call-site shape.+ useClickOutside([triggerRef, panelRef], true, vi.fn());+ });++ const subs = addSpy.mock.calls.filter(([type]) => type === 'mousedown').length;+ rerender();+ rerender();+ expect(addSpy.mock.calls.filter(([type]) => type === 'mousedown').length).toBe(subs);+ });+ });+it('detaches the listener on unmount', () => {const { outside } = setupDom();const onOutside = vi.fn();