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: Add in view for what projects a particular stem has been used o… #225

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 3 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
41 changes: 39 additions & 2 deletions pages/stems/[id].tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { /*Loop,*/ PauseRounded, PlayArrowRounded } from '@mui/icons-material'
import { Box, Container, Divider, Fab, Typography } from '@mui/material'
import { Box, Container, Divider, Fab, Grid, Typography } from '@mui/material'
import type { GetServerSideProps, NextPage } from 'next'
// Because our stem player uses Web APIs for audio, we must ignore it for SSR to avoid errors
import dynamic from 'next/dynamic'
Expand All @@ -8,8 +8,11 @@ import Link from 'next/link'
import PropTypes from 'prop-types'
import { useState } from 'react'

import ProjectCard from '../../components/ProjectCard'
import { IProjectDoc } from '../../models/project.model'
import { IStemDoc } from '../../models/stem.model'
import { detailsStyles as styles } from '../../styles/Stems.styles'
import userProfileStyles from '../../styles/UserProfile.styles'
import formatDate from '../../utils/formatDate'
import formatStemName from '../../utils/formatStemName'
import { get } from '../../utils/http'
Expand All @@ -23,12 +26,17 @@ const propTypes = {
filetype: PropTypes.string.isRequired,
metadataUrl: PropTypes.string.isRequired,
}),
projects: PropTypes.arrayOf(
PropTypes.shape({
_id: PropTypes.string.isRequired,
}),
),
}

type StemDetailsPageProps = PropTypes.InferProps<typeof propTypes>

const StemDetailsPage: NextPage<StemDetailsPageProps> = props => {
const { data } = props
const { data, projects } = props
const [waves, setWaves] = useState<any>(null)
const [isPlaying, setIsPlaying] = useState<boolean>(false)
// const [isLooping, setIsLooping] = useState<boolean>(false)
Expand Down Expand Up @@ -149,6 +157,30 @@ const StemDetailsPage: NextPage<StemDetailsPageProps> = props => {
Sorry, no details were found for this stem.
</Typography>
)}

<Divider light sx={userProfileStyles.divider} />
<Typography variant="h4" gutterBottom>
Collaborations
<Typography component="span" sx={userProfileStyles.sectionCount}>
({projects && projects.length ? 0 : ''})
0xlws marked this conversation as resolved.
Show resolved Hide resolved
</Typography>
</Typography>
<Typography sx={userProfileStyles.sectionMeta}>Projects this stem has been used on.</Typography>
0xlws marked this conversation as resolved.
Show resolved Hide resolved
<Grid container spacing={4}>
{projects && projects.length > 0 ? (
projects.map(project => (
<Grid item sm={6} md={4} key={project?._id}>
<ProjectCard details={project} />
</Grid>
))
) : (
<Grid item xs={12}>
<Typography sx={userProfileStyles.noItemsMsg}>
This stem has not been used in any projects yet.
</Typography>
</Grid>
)}
</Grid>
</Container>
</>
)
Expand All @@ -158,9 +190,14 @@ export const getServerSideProps: GetServerSideProps = async context => {
const stemId = context.query.id
const res = await get(`/stems/${stemId}`)
const data: IStemDoc | null = res.success ? res.data : null

// Get all Projects
const result = await get(`/projects`)
const projects: IProjectDoc[] | null = result.success ? result.data : null
0xlws marked this conversation as resolved.
Show resolved Hide resolved
return {
props: {
data,
projects,
},
}
}
Expand Down