Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: playback #300

Merged
merged 8 commits into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions components/Sidebar/icons/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ const SidebarIcons = ({
selected={currentSelection === "friends"}
onClick={() => onChange("friends")}
/>
<PlaybackIcon
selected={currentSelection === "playback"}
onClick={() => onChange("playback")}
/>
</>
);

Expand Down
2 changes: 1 addition & 1 deletion components/Sidebar/panels/BasePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const BasePanel = ({

if (sidebar !== sidebarId) return null;
return (
<div className="w-full md:w-64 min-h-screen h-100% md:p-4 md:bg-gray-200 md:text-black">
<div className="w-full md:w-64 max-h-screen h-screen overflow-y-scroll md:p-4 md:bg-gray-200 md:text-black">
{title && (
<>
<h2 className="normal-case font-bold">{title}</h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Link from "next/link";

import ArtistLinks from "@/components/ui/ArtistLinks";

const FriendItem = ({ track }: { track: SpotifyApi.TrackObjectFull }) => (
const FriendItem = ({ track }: { track: SpotifyApi.TrackObjectSimplified }) => (
<li>
<div className="flex flex-row justify-start content-center max-w-[224px]">
<h5 className="text-xs truncate max-w-[112px]">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import "server-only";

import getFollowedUsers from "@/lib/followers/getFollowedUsers";

import BasePanel from "./BasePanel";
import BasePanel from "../BasePanel";

import Friend from "./Friend";

const Friends = async () => {
Expand Down
28 changes: 28 additions & 0 deletions components/Sidebar/panels/Playback/PlaybackPanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"use client";

import { useSidebar } from "@/components/Sidebar/SidebarContext";

import Player from "./Player";

const PlaybackPanel = ({ accessToken }: { accessToken: string }) => {
const [sidebar] = useSidebar();
const isCurrentSidebar = sidebar === "playback";

return (
<div
className={`w-full md:w-64 max-h-screen h-screen flex flex-col md:p-4 md:bg-gray-200 md:text-black ${
isCurrentSidebar ? "" : "hidden"
}`}
>
<div>
<h2 className="normal-case font-bold">Playback</h2>
<div className="divider" />
</div>
<div className="flex-grow flex flex-col justify-center">
<Player accessToken={accessToken} />
</div>
</div>
);
};

export default PlaybackPanel;
40 changes: 40 additions & 0 deletions components/Sidebar/panels/Playback/Player.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"use client";

import { useRouter } from "next/navigation";
import { useState } from "react";
import SpotifyPlayer from "react-spotify-web-playback";

const Player = ({ accessToken }: { accessToken: string }) => {
const [isVisible, toggleVisibility] = useState(false);
const router = useRouter();
if (!isVisible) {
return (
<button
className="btn btn-ghost bg-spotify text-white btn-block"
onClick={() => toggleVisibility(true)}
type="button"
>
Connect to Spotify
</button>
);
}
return (
<>
{/* @see https://github.com/gilbarbara/react-spotify-web-playback/issues/154 */}
{/* @ts-expect-error SpotifyPlayer type error */}
<SpotifyPlayer
updateSavedStatus={() => router.refresh()}
syncExternalDevice
syncExternalDeviceInterval={5}
name="DKMS"
token={accessToken}
layout="compact"
showSaveIcon
persistDeviceSelection
hideAttribution
/>
</>
);
};

export default Player;
10 changes: 10 additions & 0 deletions components/Sidebar/panels/Playback/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import getServerAccessToken from "@/lib/getServerAccessToken";

import PlaybackPanel from "./PlaybackPanel";

const Playback = async () => {
const accessToken = await getServerAccessToken();
return <PlaybackPanel accessToken={accessToken} />;
};

export default Playback;
3 changes: 3 additions & 0 deletions components/Sidebar/panels/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import Friends from "./Friends";
import Notifications from "./Notifications";
import Playback from "./Playback";

const SidebarPanels = ({ isDesktop }: { isDesktop?: boolean }) => (
<div className={isDesktop ? "hidden md:block" : "md:hidden"}>
{/* @ts-expect-error Next 13 handles async components */}
<Friends />
{/* @ts-expect-error Next 13 handles async components */}
<Notifications />
{/* @ts-expect-error Next 13 handles async components */}
<Playback />
</div>
);

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"react-dom": "^18.2.0",
"react-hot-toast": "^2.4.0",
"react-loading-skeleton": "^3.1.1",
"react-spotify-web-playback": "^0.13.4",
"server-only": "^0.0.1",
"sharp": "0.31.1",
"v8": "^0.1.0"
Expand Down
6 changes: 3 additions & 3 deletions pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ const SCOPES = [
// "playlist-modify-public",
"user-follow-modify",
"user-follow-read",
// "user-read-playback-position",
"user-read-playback-position",
"user-top-read",
"user-read-recently-played",
"user-library-modify",
"user-library-read",
// "user-read-email",
// "user-read-private",
"user-read-email",
"user-read-private",
] as const;

export const authOptions: NextAuthOptions = {
Expand Down