From f26a76836f591ef92ea7ae1e6d00b1b2d1cfcddd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mert=20Uyan=C4=B1k?= <99019289+MertUyanik@users.noreply.github.com> Date: Wed, 29 Oct 2025 08:40:19 +0300 Subject: [PATCH] Fix lint issues and improve type safety --- src/contexts/PlayerContext.tsx | 8 ++++++-- src/hooks/useKeyboardShortcuts.ts | 5 +++-- src/types/index.ts | 8 +++++--- src/utils/hlsLoader.ts | 2 +- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/contexts/PlayerContext.tsx b/src/contexts/PlayerContext.tsx index 37278e2..e010970 100644 --- a/src/contexts/PlayerContext.tsx +++ b/src/contexts/PlayerContext.tsx @@ -1,6 +1,9 @@ import React, { createContext, useContext, useRef, useState, useCallback } from 'react' import type { PlayerContextValue, VideoState, UIState, PlayerSettings, AudioTrack } from '../types' +type SelectedQuality = PlayerSettings['quality'] +type SelectedSubtitle = PlayerSettings['subtitle'] + interface PlayerContextType extends PlayerContextValue { setVideoState: React.Dispatch> setUIState: React.Dispatch> @@ -8,6 +11,7 @@ interface PlayerContextType extends PlayerContextValue { const PlayerContext = createContext(null) +// eslint-disable-next-line react-refresh/only-export-components export const usePlayerContext = () => { const context = useContext(PlayerContext) if (!context) { @@ -143,11 +147,11 @@ export const PlayerProvider: React.FC = ({ }, []) // Settings - const setQuality = useCallback((quality: typeof settings.quality) => { + const setQuality = useCallback((quality: SelectedQuality) => { setSettings((prev) => ({ ...prev, quality })) }, []) - const setSubtitle = useCallback((subtitle: typeof settings.subtitle) => { + const setSubtitle = useCallback((subtitle: SelectedSubtitle) => { setSettings((prev) => ({ ...prev, subtitle })) }, []) diff --git a/src/hooks/useKeyboardShortcuts.ts b/src/hooks/useKeyboardShortcuts.ts index 22a1ebd..e8d03a6 100644 --- a/src/hooks/useKeyboardShortcuts.ts +++ b/src/hooks/useKeyboardShortcuts.ts @@ -92,11 +92,12 @@ export const useKeyboardShortcuts = (enabled: boolean = true) => { case '6': case '7': case '8': - case '9': + case '9': { e.preventDefault() - const percent = parseInt(e.key) / 10 + const percent = parseInt(e.key, 10) / 10 seek(videoState.duration * percent) break + } default: break diff --git a/src/types/index.ts b/src/types/index.ts index 4f3b02f..e2d6170 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,3 +1,5 @@ +import type { CSSProperties, RefObject } from 'react' + export interface SubtitleTrack { src: string lang: string @@ -39,7 +41,7 @@ export interface VideoPlayerProps { keyboardShortcuts?: boolean pictureInPicture?: boolean className?: string - style?: React.CSSProperties + style?: CSSProperties onPlay?: () => void onPause?: () => void onEnded?: () => void @@ -85,8 +87,8 @@ export interface PlayerContextValue { videoState: VideoState uiState: UIState settings: PlayerSettings - videoRef: React.RefObject - containerRef: React.RefObject + videoRef: RefObject + containerRef: RefObject // Video controls play: () => void diff --git a/src/utils/hlsLoader.ts b/src/utils/hlsLoader.ts index f438470..bb95df5 100644 --- a/src/utils/hlsLoader.ts +++ b/src/utils/hlsLoader.ts @@ -57,7 +57,7 @@ export const loadHls = async (): Promise => { const Hls = await loadHlsFromCDN() return Hls } catch (cdnError) { - console.error('❌ [HLS Loader] Failed to load hls.js from both npm and CDN') + console.error('❌ [HLS Loader] Failed to load hls.js from both npm and CDN', cdnError) throw new Error('Unable to load HLS.js library. HLS streaming is not available.') } }