From 6e8a9d2f0dde144666bbe4dc7cbf8ef59dc38e45 Mon Sep 17 00:00:00 2001 From: william Date: Sat, 31 Oct 2026 22:39:04 +0100 Subject: [PATCH] feat(ui): separate chat and pipeline stepper, move stepper beside the avatar Per user feedback after visually testing the app: the chat and the pipeline stepper were a single combined panel, which the user wanted split. Rename SessionPanel to ChatPanel (chat history + objective validation + input bar only, no stepper), rendered only while a new chatOpen flag is true - toggled via the context menu's "Ecrire un message" item, not shown automatically on login. The PipelineStepper now lives directly in App.tsx and only mounts once useSessionStore.sessionId is set (i.e. the user has actually started a training session, not just logged in). It's anchored to the right edge of the window, vertically centered, instead of stacked above the avatar: the window itself grows from 420 to 620px wide via the new set-pipeline-panel-visible IPC call whenever a session becomes active, and shrinks back when it doesn't. A new .avatar-stage wrapper keeps the avatar/chat panel's own layout anchored to a fixed 420px column so it doesn't re-center across the wider window. Co-Authored-By: Claude Sonnet 5 --- Max Avatar/src/renderer/src/App.tsx | 83 +++++++++++-- .../{SessionPanel.tsx => ChatPanel.tsx} | 23 ++-- Max Avatar/src/renderer/src/styles/app.css | 104 ++++++++++++++--- Max Avatar/tests/unit/components/App.test.tsx | 110 +++++++++++++++--- ...ssionPanel.test.tsx => ChatPanel.test.tsx} | 16 +-- 5 files changed, 272 insertions(+), 64 deletions(-) rename Max Avatar/src/renderer/src/components/{SessionPanel.tsx => ChatPanel.tsx} (64%) rename Max Avatar/tests/unit/components/{SessionPanel.test.tsx => ChatPanel.test.tsx} (85%) diff --git a/Max Avatar/src/renderer/src/App.tsx b/Max Avatar/src/renderer/src/App.tsx index 5caa4fc..3fbe4cc 100644 --- a/Max Avatar/src/renderer/src/App.tsx +++ b/Max Avatar/src/renderer/src/App.tsx @@ -1,10 +1,14 @@ import { useCallback, useEffect, useRef, useState } from 'react' import AvatarViewer, { type AvatarHandle } from './components/AvatarViewer' import AvatarStatusIndicator from './components/AvatarStatusIndicator' +import ChatPanel from './components/ChatPanel' +import ContextMenu from './components/ContextMenu' +import PipelineStepper from './components/PipelineStepper' import ThinkingIndicator from './components/ThinkingIndicator' import VoiceErrorBanner from './components/VoiceErrorBanner' import UpdateBanner from './components/UpdateBanner' -import SessionPanel from './components/SessionPanel' +import { useSessionStore } from './stores/useSessionStore' +import { deriveStepsFromStatus } from './utils/pipelineSteps' import { useVoiceAssistant, type VoiceState } from './voice/useVoiceAssistant' import { useProactiveSpeech } from './voice/useProactiveSpeech' @@ -15,9 +19,15 @@ function App(): React.JSX.Element { const [listening, setListening] = useState(false) const listeningRef = useRef(listening) const [loggedIn, setLoggedIn] = useState(false) + const [email, setEmail] = useState(null) + const [chatOpen, setChatOpen] = useState(false) + const [contextMenu, setContextMenu] = useState<{ x: number; y: number } | null>(null) const [voiceState, setVoiceState] = useState('idle') const [voiceError, setVoiceError] = useState(null) const [updateStatus, setUpdateStatus] = useState<'available' | 'ready' | null>(null) + const sessionId = useSessionStore((state) => state.sessionId) + const sessionStatus = useSessionStore((state) => state.status) + const restartSession = useSessionStore((state) => state.restart) useEffect(() => window.api.onUpdateAvailable(() => setUpdateStatus('available')), []) useEffect(() => window.api.onUpdateReady(() => setUpdateStatus('ready')), []) const voiceErrorTimer = useRef | null>(null) @@ -47,10 +57,12 @@ function App(): React.JSX.Element { .then((status) => { setListening(status.loggedIn) setLoggedIn(status.loggedIn) + setEmail(status.email) }) .catch(() => { setListening(false) setLoggedIn(false) + setEmail(null) }) }, []) useEffect(refreshAuthStatus, [refreshAuthStatus]) @@ -60,10 +72,38 @@ function App(): React.JSX.Element { useEffect(() => window.api.onToggleListening(refreshAuthStatus), [refreshAuthStatus]) useEffect(() => window.api.onProactiveSpeech(() => setVoiceState('speaking')), []) + // Le stepper n'apparait que lorsqu'une session existe reellement (l'utilisateur a mentionne + // vouloir apprendre quelque chose, pas juste parce qu'il est connecte) : voir useSessionStore, + // sessionId n'est jamais non-null avant le premier POST /sessions reussi. La fenetre s'elargit a + // droite pour lui faire de la place (set-pipeline-panel-visible, voir src/main/index.ts). + useEffect(() => { + window.api.setPipelinePanelVisible(sessionId !== null) + }, [sessionId]) + + // Ouvre automatiquement le panneau de chat des qu'une session demarre (garde-fou : en usage + // normal, c'est l'ouverture du chat via le menu contextuel qui permet d'envoyer le premier + // message qui cree la session, donc le chat est deja ouvert a ce moment-la). + const previousSessionId = useRef(null) + useEffect(() => { + if (previousSessionId.current === null && sessionId !== null) setChatOpen(true) + previousSessionId.current = sessionId + }, [sessionId]) + const onContextMenu = useCallback((event: React.MouseEvent) => { event.preventDefault() - window.api.showContextMenu(listeningRef.current) + setContextMenu({ x: event.clientX, y: event.clientY }) }, []) + const closeContextMenu = useCallback(() => setContextMenu(null), []) + const handleLogin = useCallback(() => window.api.openLoginWindow(), []) + const handleLogout = useCallback(() => { + window.api.logout() + setChatOpen(false) + restartSession() + }, [restartSession]) + const handleToggleListening = useCallback(() => setListening((prev) => !prev), []) + const handleToggleChat = useCallback(() => setChatOpen((prev) => !prev), []) + const handleQuit = useCallback(() => window.api.quitApp(), []) + const dragState = useRef<{ startMouseX: number startMouseY: number @@ -125,12 +165,12 @@ function App(): React.JSX.Element { onMouseDown={handleMouseDown} onContextMenu={onContextMenu} > - - {voiceState === 'processing' && } - {voiceError && voiceState !== 'processing' && } - {updateStatus && } - {loggedIn && ( - <> +
+ + {voiceState === 'processing' && } + {voiceError && voiceState !== 'processing' && } + {updateStatus && } + {loggedIn && (
- - + )} + {loggedIn && chatOpen && } +
+ + {sessionId !== null && ( +
+ +
+ )} + + {contextMenu && ( + )} ) diff --git a/Max Avatar/src/renderer/src/components/SessionPanel.tsx b/Max Avatar/src/renderer/src/components/ChatPanel.tsx similarity index 64% rename from Max Avatar/src/renderer/src/components/SessionPanel.tsx rename to Max Avatar/src/renderer/src/components/ChatPanel.tsx index 64c88f9..fe26414 100644 --- a/Max Avatar/src/renderer/src/components/SessionPanel.tsx +++ b/Max Avatar/src/renderer/src/components/ChatPanel.tsx @@ -1,19 +1,17 @@ import { useEffect, useRef } from 'react' import { useSessionStore } from '../stores/useSessionStore' -import { deriveStepsFromStatus } from '../utils/pipelineSteps' import ChatBubble from './ChatBubble' import InputBar from './InputBar' import ObjectiveValidationCard from './ObjectiveValidationCard' -import PipelineStepper from './PipelineStepper' /** - * Panneau flottant de la session de formation (docs/Max_Composants_Frontend.md section 4) : - * stepper + conversation + carte de validation de l'objectif + barre de saisie. N'affiche jamais - * un statut calcule localement (voir utils/pipelineSteps.ts et la regle de PipelineStepper). + * Panneau de conversation (docs/Max_Composants_Frontend.md section 4) : historique de messages + + * carte de validation de l'objectif + barre de saisie. Separe du PipelineStepper (rendu a cote de + * l'avatar par App.tsx, pas ici) - voir le retour utilisateur qui demandait cette separation. + * N'affiche jamais un statut calcule localement. */ -export default function SessionPanel(): React.JSX.Element { +export default function ChatPanel(): React.JSX.Element { const { - status, messages, objectiveDraft, objectiveReady, @@ -33,16 +31,11 @@ export default function SessionPanel(): React.JSX.Element { } }, [messages]) - const steps = deriveStepsFromStatus(status) const showObjectiveCard = objectiveReady && objectiveDraft !== null && !objectiveConfirmed return ( -
-
- -
- -
+
+
{messages.map((message) => ( - {error &&

{error}

} + {error &&

{error}

} {showObjectiveCard && objectiveDraft ? ( ({ default: ({ onReady }: { onReady: (handle: unknown) => void }) => { @@ -29,9 +30,14 @@ vi.mock('../../../src/renderer/src/voice/useProactiveSpeech', () => ({ let onUpdateAvailableCb: (() => void) | undefined let onUpdateReadyCb: (() => void) | undefined -const showContextMenu = vi.fn() const getWindowBounds = vi.fn(async () => ({ x: 0, y: 0, width: 100, height: 100 })) const setWindowPosition = vi.fn() +const openLoginWindow = vi.fn() +const logout = vi.fn() +const quitApp = vi.fn() +const setPipelinePanelVisible = vi.fn() +const sessionsCreate = vi.fn() +const sessionsSendObjectiveMessage = vi.fn() const getAuthStatus = vi.fn(async (): Promise<{ loggedIn: boolean; email: string | null }> => ({ loggedIn: false, email: null @@ -49,10 +55,19 @@ function setupWindowApi(): void { }), onToggleListening: vi.fn(() => () => {}), onProactiveSpeech: vi.fn(() => () => {}), - showContextMenu, getWindowBounds, setWindowPosition, - getAuthStatus + getAuthStatus, + openLoginWindow, + logout, + quitApp, + setPipelinePanelVisible, + sessions: { + create: sessionsCreate, + get: vi.fn(), + sendObjectiveMessage: sessionsSendObjectiveMessage, + confirmObjective: vi.fn() + } } } @@ -62,6 +77,7 @@ describe('', () => { beforeEach(() => { vi.clearAllMocks() setupWindowApi() + useSessionStore.getState().restart() }) it('should render the avatar viewer', () => { @@ -103,24 +119,37 @@ describe('', () => { expect(screen.getByText(/prochaine fermeture/)).toBeInTheDocument() }) - it('should request the context menu with the current listening state', () => { - // Faux par defaut (ecoute non activee tant qu'aucun compte n'est connecte, voir - // getAuthStatus ci-dessus qui renvoie loggedIn: false). + it('should open the custom context menu on right-click', () => { + render() + const container = screen.getByTestId('avatar-viewer').parentElement! + fireEvent.contextMenu(container, { clientX: 20, clientY: 30 }) + expect(screen.getByRole('menu')).toBeInTheDocument() + }) + + it('should call openLoginWindow when "Me connecter" is clicked from the menu', () => { render() const container = screen.getByTestId('avatar-viewer').parentElement! fireEvent.contextMenu(container) - expect(showContextMenu).toHaveBeenCalledWith(false) + fireEvent.click(screen.getByRole('menuitem', { name: 'Me connecter' })) + expect(openLoginWindow).toHaveBeenCalled() }) - it('should enable listening once getAuthStatus reports an existing session', async () => { - getAuthStatus.mockResolvedValueOnce({ loggedIn: true, email: 'william@example.com' }) + it('should call logout and reset the session when "Se deconnecter" is clicked', async () => { + getAuthStatus.mockResolvedValue({ loggedIn: true, email: 'william@example.com' }) + render() + await waitFor(() => expect(getAuthStatus).toHaveBeenCalled()) + const container = screen.getByTestId('avatar-viewer').parentElement! + fireEvent.contextMenu(container) + fireEvent.click(screen.getByRole('menuitem', { name: 'Se deconnecter' })) + expect(logout).toHaveBeenCalled() + }) + + it('should call quitApp when "Quitter" is clicked', () => { render() const container = screen.getByTestId('avatar-viewer').parentElement! - - await waitFor(() => { - fireEvent.contextMenu(container) - expect(showContextMenu).toHaveBeenCalledWith(true) - }) + fireEvent.contextMenu(container) + fireEvent.click(screen.getByRole('menuitem', { name: 'Quitter' })) + expect(quitApp).toHaveBeenCalled() }) it('should start dragging the window on mouse down and stop on mouse up', async () => { @@ -146,15 +175,64 @@ describe('', () => { expect(getWindowBounds).not.toHaveBeenCalled() }) - it('should not show the session panel when logged out', async () => { + it('should not show the chat panel when logged out', async () => { render() await waitFor(() => expect(getAuthStatus).toHaveBeenCalled()) expect(screen.queryByLabelText('Message')).not.toBeInTheDocument() }) - it('should show the session panel input once logged in', async () => { + it('should not show the chat panel right after login, until "Ecrire un message" is used', async () => { getAuthStatus.mockResolvedValue({ loggedIn: true, email: 'william@example.com' }) render() + await waitFor(() => expect(getAuthStatus).toHaveBeenCalled()) + expect(screen.queryByLabelText('Message')).not.toBeInTheDocument() + }) + + it('should open the chat panel via the context menu and shrink the pipeline panel back on toggle off', async () => { + getAuthStatus.mockResolvedValue({ loggedIn: true, email: 'william@example.com' }) + render() + await waitFor(() => expect(getAuthStatus).toHaveBeenCalled()) + + const container = screen.getByTestId('avatar-viewer').parentElement! + fireEvent.contextMenu(container) + fireEvent.click(screen.getByRole('menuitem', { name: 'Ecrire un message' })) + expect(await screen.findByLabelText('Message')).toBeInTheDocument() + + fireEvent.contextMenu(container) + fireEvent.click(screen.getByRole('menuitem', { name: 'Ecrire un message' })) + expect(screen.queryByLabelText('Message')).not.toBeInTheDocument() + }) + + it('should not show the pipeline stepper before a session exists', async () => { + getAuthStatus.mockResolvedValue({ loggedIn: true, email: 'william@example.com' }) + render() + await waitFor(() => expect(getAuthStatus).toHaveBeenCalled()) + expect(screen.queryByText('Objectif')).not.toBeInTheDocument() + expect(setPipelinePanelVisible).toHaveBeenCalledWith(false) + }) + + it('should show the pipeline stepper and widen the window once a session is created', async () => { + getAuthStatus.mockResolvedValue({ loggedIn: true, email: 'william@example.com' }) + sessionsCreate.mockResolvedValueOnce({ id: 1, status: 'objective_discovery' }) + sessionsSendObjectiveMessage.mockResolvedValueOnce({ + reply: 'Quel est ton sujet ?', + ready: false + }) + + render() + await waitFor(() => expect(getAuthStatus).toHaveBeenCalled()) + + const container = screen.getByTestId('avatar-viewer').parentElement! + fireEvent.contextMenu(container) + fireEvent.click(screen.getByRole('menuitem', { name: 'Ecrire un message' })) + + fireEvent.change(await screen.findByLabelText('Message'), { + target: { value: 'Je veux apprendre' } + }) + fireEvent.click(screen.getByRole('button', { name: 'Envoyer le message' })) + + await waitFor(() => expect(screen.getByText('Objectif')).toBeInTheDocument()) + expect(setPipelinePanelVisible).toHaveBeenCalledWith(true) }) }) diff --git a/Max Avatar/tests/unit/components/SessionPanel.test.tsx b/Max Avatar/tests/unit/components/ChatPanel.test.tsx similarity index 85% rename from Max Avatar/tests/unit/components/SessionPanel.test.tsx rename to Max Avatar/tests/unit/components/ChatPanel.test.tsx index 2b6f391..6a0835f 100644 --- a/Max Avatar/tests/unit/components/SessionPanel.test.tsx +++ b/Max Avatar/tests/unit/components/ChatPanel.test.tsx @@ -1,6 +1,6 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' import { render, screen, fireEvent, waitFor } from '@testing-library/react' -import SessionPanel from '../../../src/renderer/src/components/SessionPanel' +import ChatPanel from '../../../src/renderer/src/components/ChatPanel' import { useSessionStore } from '../../../src/renderer/src/stores/useSessionStore' const create = vi.fn() @@ -16,18 +16,18 @@ beforeEach(() => { useSessionStore.getState().restart() }) -describe('', () => { - it('should show the pending pipeline steps and an input bar before any session exists', () => { - render() +describe('', () => { + it('should show an input bar and no pipeline steps before any session exists', () => { + render() expect(screen.getByLabelText('Message')).toBeInTheDocument() - expect(screen.getByText('Objectif')).toBeInTheDocument() + expect(screen.queryByText('Objectif')).not.toBeInTheDocument() }) it('should send the first message, creating a session, and render the conversation', async () => { create.mockResolvedValueOnce({ id: 1, status: 'objective_discovery' }) sendObjectiveMessage.mockResolvedValueOnce({ reply: 'Quel est ton sujet ?', ready: false }) - render() + render() fireEvent.change(screen.getByLabelText('Message'), { target: { value: 'Je veux apprendre' } }) fireEvent.click(screen.getByRole('button', { name: 'Envoyer le message' })) @@ -43,7 +43,7 @@ describe('', () => { draft: { subject: 's', professionalGoal: 'g', duration: '1 semaine' } }) - render() + render() fireEvent.change(screen.getByLabelText('Message'), { target: { value: 'message' } }) fireEvent.click(screen.getByRole('button', { name: 'Envoyer le message' })) @@ -54,7 +54,7 @@ describe('', () => { it('should show the store error message when a call fails', async () => { create.mockRejectedValueOnce(new Error('Max API injoignable')) - render() + render() fireEvent.change(screen.getByLabelText('Message'), { target: { value: 'message' } }) fireEvent.click(screen.getByRole('button', { name: 'Envoyer le message' }))