Skip to content

Commit

Permalink
Fix upload collection C-2630 (#3404)
Browse files Browse the repository at this point in the history
Co-authored-by: Nikki Kang <kangaroo233@gmail.com>
  • Loading branch information
nicoback2 and nicoback authored May 23, 2023
1 parent aee7653 commit 2cba881
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
cacheCollectionsActions,
cacheCollectionsSelectors,
cacheTracksSelectors,
decodeHashId,
getContext,
makeKindId,
newCollectionMetadata
Expand All @@ -30,6 +29,7 @@ import { playlistPage } from 'utils/route'
import { waitForWrite } from 'utils/sagaHelpers'

import { reformat } from './utils'
import { getUnclaimedPlaylistId } from './utils/getUnclaimedPlaylistId'

const { getAccountUser } = accountSelectors
const { getTrack } = cacheTracksSelectors
Expand Down Expand Up @@ -73,19 +73,6 @@ function* createPlaylistWorker(
)
}

function* getUnclaimedPlaylistId() {
const { getAudiusLibsTyped } = yield* getContext('audiusBackendInstance')
const audiusLibs = yield* call(getAudiusLibsTyped)
if (!audiusLibs.discoveryProvider) return

const unclaimedId = yield* call(
[audiusLibs.discoveryProvider, audiusLibs.discoveryProvider.getUnclaimedId],
'playlists'
)
if (!unclaimedId) return
return decodeHashId(unclaimedId)
}

function* optimisticalySavePlaylist(
playlistId: ID,
formFields: Partial<CollectionMetadata>,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { decodeHashId, getContext } from '@audius/common'
import { call } from 'typed-redux-saga'

export function* getUnclaimedPlaylistId() {
const { getAudiusLibsTyped } = yield* getContext('audiusBackendInstance')
const audiusLibs = yield* call(getAudiusLibsTyped)
if (!audiusLibs.discoveryProvider) return

const unclaimedId = yield* call(
[audiusLibs.discoveryProvider, audiusLibs.discoveryProvider.getUnclaimedId],
'playlists'
)
if (!unclaimedId) return
return decodeHashId(unclaimedId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { reformat } from './reformat'
export { retrieveCollections } from './retrieveCollections'
export { retrieveCollectionByPermalink } from './retrieveCollections'
export { processAndCacheCollections } from './processAndCacheCollections'
export { getUnclaimedPlaylistId } from './getUnclaimedPlaylistId'
16 changes: 14 additions & 2 deletions packages/web/src/common/store/upload/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ import {
} from 'redux-saga/effects'

import { make } from 'common/store/analytics/actions'
import { reformat } from 'common/store/cache/collections/utils'
import {
getUnclaimedPlaylistId,
reformat
} from 'common/store/cache/collections/utils'
import { trackNewRemixEvent } from 'common/store/cache/tracks/sagas'
import * as confirmerActions from 'common/store/confirmer/actions'
import { confirmTransaction } from 'common/store/confirmer/sagas'
Expand Down Expand Up @@ -705,6 +708,14 @@ function* uploadCollection(tracks, userId, collectionMetadata, isAlbum) {
return
}

const playlistId = yield call(getUnclaimedPlaylistId)
if (error) {
console.debug(
'Error getting an unclaimed playlist id, not going to create a playlist.'
)
return
}

// Finally, create the playlist
yield put(
confirmerActions.requestConfirmation(
Expand All @@ -713,8 +724,9 @@ function* uploadCollection(tracks, userId, collectionMetadata, isAlbum) {
console.debug('Creating playlist')
// Uploaded collections are always public
const isPrivate = false
const { blockHash, blockNumber, playlistId, error } = yield call(
const { blockHash, blockNumber, error } = yield call(
audiusBackendInstance.createPlaylist,
playlistId,
collectionMetadata,
isAlbum,
trackIds,
Expand Down

0 comments on commit 2cba881

Please sign in to comment.