diff --git a/.planning/codebase/CHAT_REACT_PATTERNS.md b/.planning/codebase/CHAT_REACT_PATTERNS.md new file mode 100644 index 000000000..66e80d008 --- /dev/null +++ b/.planning/codebase/CHAT_REACT_PATTERNS.md @@ -0,0 +1,1255 @@ +# React Patterns for Session Chat in jam-ui + +**Purpose:** Document available React patterns in jam-ui, identify what can be reused for session chat, and highlight gaps. + +**Date:** 2026-01-26 +**Phase:** 06-session-chat-research-design +**Plan:** 01 + +--- + +## Overview + +This document analyzes existing jam-ui patterns from Phases 2-5 to identify: +- โœ… **What's Available** - Components, patterns, hooks we can reuse +- โŒ **What's Missing** - Gaps that need to be filled for session chat +- ๐Ÿงช **TDD Candidates** - What should follow Test-Driven Development + +--- + +## Available Components + +### 1. WindowPortal (Modeless Dialog) + +**File:** `/jam-ui/src/components/common/WindowPortal.js` + +**Purpose:** Creates a popup window for modeless dialogs (used by Metronome, JamTrack player) + +**Features:** +- โœ… Opens new browser window with custom dimensions +- โœ… Copies all stylesheets from parent to popup +- โœ… Auto-detects window close and triggers callback +- โœ… Cross-window message passing (`postMessage` API) +- โœ… Auto-cleanup on parent window close +- โœ… Window ID tracking for multi-instance support + +**Props:** +```javascript +{ + children: ReactNode, + onClose: () => void, + windowFeatures: string, // "width=400,height=300,left=200,top=200,..." + title: string, + onWindowReady: (window, sendMessage) => void, + onWindowMessage: (data) => void, + windowId: string +} +``` + +**Example Usage (from JKSessionMetronomePlayer):** +```javascript +{isWindowOpen && ( + setIsWindowOpen(false)} + windowId="metronome-controls" + > +
+ {/* Metronome controls */} +
+
+)} +``` + +**Reuse for Chat:** +- โœ… Perfect for expanded chat dialog +- โœ… No modifications needed +- โœ… Already handles styling, lifecycle, cleanup +- **Recommendation:** Use as-is for Phase 8 (expanded chat window) + +--- + +### 2. JKModal / Dialog Patterns + +**Status:** โŒ NOT FOUND in jam-ui codebase + +**Legacy Pattern (web app):** +- Uses custom layout system: `layout='dialog'`, `layout-id='chat-dialog'` +- Controlled via `@app.layout.showDialog()`, `closeDialog()` + +**Gap:** +- jam-ui doesn't have equivalent modal/dialog component +- WindowPortal is used instead for modeless dialogs +- For modal-style dialogs, would need to create new component + +**Recommendation:** +- For session chat, use WindowPortal (matches legacy behavior) +- If modal dialog needed later, create `JKModal.js` component (Phase 11) + +--- + +### 3. Button Components + +**Files:** Various throughout jam-ui (not centralized yet) + +**Existing Patterns:** +```javascript +// Orange button (primary action) + + +// Grey button (secondary action) + + +// Icon buttons + +``` + +**Reuse for Chat:** +- โœ… Use existing button classes +- โœ… No custom button component needed for MVP +- **Recommendation:** Reuse CSS classes from legacy (already styled) + +--- + +### 4. Input Components + +**Files:** Various throughout jam-ui + +**Existing Patterns:** +```javascript +// Textarea +