@@ -19,8 +19,8 @@ export const MusicPlayer: React.FC<IMusicPlayerProps> = (props) => {
19
19
const { playingState, setCurrentQueueSong } = props ;
20
20
const selectedPlaylist = useAtomValue ( selectedPlaylistAtom ) ;
21
21
const [ isPlaying , setIsPlaying ] = useAtom ( isPlayingAtom ) ;
22
- const [ inputValue , setInputValue ] = useState < string > (
23
- ( playingState . currentQueueSong + 1 ) . toString ( )
22
+ const [ inputValue , setInputValue ] = useState (
23
+ playingState . currentQueueSong + 1
24
24
) ;
25
25
26
26
useEvent ( 'pausevideo' , ( ) => {
@@ -30,34 +30,30 @@ export const MusicPlayer: React.FC<IMusicPlayerProps> = (props) => {
30
30
const onPreviousQueueSong = ( ) => {
31
31
if ( playingState . currentQueueSong < 1 ) return ;
32
32
setCurrentQueueSong ( playingState . currentQueueSong - 1 ) ;
33
- setInputValue ( playingState . currentQueueSong . toString ( ) ) ;
33
+ setInputValue ( playingState . currentQueueSong ) ;
34
34
} ;
35
35
36
36
const onNextQueueSong = ( ) => {
37
37
if ( playingState . currentQueueSong === playingState . currentQueue . length - 1 )
38
38
return ;
39
39
setCurrentQueueSong ( playingState . currentQueueSong + 1 ) ;
40
- setInputValue ( ( playingState . currentQueueSong + 2 ) . toString ( ) ) ;
40
+ setInputValue ( playingState . currentQueueSong + 2 ) ;
41
41
} ;
42
42
43
43
const handleInputChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
44
- const newValue = e . target . value ;
45
- if ( Number . isInteger ( Number ( newValue ) ) ) {
46
- setInputValue ( newValue ) ;
47
- }
48
- } ;
49
-
50
- const handleInputBlur = ( ) => {
51
- const userInput = parseInt ( inputValue , 10 ) - 1 ;
44
+ const userInput = parseInt ( e . target . value , 10 ) ;
52
45
if ( isNaN ( userInput ) ) {
53
46
return ;
54
47
}
55
- const newQueueSong = Math . max (
56
- 0 ,
57
- Math . min ( userInput , playingState . currentQueue . length - 1 )
48
+ const newInputValue = Math . max (
49
+ 1 ,
50
+ Math . min ( userInput , playingState . currentQueue . length )
58
51
) ;
59
- setCurrentQueueSong ( newQueueSong ) ;
60
- setInputValue ( ( newQueueSong + 1 ) . toString ( ) ) ;
52
+ setInputValue ( newInputValue ) ;
53
+ } ;
54
+
55
+ const handleInputBlur = ( ) => {
56
+ setCurrentQueueSong ( inputValue - 1 ) ;
61
57
} ;
62
58
63
59
const handleInputKeyDown = ( e : React . KeyboardEvent < HTMLInputElement > ) => {
0 commit comments