Created
July 4, 2021 15:50
-
-
Save avoajaugochukwu/1e3f798beb044cebc124d345d4d7ae36 to your computer and use it in GitHub Desktop.
Sticker Mule gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// App.js | |
function App() { | |
const [audio, setAudio] = useState({}) | |
const dispatch = useDispatch() | |
const currentTrack = useSelector((state) => state.currentTrack) | |
const { isPlaying, episode: { episodeUrl, collectionName } } = currentTrack | |
document.title = collectionName && isPlaying ? collectionName : 'Podcast Player' | |
const handlePlay = (episode) => (e) => { | |
let sound | |
if (!episodeUrl) { | |
sound = new Audio(episode.episodeUrl) | |
sound.play() | |
setAudio(sound) | |
dispatch(play(episode)) | |
} else if (episodeUrl !== episode.episodeUrl) { | |
audio.pause() | |
sound = new Audio(episode.episodeUrl) | |
sound.play() | |
setAudio(sound) | |
dispatch(play(episode)) | |
} else { | |
audio.play() | |
dispatch(play(episode)) | |
} | |
} | |
const handlePause = () => { | |
audio.pause() | |
dispatch(pause()) | |
} | |
return ( | |
<div className="App"> | |
<BrowserRouter> | |
<div> | |
<MobileHeader /> | |
<div className="flex relative"> | |
<SideBar /> | |
<MainSection handlePause={handlePause} handlePlay={handlePlay} /> | |
<FooterPlayer handlePause={handlePause} handlePlay={handlePlay} /> | |
</div> | |
</div> | |
</BrowserRouter> | |
</div> | |
); | |
} | |
export default App | |
******************************************************************************************* | |
******************************************************************************************* | |
// MainSecton.js ******************************************************************************************* | |
import React from 'react' | |
import { | |
Switch, | |
Route | |
} from 'react-router-dom' | |
const MainSection = ({ handlePause, handlePlay }) => { | |
return ( | |
<> | |
<main className=" player-section pl-0 md:pl-60 min-h-screen min-w-full"> | |
<Switch> | |
<Route exact path="/" component={HomeScreen}></Route> | |
<Route exact path="/Search" component={SearchScreen}></Route> | |
<Route exact path="/podcast/:collectionId" render={(props) => (<PodcastDetailsScreen {...props} handlePause={handlePause} handlePlay={handlePlay} />)} /> | |
<Route exact path="/genre/:genreId" component={GenreListScreen}></Route> | |
</Switch> | |
</main> | |
</> | |
) | |
} | |
export default MainSection |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment