Skip to content
Shell
5.3 KB
Raw Blame

Plan: Replace Session Page with Full-Page SessionView

Goal

Replace the narrow chat card layout at /session/[id] with the full-page three-panel SessionView that has sidebars for partner understanding.

Current State

  • SessionView (/src/components/session/SessionView.tsx) - Full three-panel design, only used in /session-demo with mock data
  • Conversation (/src/components/session/conversation.tsx) - Simple card layout, currently used in production
  • Session page (/src/app/(app)/session/[id]/page.tsx) - Wraps everything in max-w-3xl mx-auto, uses <Conversation>

Data Structure Gap

SessionView Expects Current Real Data Adapter Needed
participantA.name session.created_by (user ID only) Fetch profile
participantB.name session.invited_user_id (user ID only) Fetch profile
message.sender: 'A' | 'B' message.sender_id (user ID) Map IDs to roles
ParticipantSummary Not stored Derive from NVC extractions
currentState: 'A_SPEAKING' No turn tracking Implement based on last message

Implementation Approach

Phase 1: Create Adapter Hook

File: /src/hooks/use-session-context.ts

Creates a useSessionContext hook that:

  1. Fetches session data + both participant profiles
  2. Transforms DB messages to SessionView message format
  3. Builds ParticipantSummary objects from NVC extractions
  4. Determines current speaker (async mode = alternating turns)
  5. Subscribes to real-time message updates
  6. Returns SessionContext compatible with SessionView

Phase 2: Update Session Page

File: /src/app/(app)/session/[id]/page.tsx

  1. Remove max-w-3xl mx-auto wrapper constraint
  2. Replace <Conversation> with <SessionView> when session is active
  3. Use new useSessionContext hook for data
  4. Keep onboarding/waiting states as-is (they're already full-width)

Phase 3: Wire Up Actions

File: /src/components/session/SessionView.tsx (or adapter)

Connect SessionView's callbacks to real API:

  • onSendMessage → /api/message/process
  • onEndTurn → Update turn state
  • onSessionUpdate → Persist state changes

Files to Create

  • /src/hooks/use-session-context.ts - Adapter hook

Files to Modify

  • /src/app/(app)/session/[id]/page.tsx - Use SessionView
  • /src/components/session/SessionView.tsx - Minor tweaks if needed

Decisions Made

  1. Free-form messaging - Either person can send anytime (no enforced turns)

    • SessionView's turn logic needs adjustment for async mode
    • Input always enabled, show "last spoke" indicator instead of strict turns
  2. Derive summaries from NVC extractions - No new DB tables needed

    • Parse nvc_extraction JSON from latest message per user
    • Build ParticipantSummary dynamically
  3. Placeholder text for empty states - "Their thoughts will appear as they share"


Detailed Implementation Steps

Step 1: Create useSessionContext Hook

File: /src/hooks/use-session-context.ts

// Returns SessionContext compatible with SessionView
// - Fetches session + profiles for both participants
// - Transforms messages: sender_id → 'A' | 'B'
// - Builds summaries from latest NVC extractions
// - Subscribes to real-time updates
// - Handles free-form mode (always canSpeak = true)

Key functions:

  • fetchSessionWithProfiles(sessionId) - Get session + joined profile data
  • transformMessages(dbMessages, creatorId) - Map sender_id to 'A'/'B'
  • buildSummary(messages, participantId) - Extract latest NVC as summary
  • Real-time subscription for new messages

Step 2: Modify SessionView for Free-Form Mode

File: /src/components/session/SessionView.tsx

Changes needed:

  • Add mode: 'async' | 'sync' prop (default: 'async')
  • In async mode: canSpeak() always returns true
  • In async mode: Don't show "waiting for partner" in input area
  • Show "Last message from [Name]" instead of turn indicator

Step 3: Update Session Page

File: /src/app/(app)/session/[id]/page.tsx

  1. Remove the max-w-3xl mx-auto wrapper for active sessions
  2. Import and use useSessionContext hook
  3. Replace <Conversation> with <SessionView> when session.status === 'active'
  4. Keep existing onboarding/waiting UI unchanged (already full-width)

Step 4: Connect API Actions

In the session page or adapter:

  • Wire onSendMessage → existing /api/message/process flow
  • Wire onConfirm/onAdjust → existing /api/message/confirm flow
  • Handle reflection display state (may need to integrate with SessionView)

File Changes Summary

File Action Changes
/src/hooks/use-session-context.ts CREATE New adapter hook
/src/components/session/SessionView.tsx MODIFY Add async mode support
/src/app/(app)/session/[id]/page.tsx MODIFY Use SessionView, remove narrow wrapper

Risk Areas

  1. Reflection flow integration - SessionView doesn't have reflection/confirm UI built in

    • May need to add reflection state to SessionView
    • Or layer ReflectionDisplay component over SessionView
  2. Real-time sync - Need to ensure messages update correctly for both users

    • Test with two browser windows
  3. Mobile responsiveness - SessionView has mobile layout, verify it works with real data