|
@ -1,4 +1,5 @@ |
|
|
import React, { useEffect, useState, useRef } from 'react'; |
|
|
import React, { useEffect, useState, useRef } from 'react'; |
|
|
|
|
|
import { useQueryClient } from 'react-query'; |
|
|
import settings from 'electron-settings'; |
|
|
import settings from 'electron-settings'; |
|
|
import { FlexboxGrid, Icon, Grid, Row, Col } from 'rsuite'; |
|
|
import { FlexboxGrid, Icon, Grid, Row, Col } from 'rsuite'; |
|
|
import { useHistory } from 'react-router-dom'; |
|
|
import { useHistory } from 'react-router-dom'; |
|
@ -19,11 +20,13 @@ import { |
|
|
setStatus, |
|
|
setStatus, |
|
|
fixPlayer2Index, |
|
|
fixPlayer2Index, |
|
|
toggleRepeat, |
|
|
toggleRepeat, |
|
|
toggleShuffle, |
|
|
toggleDisplayQueue, |
|
|
|
|
|
setStar, |
|
|
} from '../../redux/playQueueSlice'; |
|
|
} from '../../redux/playQueueSlice'; |
|
|
import { useAppDispatch, useAppSelector } from '../../redux/hooks'; |
|
|
import { useAppDispatch, useAppSelector } from '../../redux/hooks'; |
|
|
import Player from './Player'; |
|
|
import Player from './Player'; |
|
|
import CustomTooltip from '../shared/CustomTooltip'; |
|
|
import CustomTooltip from '../shared/CustomTooltip'; |
|
|
|
|
|
import { star, unstar } from '../../api/api'; |
|
|
|
|
|
|
|
|
const keyCodes = { |
|
|
const keyCodes = { |
|
|
SPACEBAR: 32, |
|
|
SPACEBAR: 32, |
|
@ -32,6 +35,7 @@ const keyCodes = { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
const PlayerBar = () => { |
|
|
const PlayerBar = () => { |
|
|
|
|
|
const queryClient = useQueryClient(); |
|
|
const playQueue = useAppSelector((state) => state.playQueue); |
|
|
const playQueue = useAppSelector((state) => state.playQueue); |
|
|
const dispatch = useAppDispatch(); |
|
|
const dispatch = useAppDispatch(); |
|
|
const [seek, setSeek] = useState(0); |
|
|
const [seek, setSeek] = useState(0); |
|
@ -202,10 +206,27 @@ const PlayerBar = () => { |
|
|
dispatch(toggleRepeat()); |
|
|
dispatch(toggleRepeat()); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
const handleShuffle = () => { |
|
|
const handleDisplayQueue = () => { |
|
|
dispatch(toggleShuffle()); |
|
|
dispatch(toggleDisplayQueue()); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const handleFavorite = async () => { |
|
|
|
|
|
if (!playQueue.entry[playQueue.currentIndex].starred) { |
|
|
|
|
|
star(playQueue.entry[playQueue.currentIndex].id, 'song'); |
|
|
|
|
|
dispatch(setStar('star')); |
|
|
|
|
|
await queryClient.refetchQueries(['starred'], { |
|
|
|
|
|
active: true, |
|
|
|
|
|
exact: true, |
|
|
|
|
|
}); |
|
|
|
|
|
} else { |
|
|
|
|
|
unstar(playQueue.entry[playQueue.currentIndex].id, 'song'); |
|
|
|
|
|
dispatch(setStar('unstar')); |
|
|
|
|
|
await queryClient.refetchQueries(['starred'], { |
|
|
|
|
|
active: true, |
|
|
|
|
|
exact: true, |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
return ( |
|
|
return ( |
|
|
<Player ref={playersRef}> |
|
|
<Player ref={playersRef}> |
|
|
<PlayerContainer> |
|
|
<PlayerContainer> |
|
@ -436,14 +457,14 @@ const PlayerBar = () => { |
|
|
> |
|
|
> |
|
|
{playQueue.entry.length >= 1 && ( |
|
|
{playQueue.entry.length >= 1 && ( |
|
|
<> |
|
|
<> |
|
|
{/* Star Button */} |
|
|
{/* Favorite Button */} |
|
|
<CustomTooltip text="Star" delay={1000}> |
|
|
<CustomTooltip text="Favorite"> |
|
|
<PlayerControlIcon |
|
|
<PlayerControlIcon |
|
|
tabIndex={0} |
|
|
tabIndex={0} |
|
|
icon={ |
|
|
icon={ |
|
|
playQueue.entry[playQueue.currentIndex].starred |
|
|
playQueue.entry[playQueue.currentIndex].starred |
|
|
? 'star' |
|
|
? 'heart' |
|
|
: 'star-o' |
|
|
: 'heart-o' |
|
|
} |
|
|
} |
|
|
size="lg" |
|
|
size="lg" |
|
|
fixedWidth |
|
|
fixedWidth |
|
@ -453,46 +474,48 @@ const PlayerBar = () => { |
|
|
? '#1179ac' |
|
|
? '#1179ac' |
|
|
: undefined, |
|
|
: undefined, |
|
|
}} |
|
|
}} |
|
|
|
|
|
onClick={handleFavorite} |
|
|
/> |
|
|
/> |
|
|
</CustomTooltip> |
|
|
</CustomTooltip> |
|
|
|
|
|
|
|
|
{/* Shuffle Button */} |
|
|
{/* Repeat Button */} |
|
|
<CustomTooltip text="Shuffle" delay={1000}> |
|
|
<CustomTooltip text="Repeat"> |
|
|
<PlayerControlIcon |
|
|
<PlayerControlIcon |
|
|
tabIndex={0} |
|
|
tabIndex={0} |
|
|
icon="random" |
|
|
icon="repeat" |
|
|
size="lg" |
|
|
size="lg" |
|
|
fixedWidth |
|
|
fixedWidth |
|
|
onClick={handleShuffle} |
|
|
onClick={handleRepeat} |
|
|
onKeyDown={(e: any) => { |
|
|
onKeyDown={(e: any) => { |
|
|
if (e.keyCode === keyCodes.SPACEBAR) { |
|
|
if (e.keyCode === keyCodes.SPACEBAR) { |
|
|
handleShuffle(); |
|
|
handleRepeat(); |
|
|
} |
|
|
} |
|
|
}} |
|
|
}} |
|
|
style={{ |
|
|
style={{ |
|
|
color: playQueue.shuffle ? '#1179ac' : undefined, |
|
|
color: |
|
|
|
|
|
playQueue.repeat === 'all' |
|
|
|
|
|
? '#1179ac' |
|
|
|
|
|
: undefined, |
|
|
}} |
|
|
}} |
|
|
/> |
|
|
/> |
|
|
</CustomTooltip> |
|
|
</CustomTooltip> |
|
|
|
|
|
{/* Display Queue Button */} |
|
|
{/* Repeat Button */} |
|
|
<CustomTooltip text="Queue"> |
|
|
<CustomTooltip text="Repeat" delay={1000}> |
|
|
|
|
|
<PlayerControlIcon |
|
|
<PlayerControlIcon |
|
|
tabIndex={0} |
|
|
tabIndex={0} |
|
|
icon="repeat" |
|
|
icon="tasks" |
|
|
size="lg" |
|
|
size="lg" |
|
|
fixedWidth |
|
|
fixedWidth |
|
|
onClick={handleRepeat} |
|
|
onClick={handleDisplayQueue} |
|
|
onKeyDown={(e: any) => { |
|
|
onKeyDown={(e: any) => { |
|
|
if (e.keyCode === keyCodes.SPACEBAR) { |
|
|
if (e.keyCode === keyCodes.SPACEBAR) { |
|
|
handleRepeat(); |
|
|
handleDisplayQueue(); |
|
|
} |
|
|
} |
|
|
}} |
|
|
}} |
|
|
style={{ |
|
|
style={{ |
|
|
color: |
|
|
color: playQueue.displayQueue |
|
|
playQueue.repeat === 'all' |
|
|
? '#1179ac' |
|
|
? '#1179ac' |
|
|
: undefined, |
|
|
: undefined, |
|
|
|
|
|
}} |
|
|
}} |
|
|
/> |
|
|
/> |
|
|
</CustomTooltip> |
|
|
</CustomTooltip> |
|
|