Skip to content

Commit

Permalink
[C-3152] Fix remove artwork (#6392)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjeffers authored Oct 19, 2023
1 parent 3b2c93b commit e81e86f
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/common/src/api/suggestedTracks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type SuggestedTrack =
| { isLoading: false; id: ID; track: Track; key: ID }

const skeletons = [...Array(5)].map((_, index) => ({
key: index,
key: index + 5,
isLoading: true as const
}))

Expand Down
4 changes: 4 additions & 0 deletions packages/common/src/store/pages/collection/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export const getCollection = (
return getSmartCollection(state, { variant: smartCollectionVariant })
}

if (params?.id) {
return getCachedCollection(state, params)
}

const permalink = getCollectionPermalink(state)
if (permalink) {
return getCachedCollection(state, { permalink })
Expand Down
5 changes: 3 additions & 2 deletions packages/mobile/src/hooks/useContentNodeImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const createAllImageSources = ({
cidMap?: Nullable<{ [key: string]: string }>
}) => {
if (!cid || !endpoints) {
if (localSource) return [localSource]
return []
}
let cidForSize: Nullable<string> = null
Expand Down Expand Up @@ -156,8 +157,8 @@ export const useContentNodeImage = (
}, [imageSourceIndex, imageSources])

const showFallbackImage = useMemo(() => {
return !cid || failedToLoad
}, [failedToLoad, cid])
return (!cid && !localSource) || failedToLoad
}, [failedToLoad, localSource, cid])

const source = useMemo(() => {
if (showFallbackImage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ type PickArtworkFieldProps = {

export const PlaylistArtworkField = (props: PickArtworkFieldProps) => {
const { name } = props
const [{ value: artworkUrl }, , { setValue: setArtwork }] = useField(name)
const [{ value: artwork }, , { setValue: setArtwork }] = useField(name)
const { url: artworkUrl } = artwork
const [{ value: collectionId }] = useField('playlist_id')
const [{ value: isImageAutogenerated }, , { setValue: setIsAutogenerated }] =
useField('is_image_autogenerated')
const [{ value: track_count }] = useField('track_count')
const generatePlaylistArtwork = useGeneratePlaylistArtwork(collectionId)
const { status, setStatus } = useFormikContext()

Expand All @@ -40,17 +42,20 @@ export const PlaylistArtworkField = (props: PickArtworkFieldProps) => {
setStatus({ imageGenerating: false })
}, [setStatus])

const shouldRemoveArtwork =
artworkUrl && !isImageAutogenerated && track_count > 0

return (
<PickArtworkField
{...props}
onPress={artworkUrl && !isImageAutogenerated ? handleRemove : undefined}
onPress={shouldRemoveArtwork ? handleRemove : undefined}
onChange={handleChange}
buttonTitle={
status.imageGenerating && isImageAutogenerated
? messages.updatingArtwork
: artworkUrl && status.imageGenerating
? messages.removingArtwork
: artworkUrl && !isImageAutogenerated
: shouldRemoveArtwork
? messages.removeArtwork
: undefined
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ function* addTrackToPlaylistAsync(action: AddTrackToPlaylistAction) {

yield* put(event)

yield* call(optimisticUpdateCollection, { ...playlist, track_count: count })
yield* call(
confirmAddTrackToPlaylist,
userId,
Expand All @@ -120,7 +121,6 @@ function* addTrackToPlaylistAsync(action: AddTrackToPlaylistAction) {
playlist
)

yield* call(optimisticUpdateCollection, { ...playlist, track_count: count })
yield* put(
cacheActions.subscribe(Kind.TRACKS, [{ uid: trackUid, id: action.trackId }])
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ function* editPlaylistAsync(action) {
{ audiusBackend, generateImage: generatePlaylistArtwork }
)

yield call(optimisticUpdateCollection, playlist)
yield call(confirmEditPlaylist, playlistId, userId, playlist)

yield call(optimisticUpdateCollection, playlist)
yield put(collectionActions.editPlaylistSucceeded())
yield put(toast({ content: messages.editToast }))
}
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/common/store/pages/collection/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function* watchFetchCollection() {
collection.playlist_contents.track_ids.length
)
)
if (fetchLineup) {
if (fetchLineup && collection.track_count > 0) {
yield put(tracksActions.fetchLineupMetadatas(0, 200, false, undefined))
}
} else {
Expand Down

0 comments on commit e81e86f

Please sign in to comment.