Complete stabilization pass bringing all 3 stacks to green: Frontend (apps/web/): - Fix TypeScript nullability in useSeason.ts, useTimeOfDay.ts hooks - Disable no-undef in ESLint config (TypeScript handles it; JSX misidentified) - Rename 306 story imports from @storybook/react to @storybook/react-vite - Fix conditional hook call in useMediaQuery.ts useIsTablet - Move useQuery to top of LoginPage.tsx component - Remove useless try/catch in GearFormModal.tsx - Fix stale closure in ResetPasswordPage.tsx handleChange - Make Storybook decorators (withRouter, withQueryClient, withToast, withAudio) no-ops since global StorybookDecorator already provides these — prevents nested Router / duplicate provider crashes in vitest-browser - Fix nested MemoryRouter in 3 page stories (TrackDetail, PlaylistDetail, UserProfile) - Update i18n initialization in test setup (await init before changeLanguage) - Update ~30 test assertions from English to French to match i18n translations - Update test assertions to match SUMI V3 design changes (shadow vs border) - Fix remaining story type errors (PlayerError, PlaylistBatchActions, TrackFilters, VirtualizedChatMessages) Backend (veza-backend-api/): - Fix response_test.go RespondWithAppError signature (2 args, not 3) - Fix TestErrorContractAuthEndpoints expected error codes (ErrCodeUnauthorized vs ErrCodeInvalidCredentials) - Fix TestTrackHandler_GetTrackLikes_Success missing auth middleware setup - Fix TestPlaybackAnalyticsService_GetTrackStats k-anonymity threshold (needs 5 unique users, not 1) - Replace NOW() PostgreSQL function with time.Now() parameter in marketplace service for SQLite test compatibility - Add missing AutoMigrate entries in marketplace_test.go (ProductImage, ProductPreview, ProductLicense, ProductReview) Results: - Frontend TypeCheck: 617 errors -> 0 errors - Frontend ESLint: 349 errors -> 0 errors - Frontend Vitest: 196 failing tests -> 1 skipped (3396/3397 passing) - Backend go vet: 1 error -> 0 errors - Backend tests: 5 failing -> all 13 packages passing - Rust: 150/150 tests passing (unchanged) - Storybook audit: 0 errors across 1244 stories Triage report: docs/TRIAGE_REPORT.md Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
156 lines
4.7 KiB
TypeScript
156 lines
4.7 KiB
TypeScript
/**
|
|
* Composant QualitySelector
|
|
* Sélecteur de qualité audio avec dropdown
|
|
*/
|
|
|
|
import { useState, useRef, useEffect } from 'react';
|
|
import { ChevronDown, Check } from 'lucide-react';
|
|
import { cn } from '@/lib/utils';
|
|
|
|
export type AudioQuality = 'auto' | 'low' | 'medium' | 'high' | 'lossless';
|
|
|
|
export interface QualityOption {
|
|
value: AudioQuality;
|
|
label: string;
|
|
description?: string;
|
|
}
|
|
|
|
export interface QualitySelectorProps {
|
|
currentQuality: AudioQuality;
|
|
availableQualities?: AudioQuality[];
|
|
onQualityChange: (quality: AudioQuality) => void;
|
|
className?: string;
|
|
disabled?: boolean;
|
|
}
|
|
|
|
const DEFAULT_QUALITIES: QualityOption[] = [
|
|
{ value: 'auto', label: 'Auto', description: 'Qualité automatique' },
|
|
{ value: 'low', label: 'Faible', description: '128 kbps' },
|
|
{ value: 'medium', label: 'Moyenne', description: '256 kbps' },
|
|
{ value: 'high', label: 'Haute', description: '320 kbps' },
|
|
{ value: 'lossless', label: 'Sans perte', description: 'FLAC / WAV' },
|
|
];
|
|
|
|
export function QualitySelector({
|
|
currentQuality,
|
|
availableQualities,
|
|
onQualityChange,
|
|
className,
|
|
disabled = false,
|
|
}: QualitySelectorProps) {
|
|
const [isOpen, setIsOpen] = useState(false);
|
|
const dropdownRef = useRef<HTMLDivElement>(null);
|
|
|
|
// Filtrer les qualités disponibles
|
|
const qualities = availableQualities
|
|
? DEFAULT_QUALITIES.filter((q) => availableQualities.includes(q.value))
|
|
: DEFAULT_QUALITIES;
|
|
|
|
const currentQualityOption =
|
|
qualities.find((q) => q.value === currentQuality) ??
|
|
qualities[0] ??
|
|
{ value: currentQuality, label: currentQuality };
|
|
|
|
// Fermer le dropdown quand on clique en dehors
|
|
useEffect(() => {
|
|
const handleClickOutside = (event: MouseEvent) => {
|
|
if (
|
|
dropdownRef.current &&
|
|
!dropdownRef.current.contains(event.target as Node)
|
|
) {
|
|
setIsOpen(false);
|
|
}
|
|
};
|
|
|
|
if (isOpen) {
|
|
document.addEventListener('mousedown', handleClickOutside);
|
|
return () => {
|
|
document.removeEventListener('mousedown', handleClickOutside);
|
|
};
|
|
}
|
|
return undefined;
|
|
}, [isOpen]);
|
|
|
|
const handleSelect = (quality: AudioQuality) => {
|
|
onQualityChange(quality);
|
|
setIsOpen(false);
|
|
};
|
|
|
|
return (
|
|
<div ref={dropdownRef} className={cn('relative', className)}>
|
|
{/* Button */}
|
|
<button
|
|
type="button"
|
|
onClick={() => !disabled && setIsOpen(!isOpen)}
|
|
disabled={disabled}
|
|
className={cn(
|
|
'flex items-center gap-2 px-4 py-2 text-sm font-medium rounded-lg',
|
|
'bg-card shadow-[0_2px_8px_rgba(26,26,30,0.10)]',
|
|
'text-foreground',
|
|
'hover:bg-muted',
|
|
'focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2',
|
|
'disabled:opacity-50 disabled:cursor-not-allowed',
|
|
'transition-colors',
|
|
)}
|
|
aria-label={`Qualité audio: ${currentQualityOption.label}`}
|
|
aria-expanded={isOpen}
|
|
aria-haspopup="listbox"
|
|
aria-disabled={disabled}
|
|
>
|
|
<span>{currentQualityOption.label}</span>
|
|
<ChevronDown
|
|
className={cn(
|
|
'h-4 w-4 transition-transform',
|
|
isOpen && 'transform rotate-180',
|
|
)}
|
|
aria-hidden="true"
|
|
/>
|
|
</button>
|
|
|
|
{/* Dropdown */}
|
|
{isOpen && !disabled && (
|
|
<div
|
|
className="absolute z-50 mt-1 w-48 bg-card rounded-lg shadow-[0_8px_32px_rgba(26,26,30,0.18)]"
|
|
role="listbox"
|
|
>
|
|
{qualities.map((quality) => (
|
|
<button
|
|
key={quality.value}
|
|
type="button"
|
|
onClick={() => handleSelect(quality.value)}
|
|
className={cn(
|
|
'w-full flex items-center justify-between px-4 py-2 text-sm text-left',
|
|
'hover:bg-muted',
|
|
'focus:outline-none focus:bg-muted',
|
|
'transition-colors',
|
|
currentQuality === quality.value &&
|
|
'bg-primary/10',
|
|
)}
|
|
role="option"
|
|
aria-selected={currentQuality === quality.value}
|
|
>
|
|
<div className="flex flex-col">
|
|
<span className="font-medium text-foreground">
|
|
{quality.label}
|
|
</span>
|
|
{quality.description && (
|
|
<span className="text-xs text-muted-foreground">
|
|
{quality.description}
|
|
</span>
|
|
)}
|
|
</div>
|
|
{currentQuality === quality.value && (
|
|
<Check
|
|
className="h-4 w-4 text-muted-foreground"
|
|
aria-hidden="true"
|
|
/>
|
|
)}
|
|
</button>
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default QualitySelector;
|