Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion packages/web/src/common/store/upload/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ import {
albumMetadataForSDK,
fileToSdk,
playlistMetadataForCreateWithSDK,
stemTrackMetadataFromSDK,
trackMetadataForUploadToSdk,
transformAndCleanList,
userCollectionMetadataFromSDK
} from '@audius/common/adapters'
import { queryUser } from '@audius/common/api'
import { getStemsQueryKey, queryUser } from '@audius/common/api'
import {
Collection,
Feature,
FieldVisibility,
ID,
Kind,
Name,
StemTrack,
StemUploadWithFile,
isContentFollowGated,
isContentUSDCPurchaseGated
Expand Down Expand Up @@ -414,6 +416,8 @@ export function* handleUploads({
kind: 'album' | 'playlist' | 'tracks' | 'stems'
}) {
const isCollection = kind === 'album' || kind === 'playlist'
const queryClient = yield* getContext('queryClient')
const userId = (yield* select(getUserId))!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

! makes me nervous but ok


// Queue for the upload tasks (uploading files to storage)
const uploadQueue = yield* call(
Expand Down Expand Up @@ -530,6 +534,27 @@ export function* handleUploads({
{ trackIndex, stemIndex }
)

if (payload.metadata.stemOf?.parentTrackId) {
const parentTrackId = payload.metadata.stemOf.parentTrackId

queryClient.setQueryData(
getStemsQueryKey(parentTrackId),
(currentStems: StemTrack[] | undefined) => {
const newStem = stemTrackMetadataFromSDK({
...payload.metadata,
id: Id.parse(parentTrackId + (payload.trackIndex + 1 + Date.now())),
parentId: Id.parse(parentTrackId),
userId: Id.parse(userId),
blocknumber: 0,
cid: '',
category: payload.metadata.stemOf!.category!,
origFilename: payload.metadata.origFilename!
})
return [...(currentStems ?? []), newStem!]
}
)
}

// We know trackId exists because we generate it in uploadMultipleTracks
const trackId = metadata.trackId!
const stemCount = pendingStemCount[trackId]
Expand Down
37 changes: 27 additions & 10 deletions packages/web/src/components/track/DownloadSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import {
IconReceive,
Button,
IconCaretDown,
IconLockUnlocked
IconLockUnlocked,
LoadingSpinner
} from '@audius/harmony'
import { useDispatch } from 'react-redux'

Expand Down Expand Up @@ -88,6 +89,12 @@ export const DownloadSection = ({ trackId }: DownloadSectionProps) => {
shouldDisplayOwnerPremiumDownloads
} = useDownloadableContentAccess({ trackId })

// Filter out uploading stems that are already in the stemTracks array
const filteredUploadingStems = uploadingStems.filter(
(s) => !stemTracks.find((t) => t.orig_filename === s.name)
)
const isUploadingStems = filteredUploadingStems.length > 0

const { isEnabled: isDownloadAllTrackFilesEnabled } = useFeatureFlag(
FeatureFlags.DOWNLOAD_ALL_TRACK_FILES
)
Expand Down Expand Up @@ -179,6 +186,18 @@ export const DownloadSection = ({ trackId }: DownloadSectionProps) => {
[trackId, stemTracks]
)

const renderDownloadAllButton = () => {
if (shouldHideDownload || !isDownloadAllTrackFilesEnabled) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we just get rid of this feature flag yet?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

probably lol

return null
}

return (
<Button variant='secondary' size='small' onClick={handleDownloadAll}>
{messages.downloadAll}
</Button>
)
}

return (
<Box border='default' borderRadius='m' css={{ overflow: 'hidden' }}>
<Flex column>
Expand Down Expand Up @@ -229,14 +248,10 @@ export const DownloadSection = ({ trackId }: DownloadSectionProps) => {
gap='m'
role='row'
>
{shouldHideDownload || !isDownloadAllTrackFilesEnabled ? null : (
<Button
variant='secondary'
size='small'
onClick={handleDownloadAll}
>
{messages.downloadAll}
</Button>
{isUploadingStems ? (
<LoadingSpinner size='xl' />
) : (
renderDownloadAllButton()
)}

{shouldDisplayPremiumDownloadUnlocked ? (
Expand Down Expand Up @@ -297,6 +312,8 @@ export const DownloadSection = ({ trackId }: DownloadSectionProps) => {
trackId={stemTrack.track_id}
parentTrackId={trackId}
key={stemTrack.track_id}
category={stemTrack.stem_of?.category}
filename={stemTrack.orig_filename ?? undefined}
onDownload={handleDownload}
hideDownload={shouldHideDownload}
size={fileSizes?.[stemTrack.track_id]?.[downloadQuality]}
Expand All @@ -308,7 +325,7 @@ export const DownloadSection = ({ trackId }: DownloadSectionProps) => {
}
/>
))}
{uploadingStems.map((s, i) => (
{filteredUploadingStems.map((s, i) => (
<DownloadRow
key={`uploading-stem-${i}`}
onDownload={() => {}}
Expand Down