From e2278495e03a620482c9ded1de83e2bcd253a166 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 20 Dec 2023 20:46:02 +0100 Subject: [PATCH 1/3] added stats --- packages/nextjs/pages/artist/[artistId].tsx | 33 +++++----- packages/nextjs/pages/dashboard/overview.tsx | 65 +++++++++++++++++++ packages/nextjs/pages/login.tsx | 2 +- .../nextjs/pages/playlists/[playlistId].tsx | 2 +- 4 files changed, 82 insertions(+), 20 deletions(-) create mode 100644 packages/nextjs/pages/dashboard/overview.tsx diff --git a/packages/nextjs/pages/artist/[artistId].tsx b/packages/nextjs/pages/artist/[artistId].tsx index d46faee..ee4b4c5 100644 --- a/packages/nextjs/pages/artist/[artistId].tsx +++ b/packages/nextjs/pages/artist/[artistId].tsx @@ -88,24 +88,21 @@ export default function SingleArtist({ -
- -
-
- -
+ + +
diff --git a/packages/nextjs/pages/dashboard/overview.tsx b/packages/nextjs/pages/dashboard/overview.tsx new file mode 100644 index 0000000..1262734 --- /dev/null +++ b/packages/nextjs/pages/dashboard/overview.tsx @@ -0,0 +1,65 @@ +import { useState } from "react"; +import { GetServerSideProps } from "next"; +import { getSession } from "next-auth/react"; +import DashboardLayout from "~~/components/dashboard/DashboardLayout"; +import ArtistList from "~~/components/spotify/ArtistList"; +import Heading from "~~/components/spotify/Heading"; +import Layout from "~~/components/spotify/Layout"; +import { MySession } from "~~/types/session"; +import { Artist } from "~~/types/spotify"; +import { customGet } from "~~/utils/beat-bridge/customGet"; +import { isAuthenticated } from "~~/utils/beat-bridge/isAuthenticated"; + +interface IProps { + topArtists: Artist[]; +} + +export default function FollowedArtists({ topArtists }: IProps) { + const [timeRange, setTimeRange] = useState("short_term"); + + return ( + + + + + + + + ); +} + +export const getServerSideProps: GetServerSideProps = async ctx => { + const session = (await getSession(ctx)) as MySession | null; + + if (!(await isAuthenticated(session))) { + return { + redirect: { + destination: "/login", + permanent: false, + }, + }; + } + + const timeRange = ctx.query.time_range || "short_term"; + + const topArtists = await customGet( + `https://api.spotify.com/v1/me/top/artists?time_range=${timeRange}&limit=50`, + session, + ); + + return { props: { topArtists: topArtists.items } }; +}; diff --git a/packages/nextjs/pages/login.tsx b/packages/nextjs/pages/login.tsx index cf1003a..ce2feec 100644 --- a/packages/nextjs/pages/login.tsx +++ b/packages/nextjs/pages/login.tsx @@ -11,7 +11,7 @@ export default function Login() { style={{ backgroundImage: `url("/assets/bg.png")`, backgroundColor: "#00011e" }} >
); diff --git a/packages/nextjs/pages/playlists/[playlistId].tsx b/packages/nextjs/pages/playlists/[playlistId].tsx index f6ac2ab..96e5d01 100644 --- a/packages/nextjs/pages/playlists/[playlistId].tsx +++ b/packages/nextjs/pages/playlists/[playlistId].tsx @@ -32,7 +32,7 @@ export default function Playlist({ playlist }: IProps) {
{playlist.type}

{playlist.name}

-

{parse(playlist.description || "")}

+

{parse(playlist.description || "Playlist")}

{playlist.owner?.display_name} From 84ad6e9669e19b5d10078c5e40cca79fd01994c6 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 20 Dec 2023 20:47:03 +0100 Subject: [PATCH 2/3] fixed typo --- packages/nextjs/pages/dashboard/overview.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/nextjs/pages/dashboard/overview.tsx b/packages/nextjs/pages/dashboard/overview.tsx index 1262734..708a074 100644 --- a/packages/nextjs/pages/dashboard/overview.tsx +++ b/packages/nextjs/pages/dashboard/overview.tsx @@ -1,4 +1,3 @@ -import { useState } from "react"; import { GetServerSideProps } from "next"; import { getSession } from "next-auth/react"; import DashboardLayout from "~~/components/dashboard/DashboardLayout"; @@ -15,15 +14,13 @@ interface IProps { } export default function FollowedArtists({ topArtists }: IProps) { - const [timeRange, setTimeRange] = useState("short_term"); - return ( e.target.value} + className="mx-2 pr-1 bg-transparent border-none rounded cursor-pointer text-base p-2 " + > + + + + + + + ); } @@ -33,6 +50,12 @@ export const getServerSideProps: GetServerSideProps = async ctx => { }, }; } + const timeRange = ctx.query.time_range || "long_term"; - return { props: { userPlaylist: [] } }; + const topArtists = await customGet( + `https://api.spotify.com/v1/me/top/artists?time_range=${timeRange}&limit=50`, + session, + ); + + return { props: { topArtists: topArtists.items } }; };