Skip to content

Commit 51b1db4

Browse files
committed
fix: keep inputValue in sync with currentQueueSong
1 parent 0ab5d80 commit 51b1db4

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/components/MusicPlayer.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @jsxImportSource @emotion/react */
22
import { css } from '@emotion/react';
3-
import React, { useRef, useState } from 'react';
3+
import React, { useEffect, useRef, useState } from 'react';
44
import ReactPlayer from 'react-player';
55
import { ButtonGroup, Button, FormControl } from 'react-bootstrap';
66
import { IPlayingState } from '../models/Player';
@@ -23,21 +23,23 @@ export const MusicPlayer: React.FC<IMusicPlayerProps> = (props) => {
2323
playingState.currentQueueSong + 1
2424
);
2525

26+
useEffect(() => {
27+
setInputValue(playingState.currentQueueSong + 1);
28+
}, [playingState.currentQueueSong]);
29+
2630
useEvent('pausevideo', () => {
2731
setIsPlaying(false);
2832
});
2933

3034
const onPreviousQueueSong = () => {
3135
if (playingState.currentQueueSong < 1) return;
3236
setCurrentQueueSong(playingState.currentQueueSong - 1);
33-
setInputValue(playingState.currentQueueSong);
3437
};
3538

3639
const onNextQueueSong = () => {
3740
if (playingState.currentQueueSong === playingState.currentQueue.length - 1)
3841
return;
3942
setCurrentQueueSong(playingState.currentQueueSong + 1);
40-
setInputValue(playingState.currentQueueSong + 2);
4143
};
4244

4345
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {

0 commit comments

Comments
 (0)