veza/apps/web/src/features/player
senke 559cfbee3e refactor(web): zero out 3 ESLint warning buckets (storybook + react-refresh + non-null-assertion)
Three rules cleaned in parallel passes — 187 fewer warnings, 0 TS
errors, 0 behaviour change beyond one incidental auth bugfix
flagged below.

storybook/no-redundant-story-name (23 → 0) — 14 stories files
  Storybook v7+ infers the story name from the variable name, so
  `name: 'Default'` next to `export const Default: Story = …` is
  pure noise. Removed only when the name was redundant ;
  preserved when the label was a French translation
  ('Par défaut', 'Chargement', 'Avec erreur', etc.) since those
  are intentional.

react-refresh/only-export-components (25 → 0) — 21 files
  Each warning marks a file that exports a React component AND a
  hook / context / constant / barrel re-export. Suppressed
  per-line with the suppression-with-justification pattern :
    // eslint-disable-next-line react-refresh/only-export-components -- <kind>; refactor would split a tightly-coupled API
  The justification matters — every comment names the specific
  thing being co-located (hook / context / CVA constant / lazy
  registry / route config / test util / backward-compat barrel).
  Splitting these would create 21 new files for a HMR-only DX
  win that's already a non-issue in practice.

@typescript-eslint/no-non-null-assertion (139 → 0) — 43 files
  Distribution of fixes :
    ~85 cases : refactored to explicit guard
                `if (!x) throw new Error('invariant: …')`
                or hoisted into local with narrowing.
    ~36 cases : helper extraction (one tooltip test had 16
                `wrapper!` patterns reduced to a single
                `getWrapper()` helper).
    ~18 cases : suppressed with specific reason :
                static literal arrays where index is provably
                in bounds, mock fixtures with structural
                guarantees, filter-then-map patterns where the
                filter excludes the null branch.
  One incidental find : services/api/auth.ts threw on missing
  tokens but didn't guard `user` ; added the missing check while
  refactoring the `user!` to a guard.

baseline post-commit : 921 warnings, 0 errors, 0 TS errors.
The remaining buckets are no-restricted-syntax (757, design-system
guardrail), no-explicit-any (115), exhaustive-deps (49).

CI --max-warnings will be lowered to 921 in the follow-up commit.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-30 23:30:22 +02:00
..
__tests__ refonte: backend-api go first; phase 1 2025-12-12 21:34:34 -05:00
components refactor(web): zero out 3 ESLint warning buckets (storybook + react-refresh + non-null-assertion) 2026-04-30 23:30:22 +02:00
hooks refactor(web): zero out @typescript-eslint/no-unused-vars (134 → 0) 2026-04-30 23:05:32 +02:00
pages fix: stabilize frontend — 98 TS errors to 0, align API endpoints, optimize bundle 2026-03-24 21:18:49 +01:00
services refactor(web): zero out 3 ESLint warning buckets (storybook + react-refresh + non-null-assertion) 2026-04-30 23:30:22 +02:00
store refactor(web): zero out @typescript-eslint/no-unused-vars (134 → 0) 2026-04-30 23:05:32 +02:00
index.ts feat(v0.13.4): polish audio & player — PiP canvas, visualizer, Cast/AirPlay stubs 2026-03-13 13:59:30 +01:00
README.md [INT-V2-003] Update documentation with id: string 2025-12-26 09:54:51 +01:00
types.test.ts feat(player): Lot F - PlaybackSpeedControl, useMediaSession, waveform 2026-02-20 00:40:53 +01:00
types.ts feat(player): Lot F - PlaybackSpeedControl, useMediaSession, waveform 2026-02-20 00:40:53 +01:00

Player Feature

Vue d'ensemble

Le module Player fournit une solution complète de lecture audio pour l'application VEZA. Il inclut tous les composants nécessaires pour une expérience de lecture audio complète et moderne.

Architecture

Structure des fichiers

features/player/
├── components/          # Composants UI
│   ├── AudioPlayer.tsx          # Composant principal (intégration complète)
│   ├── MiniPlayer.tsx           # Version compacte du player
│   ├── TrackInfo.tsx            # Affichage des informations de la piste
│   ├── PlayPauseButton.tsx      # Bouton play/pause
│   ├── NextPreviousButtons.tsx  # Boutons next/previous
│   ├── ProgressBar.tsx          # Barre de progression
│   ├── TimeDisplay.tsx          # Affichage du temps
│   ├── VolumeControl.tsx        # Contrôle du volume
│   ├── RepeatShuffleButtons.tsx # Boutons repeat/shuffle
│   ├── QualitySelector.tsx      # Sélecteur de qualité
│   ├── PlaybackSpeedControl.tsx # Contrôle de vitesse
│   ├── PlayerError.tsx          # Affichage des erreurs
│   └── PlayerLoading.tsx        # État de chargement
├── hooks/               # Hooks React
│   ├── usePlayer.ts             # Hook principal
│   ├── useKeyboardShortcuts.ts  # Raccourcis clavier
│   └── useUsernameAvailability.ts # (auth feature)
├── store/               # State management
│   └── playerStore.ts           # Store Zustand
├── services/            # Services
│   └── playerService.ts         # Service audio
├── types.ts             # Types TypeScript
└── index.ts             # Exports publics

Utilisation

Composant principal AudioPlayer

import { AudioPlayer } from '@/features/player';

