-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve playback usability (#354)
- Loading branch information
Showing
12 changed files
with
182 additions
and
93 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
"use client"; | ||
|
||
import PlayerProvider from "@/components/Player/PlayerProvider"; | ||
import SidebarProvider from "@/components/Sidebar/SidebarProvider"; | ||
|
||
const AppProviders = ({ children }: { children: React.ReactNode }) => ( | ||
<SidebarProvider>{children}</SidebarProvider> | ||
<SidebarProvider> | ||
<PlayerProvider>{children}</PlayerProvider> | ||
</SidebarProvider> | ||
); | ||
|
||
export default AppProviders; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { createContext, useContext } from "react"; | ||
|
||
import type { Dispatch, SetStateAction } from "react"; | ||
|
||
export type PlayerContextType = { | ||
currentDeviceState: [ | ||
string | undefined, | ||
Dispatch<SetStateAction<string | undefined>> | ||
]; | ||
visibleState: [boolean, Dispatch<SetStateAction<boolean>>]; | ||
}; | ||
const PlayerContext = createContext<PlayerContextType>({ | ||
currentDeviceState: [undefined, () => undefined], | ||
visibleState: [false, () => undefined], | ||
}); | ||
|
||
export const usePlayer = () => useContext(PlayerContext); | ||
|
||
export default PlayerContext; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"use client"; | ||
|
||
import { useMemo, useState } from "react"; | ||
|
||
import PlayerContext from "./PlayerContext"; | ||
|
||
import type { PlayerContextType } from "./PlayerContext"; | ||
|
||
const PlayerProvider = ({ children }: { children: React.ReactNode }) => { | ||
const [currentDeviceId, setCurrentDeviceId] = useState<string | undefined>( | ||
undefined | ||
); | ||
const [visible, setVisible] = useState<boolean>(false); | ||
|
||
const playbackContextValue = useMemo( | ||
(): PlayerContextType => ({ | ||
currentDeviceState: [currentDeviceId, setCurrentDeviceId], | ||
visibleState: [visible, setVisible], | ||
}), | ||
[currentDeviceId, visible] | ||
); | ||
|
||
return ( | ||
<PlayerContext.Provider value={playbackContextValue}> | ||
{children} | ||
</PlayerContext.Provider> | ||
); | ||
}; | ||
|
||
export default PlayerProvider; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
"use client"; | ||
|
||
import { useRouter } from "next/navigation"; | ||
import SpotifyPlayer from "react-spotify-web-playback"; | ||
|
||
import { usePlayer } from "@/components/Player/PlayerContext"; | ||
|
||
const Player = ({ accessToken }: { accessToken: string }) => { | ||
const { currentDeviceState, visibleState } = usePlayer(); | ||
const [isVisible, setIsVisible] = visibleState; | ||
const [, setCurrentDeviceId] = currentDeviceState; | ||
|
||
const router = useRouter(); | ||
|
||
return ( | ||
<> | ||
<div className="hidden"> | ||
<SpotifyPlayer | ||
callback={(state) => { | ||
if (state.status === "READY") { | ||
setIsVisible(true); | ||
setCurrentDeviceId(state.currentDeviceId); | ||
} | ||
}} | ||
name="DKMS" | ||
token={accessToken} | ||
persistDeviceSelection | ||
uris={[]} | ||
/> | ||
<br /> | ||
</div> | ||
{isVisible ? ( | ||
<SpotifyPlayer | ||
updateSavedStatus={() => router.refresh()} | ||
syncExternalDevice | ||
syncExternalDeviceInterval={2} | ||
callback={(state) => { | ||
setCurrentDeviceId(state.currentDeviceId); | ||
}} | ||
name="DKMS" | ||
token={accessToken} | ||
layout="compact" | ||
showSaveIcon | ||
persistDeviceSelection | ||
uris={[]} | ||
hideAttribution | ||
/> | ||
) : ( | ||
<button | ||
className="btn btn-ghost bg-spotify text-white btn-block" | ||
onClick={() => setIsVisible(true)} | ||
type="button" | ||
> | ||
Connect to Spotify | ||
</button> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default Player; |
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
This file was deleted.
Oops, something went wrong.
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
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
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
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