From 2fac8281e06bf0dcdd293b461581923a22529358 Mon Sep 17 00:00:00 2001 From: jeffvli Date: Thu, 7 Apr 2022 00:35:12 -0700 Subject: [PATCH] Add "Play Random" button to player bar --- src/components/player/PlayerBar.tsx | 38 ++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/components/player/PlayerBar.tsx b/src/components/player/PlayerBar.tsx index ed2a4f0..ede9500 100644 --- a/src/components/player/PlayerBar.tsx +++ b/src/components/player/PlayerBar.tsx @@ -27,7 +27,7 @@ import placeholderImg from '../../img/placeholder.png'; import DebugWindow from '../debug/DebugWindow'; import { getCurrentEntryList, writeOBSFiles } from '../../shared/utils'; import { SecondaryTextWrapper, StyledButton, StyledRate } from '../shared/styled'; -import { Artist, Server } from '../../types'; +import { Artist, Play, Server, Song } from '../../types'; import { notifyToast } from '../shared/toast'; import { InfoModal } from '../modal/Modal'; import useGetLyrics from '../../hooks/useGetLyrics'; @@ -36,6 +36,8 @@ import { setSidebar } from '../../redux/configSlice'; import Popup from '../shared/Popup'; import useFavorite from '../../hooks/useFavorite'; import { useRating } from '../../hooks/useRating'; +import usePlayQueueHandler from '../../hooks/usePlayQueueHandler'; +import { apiController } from '../../api/controller'; const DiscordRPC = require('discord-rpc'); @@ -45,6 +47,7 @@ const PlayerBar = () => { const playQueue = useAppSelector((state) => state.playQueue); const player = useAppSelector((state) => state.player); const config = useAppSelector((state) => state.config); + const folder = useAppSelector((state) => state.folder); const dispatch = useAppDispatch(); const [seek, setSeek] = useState(0); const [isDragging, setIsDragging] = useState(false); @@ -56,6 +59,23 @@ const PlayerBar = () => { const [discordRpc, setDiscordRpc] = useState(); const [showCoverArtModal, setShowCoverArtModal] = useState(false); const [showLyricsModal, setShowLyricsModal] = useState(false); + const [isLoadingRandom, setIsLoadingRandom] = useState(false); + const { handlePlayQueueAdd } = usePlayQueueHandler(); + + const handlePlayRandom = async () => { + setIsLoadingRandom(true); + const res: Song[] = await apiController({ + serverType: config.serverType, + endpoint: 'getRandomSongs', + args: { + size: 200, + musicFolderId: folder.musicFolder, + }, + }); + + handlePlayQueueAdd({ byData: res, play: Play.Play }); + setIsLoadingRandom(false); + }; const playersRef = useRef(); const history = useHistory(); @@ -572,9 +592,19 @@ const PlayerBar = () => { }} /> - - {' '} - + + +