function MyComponent() {
  return (
    <AudioPlayer
      autoPlay={false}
      preload="metadata"
      showQualitySelector={true}
      showSpeedControl={true}
      compact={false}
    />
  );
}

Props du AudioPlayer

  • className?: string - Classes CSS personnalisées
  • autoPlay?: boolean - Lecture automatique (défaut: false)
  • preload?: 'none' | 'metadata' | 'auto' - Stratégie de préchargement (défaut: 'metadata')
  • showQualitySelector?: boolean - Afficher le sélecteur de qualité (défaut: true)
  • showSpeedControl?: boolean - Afficher le contrôle de vitesse (défaut: true)
  • compact?: boolean - Mode compact (défaut: false)

MiniPlayer

import { MiniPlayer } from '@/features/player';

function MyComponent() {
  const [isVisible, setIsVisible] = useState(false);

  return (
    <MiniPlayer
      isVisible={isVisible}
      onToggle={() => setIsVisible(false)}
      onClose={() => setIsVisible(false)}
      position="bottom"
    />
  );
}

Hook usePlayer

import { usePlayer } from '@/features/player';

function MyComponent() {
  const audioRef = useRef<HTMLAudioElement>(null);
  const player = usePlayer(audioRef);

  // Utiliser l'état et les contrôles
  const { currentTrack, isPlaying, play, pause } = player;

  return (
    <div>
      {currentTrack && <p>{currentTrack.title}</p>}
      <button onClick={isPlaying ? pause : () => play()}>
        {isPlaying ? 'Pause' : 'Play'}
      </button>
    </div>
  );
}

Raccourcis clavier

Les raccourcis clavier sont activés automatiquement dans AudioPlayer :

  • Espace : Play/Pause
  • Flèche gauche : Reculer de 5 secondes
  • Flèche droite : Avancer de 5 secondes
  • Flèche haut : Augmenter le volume
  • Flèche bas : Diminuer le volume

Composants individuels

TrackInfo

Affiche les informations de la piste (titre, artiste, cover, métadonnées).

import { TrackInfo } from '@/features/player';

<TrackInfo track={track} showCover={true} coverSize="md" showMetadata={true} />;

PlayPauseButton

Bouton pour contrôler la lecture/pause.

import { PlayPauseButton } from '@/features/player';

<PlayPauseButton
  isPlaying={isPlaying}
  onClick={handlePlayPause}
  size="md"
  variant="default"
/>;

ProgressBar

Barre de progression avec interaction drag et seek.

import { ProgressBar } from '@/features/player';

<ProgressBar
  currentTime={currentTime}
  duration={duration}
  onSeek={handleSeek}
  showTooltip={true}
/>;

VolumeControl

Contrôle du volume avec slider et bouton mute.

import { VolumeControl } from '@/features/player';

<VolumeControl
  volume={volume}
  muted={muted}
  onVolumeChange={setVolume}
  onMuteToggle={toggleMute}
  showValue={true}
  showSlider={true}
/>;

QualitySelector

Sélecteur de qualité audio.

import { QualitySelector } from '@/features/player';

<QualitySelector
  currentQuality="high"
  onQualityChange={setQuality}
  availableQualities={['auto', 'medium', 'high']}
/>;

PlaybackSpeedControl

Contrôle de la vitesse de lecture.

import { PlaybackSpeedControl } from '@/features/player';

<PlaybackSpeedControl
  currentSpeed={1}
  onSpeedChange={setSpeed}
  availableSpeeds={[0.5, 1, 1.5, 2]}
/>;

State Management

Le player utilise Zustand pour la gestion d'état globale. Le store est persistant (localStorage).

import { usePlayerStore } from '@/features/player';

const { currentTrack, isPlaying, volume, setVolume } = usePlayerStore();

Services

AudioPlayerService

Service pour gérer l'élément audio HTML directement.

import { audioPlayerService } from '@/features/player';

// Initialiser avec un élément audio
audioPlayerService.initialize(audioElement);

// Charger une piste
await audioPlayerService.loadTrack(track);

// Contrôles
await audioPlayerService.play();
audioPlayerService.pause();
audioPlayerService.seek(30); // 30 secondes
audioPlayerService.setVolume(0.5); // 50%

Types

Track

interface Track {
  id: string; // UUID from backend
  title: string;
  artist?: string;
  album?: string;
  duration: number;
  url: string;
  cover?: string;
  genre?: string;
}

PlayerState

interface PlayerState {
  currentTrack: Track | null;
  isPlaying: boolean;
  currentTime: number;
  duration: number;
  volume: number;
  muted: boolean;
  queue: Track[];
  currentIndex: number;
  repeat: 'off' | 'track' | 'playlist';
  shuffle: boolean;
}

Tests

Tous les composants incluent des tests unitaires avec une couverture ≥ 80%. Des tests end-to-end sont également disponibles dans __tests__/player.e2e.test.tsx.

Accessibilité

Tous les composants sont accessibles avec :

  • Support des lecteurs d'écran (ARIA labels)
  • Navigation au clavier
  • Focus visible
  • Rôles ARIA appropriés

Performance

  • Lazy loading des composants
  • Mémoization des callbacks
  • Optimisation des re-renders
  • Persistance intelligente du state

Compatibilité

  • Navigateurs modernes (Chrome, Firefox, Safari, Edge)
  • Support mobile (iOS, Android)
  • Dark mode
  • Responsive design