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/track page #152

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@ MUSICRITIC_PROD_FIREBASE_PROJECT_ID=
MUSICRITIC_PROD_FIREBASE_DATABASE_URL=
MUSICRITIC_PROD_FIREBASE_APP_ID=
MUSICRITIC_PROD_FIREBASE_AUTH_DOMAIN=
MUSICRITIC_PROD_FIREBASE_API_KEY=


MUSICRITIC_PROD_FIREBASE_API_KEY=
2 changes: 1 addition & 1 deletion firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"ui": {
"enabled": true,
"port": 5000
jonathasbsouza marked this conversation as resolved.
Show resolved Hide resolved
"port": 6000
}
}
}
3 changes: 3 additions & 0 deletions next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/// <reference types="next" />
/// <reference types="next/types/global" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
58 changes: 58 additions & 0 deletions pages/tracks/[id].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import type {
GetStaticPaths,
GetStaticProps,
GetStaticPropsContext,
} from 'next'
import type { FC } from 'react'
import type { Track } from 'spotify-web-sdk'
import { useRouter } from 'next/router'

import spotify from '@/node/lib/spotify'
import PageHeader from '@/components/common/PageHeader'
import TrackMetadata from '@/components/track/TrackMetadata'

export const getStaticPaths: GetStaticPaths = async () => {
return {
paths: [],
fallback: true,
}
}

export const getStaticProps: GetStaticProps = async (
context: GetStaticPropsContext
) => {
const trackId = (context.params?.id as string) ?? ''
const trackInfo = await spotify.getTrack(trackId)

return {
props: { trackInfo: JSON.parse(JSON.stringify(trackInfo.toJSON())) },
}
}

interface Props {
trackInfo: Track
}

const TrackPage: FC<Props> = ({ trackInfo }) => {
const { isFallback: isLoading } = useRouter()

return (
<PageHeader
imgUrl={trackInfo?.album?.imageUrl ?? ''}
imgAlt={trackInfo?.albumName ?? ''}
rating={10}
loading={isLoading}
>
<TrackMetadata
name={trackInfo?.name}
artist={trackInfo?.stringArtists}
album={trackInfo?.albumName}
length={trackInfo?.length}
releaseDate={trackInfo?.album.releaseDate}
spotifyUrl={trackInfo?.uri}
/>
</PageHeader>
)
}

export default TrackPage
2 changes: 1 addition & 1 deletion react/components/album/AlbumPageHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { ThemeUIStyleObject } from 'theme-ui'
import Skeleton from '@/components/common/Skeleton'
import SkeletonImage from '@/components/common/SkeletonImage'

import AlbumRatingBadge from './AlbumRatingBadge'
import AlbumRatingBadge from '../../common/RatingBadge'
import AlbumMetadata from './AlbumMetadata'

const containerStyles: ThemeUIStyleObject = {
Expand Down
50 changes: 50 additions & 0 deletions react/components/common/PageHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Flex } from '@theme-ui/components'
import type { ThemeUIStyleObject } from 'theme-ui'
import type { PropsWithChildren } from 'hoist-non-react-statics/node_modules/@types/react'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import type { PropsWithChildren } from 'hoist-non-react-statics/node_modules/@types/react'
import type { PropsWithChildren } from 'react'


import RatingBadge from '@/components/common/RatingBadge'
import SkeletonImage from '@/components/common/SkeletonImage'

const containerStyles: ThemeUIStyleObject = {
flexDirection: ['column', 'column', 'row'],
backgroundColor: 'muted.0',
width: '100%',
padding: [3, 4, 6, 16],
justifyContent: 'space-between',
alignItems: 'center',
}

interface Props {
imgUrl: string
imgAlt: string
loading?: boolean
rating?: number
}

const PageHeader = ({
imgUrl,
imgAlt,
rating = 5,
loading = false,
children,
}: PropsWithChildren<Props>) => {
return (
<Flex sx={containerStyles}>
<Flex sx={{ alignItems: 'center' }}>
<Flex sx={{ marginRight: 4 }}>
<SkeletonImage
loading={loading}
alt={imgAlt}
src={imgUrl}
height={280}
width={280}
/>
</Flex>
{children}
</Flex>
<RatingBadge rating={rating} />
</Flex>
)
}

export default PageHeader
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ interface Props {
rating: number
}

const AlbumRatingBadge: FC<Props> = ({ rating }) => (
const RatingBadge: FC<Props> = ({ rating }) => (
<Badge sx={ratingBadgeStyles}>{rating}</Badge>
)

export default AlbumRatingBadge
export default RatingBadge
60 changes: 60 additions & 0 deletions react/components/track/TrackMetadata/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Box, Heading, Link } from '@theme-ui/components'
import { defineMessages, FormattedDate, FormattedMessage } from 'react-intl'

const messages = defineMessages({
byArtists: { id: 'musicritic.album-page.by-artists' },
releaseDate: { id: 'musicritic.album-page.release-date' },
openOnSpotify: { id: 'musicritic.album-page.open-on-spotify' },
})

interface Props {
name: string
artist: string
album: string
length: string
releaseDate: string
spotifyUrl: string
}

const TrackMetadata = ({
name,
artist,
album,
length,
releaseDate,
spotifyUrl,
}: Props) => {
const formattedReleaseDate = (
<FormattedDate
value={releaseDate}
year="numeric"
month="long"
day="2-digit"
/>
)

return (
<Box>
<Heading variant="title">{name}</Heading>
<Heading variant="subtitle">
<FormattedMessage
{...messages.byArtists}
values={{ artists: artist }}
/>
</Heading>
<Box>{album}</Box>
<Box sx={{ marginBottom: 4 }}>
<FormattedMessage
{...messages.releaseDate}
values={{ date: formattedReleaseDate }}
/>{' '}
· {length}
</Box>
<Link href={spotifyUrl ?? '/'} variant="button">
<FormattedMessage {...messages.openOnSpotify} />
</Link>
</Box>
)
}

export default TrackMetadata
1 change: 1 addition & 0 deletions react/providers/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const theme: Theme | Record<string, ThemeUIStyleObject> = {
},
links: {
button: {
display: 'inline-block',
border: '1px solid',
borderColor: 'muted.4',
color: 'muted.4',
Expand Down