import { For, createSignal, createEffect, createMemo, onCleanup } from "solid-js"; import { useEi } from "../context/ei"; import { useKeyboardNav } from "../context/keyboard"; import { RoomMode } from "../../../src/core/types/enums.js"; import type { RoomSummary } from "../../../src/core/types.js"; const modeBadge = (mode: RoomMode): string => { switch (mode) { case RoomMode.ChooseYourPath: return "[CYP]"; case RoomMode.FreeForAll: return "[FFA]"; case RoomMode.MessagesAgainstPersona: return "[MAP]"; default: return ""; } }; export function Sidebar() { const { personas, activePersonaId, rooms, activeRoomId } = useEi(); const { focusedPanel } = useKeyboardNav(); const isFocused = () => focusedPanel() === "sidebar"; const isRoomMode = () => activeRoomId() !== null; // Memoize visible (non-archived) personas for proper reactivity const visiblePersonas = createMemo(() => personas().filter(p => !p.is_archived) ); const visibleRooms = createMemo(() => rooms().filter((r: RoomSummary) => !r.is_archived) ); const [highlightedPersona, setHighlightedPersona] = createSignal(null); let highlightTimer: ReturnType | null = null; createEffect(() => { const currentId = activePersonaId(); if (currentId) { if (highlightTimer) clearTimeout(highlightTimer); setHighlightedPersona(currentId); highlightTimer = setTimeout(() => { setHighlightedPersona(null); highlightTimer = null; }, 500); } }); onCleanup(() => { if (highlightTimer) clearTimeout(highlightTimer); }); return ( {isRoomMode() ? `/p Personas | * Rooms` : `* Personas | /r Rooms`} {(persona) => { const isActive = () => activePersonaId() === persona.id; const displayName = () => persona.display_name || persona.aliases[0] || persona.id; const getLabel = () => { const prefix = isActive() ? "* " : " "; const name = displayName(); const unread = persona.unread_count > 0 ? ` (${persona.unread_count} new)` : ""; const paused = persona.is_paused ? " ⏸" : ""; const reflect = persona.has_pending_update ? " ✦" : ""; return `${prefix}${name}${unread}${paused}${reflect}`; }; const textColor = () => { if (isActive()) return "#eee8d5"; if (persona.is_paused) return "#586e75"; return "#839496"; }; return ( {getLabel()} {persona.short_description ?? ""} ); }} {(room) => { const isActive = () => activeRoomId() === room.id; const getLabel = () => { const prefix = isActive() ? "* " : " "; const name = room.display_name; const badge = modeBadge(room.mode); const unread = room.unread_count > 0 ? ` (${room.unread_count} new)` : ""; return `${prefix}${name} ${badge}${unread}`; }; const textColor = () => { if (isActive()) return "#eee8d5"; return "#839496"; }; return ( {getLabel()} ); }} ); }