From b1df62c8bf4bdd4ccc652e7412161418faddca63 Mon Sep 17 00:00:00 2001 From: "Elisei.Nicolae" Date: Sun, 25 Dec 2022 23:43:15 +0200 Subject: [PATCH] feat: add loading svg. --- frontend/components/StationPlayer.tsx | 17 ++++++++++++++--- frontend/public/images/loading.tsx | 26 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 frontend/public/images/loading.tsx diff --git a/frontend/components/StationPlayer.tsx b/frontend/components/StationPlayer.tsx index acd5fd7..fd6c063 100644 --- a/frontend/components/StationPlayer.tsx +++ b/frontend/components/StationPlayer.tsx @@ -3,7 +3,6 @@ import {useRouter} from 'next/router'; import {useIdleTimer} from 'react-idle-timer'; import {isDesktop, isMobile} from 'react-device-detect'; import dynamic from 'next/dynamic'; - import { Box, Flex, @@ -21,6 +20,7 @@ import {trackListenClientSide} from '../frontendServices/listen'; import {CONSTANTS} from '../lib/constants'; import {Station} from '../types'; import {cdnImageLoader} from '@/utils/cdnImageLoader'; +import {Loading} from '@/public/images/loading'; const ReactPlayer = dynamic(() => import('react-player/lazy'), {ssr: false}); @@ -48,6 +48,7 @@ export default function StationPlayer({stations}: any) { const [volume, setVolume] = useLocalStorageState(60, 'AUDIO_PLAYER_VOLUME'); const [selectedStreamType, setSelectedStreamType] = useState('HLS'); const [hasInteracted, setInteraction] = useState(false); + const [isLoading, setIsLoading] = useState(true); useIdleTimer({ onAction: () => setInteraction(true), @@ -251,9 +252,13 @@ export default function StationPlayer({stations}: any) { aria-hidden="true" viewBox="0 0 24 24"> {isPlaying ? ( - + isLoading ? ( + + ) : ( + + ) ) : ( - + )} @@ -266,6 +271,12 @@ export default function StationPlayer({stations}: any) { playing={isPlaying} muted={isMuted} volume={volume / 100} + onBuffer={() => { + setIsLoading(true); + }} + onBufferEnd={() => { + setIsLoading(false); + }} onPlay={() => { console.debug('onPlay'); setMuted(false); diff --git a/frontend/public/images/loading.tsx b/frontend/public/images/loading.tsx new file mode 100644 index 0000000..f96ed50 --- /dev/null +++ b/frontend/public/images/loading.tsx @@ -0,0 +1,26 @@ +export const Loading = () => { + return ( + + + + + + ); +};