feat(pipeline): add InputBar, ChatBubble, AvatarStatusIndicator, PipelineStepper and ObjectiveValidationCard
Shell and Agent 1 UI components per docs/Max_Composants_Frontend.md: - InputBar: send on Enter, newline on Shift+Enter, mic toggle (STT itself stays in the main process). - ChatBubble: max/user variants reusing the existing chat-bubble design-system classes, simple Markdown via react-markdown+remark-gfm. - AvatarStatusIndicator: purely visual, no status computed here. - PipelineStepper + utils/pipelineSteps.ts: the stepper itself only renders the `steps` prop as given (never computes status); the session.status -> step list derivation lives in a separate pure function the store/App call, per the doc's explicit rule that the component must never calculate status itself. - ObjectiveValidationCard: single-field-at-a-time editing, locked and irreversible once onConfirm resolves. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
ed32c21f24
commit
309db80add
@@ -0,0 +1,40 @@
|
||||
export type AvatarStatus = 'idle' | 'thinking' | 'speaking' | 'waiting'
|
||||
|
||||
export interface AvatarStatusIndicatorProps {
|
||||
status: AvatarStatus
|
||||
label?: string
|
||||
}
|
||||
|
||||
const DEFAULT_LABELS = new Map<AvatarStatus, string>([
|
||||
['thinking', 'Max reflechit...'],
|
||||
['speaking', 'Max parle...'],
|
||||
['waiting', 'En attente']
|
||||
])
|
||||
|
||||
/**
|
||||
* Badge d'etat sous l'avatar (docs/Max_Composants_Frontend.md section 2). Purement visuel : pas
|
||||
* d'appel API, aucune logique de calcul d'etat ici (le statut vient toujours du parent).
|
||||
*/
|
||||
export default function AvatarStatusIndicator({
|
||||
status,
|
||||
label
|
||||
}: AvatarStatusIndicatorProps): React.JSX.Element | null {
|
||||
if (status === 'idle') return null
|
||||
|
||||
const text = label ?? DEFAULT_LABELS.get(status) ?? ''
|
||||
|
||||
return (
|
||||
<div className="avatar-status" role="status">
|
||||
{status === 'waiting' ? (
|
||||
<span className="avatar-status__dot avatar-status__dot--waiting" />
|
||||
) : (
|
||||
<span className="avatar-status__dots">
|
||||
<span className="avatar-status__dot" style={{ animationDelay: '0s' }} />
|
||||
<span className="avatar-status__dot" style={{ animationDelay: '0.2s' }} />
|
||||
<span className="avatar-status__dot" style={{ animationDelay: '0.4s' }} />
|
||||
</span>
|
||||
)}
|
||||
<span className="avatar-status__label">{text}</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import ReactMarkdown from 'react-markdown'
|
||||
import remarkGfm from 'remark-gfm'
|
||||
|
||||
export interface ChatBubbleProps {
|
||||
role: 'max' | 'user'
|
||||
content: string
|
||||
timestamp?: Date
|
||||
}
|
||||
|
||||
/** Bulle de message de la zone de conversation (docs/Max_Composants_Frontend.md section 4). */
|
||||
export default function ChatBubble({
|
||||
role,
|
||||
content,
|
||||
timestamp
|
||||
}: ChatBubbleProps): React.JSX.Element {
|
||||
return (
|
||||
<div className={`chat-bubble chat-bubble--${role}`}>
|
||||
<ReactMarkdown remarkPlugins={[remarkGfm]}>{content}</ReactMarkdown>
|
||||
{timestamp && (
|
||||
<time className="chat-bubble__time" dateTime={timestamp.toISOString()}>
|
||||
{timestamp.toLocaleTimeString('fr-FR', { hour: '2-digit', minute: '2-digit' })}
|
||||
</time>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import { useState } from 'react'
|
||||
import { Mic, Send } from 'lucide-react'
|
||||
|
||||
export interface InputBarProps {
|
||||
placeholder?: string
|
||||
disabled?: boolean
|
||||
onSend: (text: string) => void
|
||||
onVoiceStart?: () => void
|
||||
onVoiceStop?: () => void
|
||||
}
|
||||
|
||||
/**
|
||||
* Barre de saisie du shell permanent (docs/Max_Composants_Frontend.md section 2). La
|
||||
* reconnaissance vocale elle-meme vit dans le main process : ce composant se contente d'appeler
|
||||
* onVoiceStart/onVoiceStop et de refleter l'etat "recording" qu'on lui donne en retour via le
|
||||
* parent (pas de logique STT ici).
|
||||
*/
|
||||
export default function InputBar({
|
||||
placeholder,
|
||||
disabled = false,
|
||||
onSend,
|
||||
onVoiceStart,
|
||||
onVoiceStop
|
||||
}: InputBarProps): React.JSX.Element {
|
||||
const [text, setText] = useState('')
|
||||
const [recording, setRecording] = useState(false)
|
||||
|
||||
const send = (): void => {
|
||||
const trimmed = text.trim()
|
||||
if (trimmed.length === 0 || disabled) return
|
||||
onSend(trimmed)
|
||||
setText('')
|
||||
}
|
||||
|
||||
const onKeyDown = (event: React.KeyboardEvent<HTMLInputElement>): void => {
|
||||
if (event.key === 'Enter' && !event.shiftKey) {
|
||||
event.preventDefault()
|
||||
send()
|
||||
}
|
||||
}
|
||||
|
||||
const toggleVoice = (): void => {
|
||||
if (recording) {
|
||||
onVoiceStop?.()
|
||||
} else {
|
||||
onVoiceStart?.()
|
||||
}
|
||||
setRecording((prev) => !prev)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="input-bar">
|
||||
<input
|
||||
type="text"
|
||||
value={text}
|
||||
onChange={(e) => setText(e.target.value)}
|
||||
onKeyDown={onKeyDown}
|
||||
placeholder={placeholder}
|
||||
disabled={disabled}
|
||||
aria-label="Message"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
className={`input-bar__btn${recording ? ' input-bar__btn--recording' : ''}`}
|
||||
aria-label={recording ? "Arreter l'enregistrement vocal" : 'Activer le microphone'}
|
||||
onClick={toggleVoice}
|
||||
disabled={disabled}
|
||||
>
|
||||
<Mic size={14} />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="input-bar__send"
|
||||
aria-label="Envoyer le message"
|
||||
onClick={send}
|
||||
disabled={disabled || text.trim().length === 0}
|
||||
>
|
||||
<Send size={14} />
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
import { useState } from 'react'
|
||||
import { Check, Pencil, Target } from 'lucide-react'
|
||||
|
||||
export interface ObjectiveData {
|
||||
subject: string
|
||||
professionalGoal: string
|
||||
duration: string
|
||||
}
|
||||
|
||||
export interface ObjectiveValidationCardProps {
|
||||
objective: ObjectiveData
|
||||
onConfirm: (objective: ObjectiveData) => Promise<void>
|
||||
onRestart: () => void
|
||||
}
|
||||
|
||||
type FieldKey = keyof ObjectiveData
|
||||
|
||||
const FIELD_LABELS: { key: FieldKey; label: string }[] = [
|
||||
{ key: 'subject', label: 'Sujet' },
|
||||
{ key: 'professionalGoal', label: 'But professionnel' },
|
||||
{ key: 'duration', label: 'Duree' }
|
||||
]
|
||||
|
||||
/**
|
||||
* Carte de validation de l'objectif issu de l'Agent 1 (docs/Max_Composants_Frontend.md section
|
||||
* 4). Une seule ligne editable a la fois ; une fois confirmee, l'objectif est verrouille pour le
|
||||
* reste de la session (etat `confirmed` irreversible).
|
||||
*/
|
||||
export default function ObjectiveValidationCard({
|
||||
objective,
|
||||
onConfirm,
|
||||
onRestart
|
||||
}: ObjectiveValidationCardProps): React.JSX.Element {
|
||||
const [draft, setDraft] = useState<ObjectiveData>(objective)
|
||||
const [editingField, setEditingField] = useState<FieldKey | null>(null)
|
||||
const [confirmed, setConfirmed] = useState(false)
|
||||
const [confirming, setConfirming] = useState(false)
|
||||
|
||||
const updateField = (key: FieldKey, value: string): void => {
|
||||
if (key === 'subject') setDraft((prev) => ({ ...prev, subject: value }))
|
||||
else if (key === 'professionalGoal') setDraft((prev) => ({ ...prev, professionalGoal: value }))
|
||||
else setDraft((prev) => ({ ...prev, duration: value }))
|
||||
}
|
||||
|
||||
const startEditing = (key: FieldKey): void => {
|
||||
if (confirmed) return
|
||||
setEditingField(key)
|
||||
}
|
||||
|
||||
const closeEditing = (): void => {
|
||||
setEditingField(null)
|
||||
}
|
||||
|
||||
const confirm = (): void => {
|
||||
if (editingField !== null) return
|
||||
setConfirming(true)
|
||||
void onConfirm(draft).then(() => {
|
||||
setConfirming(false)
|
||||
setConfirmed(true)
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="module-panel objective-card">
|
||||
<div className="module-panel__header objective-card__header">
|
||||
<Target size={16} aria-hidden="true" />
|
||||
<span className="module-panel__title">Ton objectif de formation</span>
|
||||
</div>
|
||||
|
||||
<div className="module-panel__body">
|
||||
{FIELD_LABELS.map(({ key, label }) => {
|
||||
const value: string = Reflect.get(draft, key)
|
||||
return (
|
||||
<div key={key} className="objective-card__row">
|
||||
<span className="objective-card__row-label">{label}</span>
|
||||
{editingField === key ? (
|
||||
<input
|
||||
type="text"
|
||||
className="auth-field__input"
|
||||
value={value}
|
||||
aria-label={label}
|
||||
autoFocus
|
||||
onChange={(e) => updateField(key, e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') closeEditing()
|
||||
}}
|
||||
onBlur={closeEditing}
|
||||
/>
|
||||
) : (
|
||||
<span className="objective-card__row-value">{value}</span>
|
||||
)}
|
||||
{!confirmed && (
|
||||
<button
|
||||
type="button"
|
||||
className="objective-card__edit-btn"
|
||||
aria-label={editingField === key ? `Valider ${label}` : `Modifier ${label}`}
|
||||
onClick={() => (editingField === key ? closeEditing() : startEditing(key))}
|
||||
disabled={editingField === key && value.trim().length === 0}
|
||||
>
|
||||
{editingField === key ? <Check size={14} /> : <Pencil size={14} />}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
|
||||
{confirmed ? (
|
||||
<p className="objective-card__confirmed">
|
||||
<Check size={14} aria-hidden="true" /> Objectif enregistre — Max passe a la cartographie
|
||||
</p>
|
||||
) : (
|
||||
<div className="objective-card__actions">
|
||||
<button
|
||||
type="button"
|
||||
className="auth-panel__submit"
|
||||
aria-label="C'est exactement ca, confirmer l'objectif"
|
||||
onClick={confirm}
|
||||
disabled={editingField !== null || confirming}
|
||||
>
|
||||
{confirming ? 'Confirmation...' : "C'est exactement ca ✓"}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="objective-card__restart"
|
||||
aria-label="Recommencer depuis le debut"
|
||||
onClick={onRestart}
|
||||
disabled={confirming}
|
||||
>
|
||||
Recommencer depuis le debut
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
export type StepStatus = 'done' | 'active' | 'pending'
|
||||
|
||||
export interface PipelineStep {
|
||||
id: number
|
||||
label: string
|
||||
subLabel?: string
|
||||
status: StepStatus
|
||||
}
|
||||
|
||||
export interface PipelineStepperProps {
|
||||
steps: PipelineStep[]
|
||||
}
|
||||
|
||||
/**
|
||||
* Liste verticale des 7 etapes du pipeline (docs/Max_Composants_Frontend.md section 4). Purement
|
||||
* affichage : le statut de chaque etape vient du store Zustand qui lit session.status depuis
|
||||
* l'API (voir src/renderer/src/stores/useSessionStore.ts et utils/pipelineSteps.ts) - ce composant
|
||||
* ne calcule jamais lui-meme un statut, il se contente de rendre les props telles quelles.
|
||||
*/
|
||||
export default function PipelineStepper({ steps }: PipelineStepperProps): React.JSX.Element {
|
||||
return (
|
||||
<ol className="pipeline-stepper">
|
||||
{steps.map((step) => (
|
||||
<li key={step.id} className={`step step--${step.status}`}>
|
||||
<span className="step__num">{step.status === 'done' ? '✓' : step.id}</span>
|
||||
<span className="step__texts">
|
||||
<span className="step__label">{step.label}</span>
|
||||
{step.status === 'active' && step.subLabel && (
|
||||
<span className="step__sublabel">{step.subLabel}</span>
|
||||
)}
|
||||
</span>
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
)
|
||||
}
|
||||
@@ -52,6 +52,53 @@
|
||||
}
|
||||
}
|
||||
|
||||
/* ── Badge d'etat sous l'avatar ── */
|
||||
|
||||
.avatar-status {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
padding: 3px var(--space-3);
|
||||
border-radius: var(--radius-full);
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.avatar-status__label {
|
||||
font-family: var(--font-sans);
|
||||
font-size: var(--text-xs);
|
||||
color: var(--text-2);
|
||||
}
|
||||
|
||||
.avatar-status__dots {
|
||||
display: flex;
|
||||
gap: 3px;
|
||||
}
|
||||
|
||||
.avatar-status__dot {
|
||||
width: 5px;
|
||||
height: 5px;
|
||||
border-radius: 50%;
|
||||
background: var(--accent);
|
||||
animation: avatar-status-pulse 1s infinite ease-in-out;
|
||||
}
|
||||
|
||||
.avatar-status__dot--waiting {
|
||||
background: var(--green);
|
||||
animation: none;
|
||||
}
|
||||
|
||||
@keyframes avatar-status-pulse {
|
||||
0%,
|
||||
80%,
|
||||
100% {
|
||||
opacity: 0.3;
|
||||
}
|
||||
40% {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* ── Bannieres flottantes (erreur, mise a jour) ── */
|
||||
|
||||
.banner {
|
||||
@@ -208,3 +255,94 @@
|
||||
cursor: not-allowed;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
/* ── Carte de validation de l'objectif (Agent 1) ── */
|
||||
|
||||
.objective-card__header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.objective-card__row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
padding: var(--space-2) 0;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.objective-card__row-label {
|
||||
width: 120px;
|
||||
flex-shrink: 0;
|
||||
font-size: var(--text-xs);
|
||||
color: var(--text-2);
|
||||
}
|
||||
|
||||
.objective-card__row-value {
|
||||
flex: 1;
|
||||
font-size: var(--text-base);
|
||||
color: var(--text-1);
|
||||
}
|
||||
|
||||
.objective-card__edit-btn {
|
||||
flex-shrink: 0;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border: none;
|
||||
background: none;
|
||||
color: var(--text-2);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.objective-card__edit-btn:hover:not(:disabled) {
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.objective-card__edit-btn:disabled {
|
||||
color: var(--text-3);
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.objective-card__actions {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-2);
|
||||
margin-top: var(--space-4);
|
||||
}
|
||||
|
||||
.objective-card__restart {
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--text-2);
|
||||
font-family: var(--font-sans);
|
||||
font-size: var(--text-sm);
|
||||
cursor: pointer;
|
||||
padding: var(--space-1);
|
||||
}
|
||||
|
||||
.objective-card__restart:hover:not(:disabled) {
|
||||
color: var(--text-1);
|
||||
}
|
||||
|
||||
.objective-card__confirmed {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
margin-top: var(--space-4);
|
||||
color: var(--green);
|
||||
font-size: var(--text-sm);
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.thinking__dot,
|
||||
.avatar-status__dot,
|
||||
.input-bar__btn--recording,
|
||||
.live-dot {
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,29 @@
|
||||
align-self: flex-end;
|
||||
}
|
||||
|
||||
.chat-bubble p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.chat-bubble p + p {
|
||||
margin-top: var(--space-2);
|
||||
}
|
||||
|
||||
.chat-bubble code {
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--text-sm);
|
||||
background: var(--surface-2);
|
||||
padding: 1px 4px;
|
||||
border-radius: var(--radius-sm);
|
||||
}
|
||||
|
||||
.chat-bubble__time {
|
||||
display: block;
|
||||
margin-top: var(--space-1);
|
||||
font-size: var(--text-xs);
|
||||
color: var(--text-2);
|
||||
}
|
||||
|
||||
/* ── Module panel — panneau de cours ── */
|
||||
|
||||
.module-panel {
|
||||
@@ -115,6 +138,25 @@
|
||||
|
||||
/* ── Pipeline stepper — progression session ── */
|
||||
|
||||
.pipeline-stepper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-1);
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.step__texts {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.step__sublabel {
|
||||
font-size: var(--text-xs);
|
||||
color: var(--text-2);
|
||||
}
|
||||
|
||||
.step {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -228,6 +270,12 @@
|
||||
color: var(--text-1);
|
||||
}
|
||||
|
||||
.input-bar__btn--recording {
|
||||
color: var(--red);
|
||||
border-color: var(--red);
|
||||
animation: blink 1.2s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.input-bar__send {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import type { SessionStatus } from '../../../shared/session'
|
||||
import type { PipelineStep } from '../components/PipelineStepper'
|
||||
|
||||
const STEP_LABELS: { status: SessionStatus; label: string }[] = [
|
||||
{ status: 'objective_discovery', label: 'Objectif' },
|
||||
{ status: 'mapping', label: 'Cartographie' },
|
||||
{ status: 'level_assessment', label: 'Niveau' },
|
||||
{ status: 'researching', label: 'Recherche approfondie' },
|
||||
{ status: 'planning', label: 'Plan de formation' },
|
||||
{ status: 'teaching', label: 'Modules' },
|
||||
{ status: 'evaluating', label: 'Evaluation finale' }
|
||||
]
|
||||
|
||||
/**
|
||||
* Derive les 7 etapes du PipelineStepper a partir du session.status reellement renvoye par
|
||||
* l'API - jamais depuis un calcul fait par le composant lui-meme (voir PipelineStepper.tsx).
|
||||
* objective_validated est traite comme "Objectif termine" (l'etape 2 n'a pas encore commence).
|
||||
*/
|
||||
export function deriveStepsFromStatus(status: SessionStatus | null): PipelineStep[] {
|
||||
const effectiveIndex = status === null ? -1 : indexForStatus(status)
|
||||
|
||||
return STEP_LABELS.map((step, index) => {
|
||||
if (effectiveIndex === -1) return { id: index + 1, label: step.label, status: 'pending' }
|
||||
if (index < effectiveIndex) return { id: index + 1, label: step.label, status: 'done' }
|
||||
if (index === effectiveIndex) return { id: index + 1, label: step.label, status: 'active' }
|
||||
return { id: index + 1, label: step.label, status: 'pending' }
|
||||
})
|
||||
}
|
||||
|
||||
function indexForStatus(status: SessionStatus): number {
|
||||
if (status === 'objective_validated') return 1
|
||||
if (status === 'completed') return STEP_LABELS.length
|
||||
const index = STEP_LABELS.findIndex((step) => step.status === status)
|
||||
return index === -1 ? 0 : index
|
||||
}
|
||||
Reference in New Issue
Block a user