From 9e4b90f7c058aa85ebaf7cc4af1e1592c870db1d Mon Sep 17 00:00:00 2001 From: Dylan Jeffers Date: Tue, 14 Feb 2023 21:46:23 -0800 Subject: [PATCH] [C-2141] Fix missing lineup when coming back online (#2863) Co-authored-by: Andrew Mendelsohn Co-authored-by: Sebastian Klingler --- .../collection-screen/CollectionHeader.tsx | 4 ++- packages/web/src/common/store/lineup/sagas.js | 32 +++++++++++++------ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/packages/mobile/src/screens/collection-screen/CollectionHeader.tsx b/packages/mobile/src/screens/collection-screen/CollectionHeader.tsx index 9720beb4e2..bb81fa0067 100644 --- a/packages/mobile/src/screens/collection-screen/CollectionHeader.tsx +++ b/packages/mobile/src/screens/collection-screen/CollectionHeader.tsx @@ -160,6 +160,8 @@ const OfflineCollectionHeader = (props: OfflineCollectionHeaderProps) => { [playlist_id, downloadSwitchValue] ) + const isReachable = useSelector(getIsReachable) + const showDownloadSwitchAndIndicator = collection.has_current_user_saved || collection.playlist_owner_id === currentUserId @@ -214,7 +216,7 @@ const OfflineCollectionHeader = (props: OfflineCollectionHeaderProps) => { weight='demiBold' fontSize='small' > - {downloadStatus === OfflineDownloadStatus.LOADING + {downloadStatus === OfflineDownloadStatus.LOADING && isReachable ? messages.downloading : headerText} diff --git a/packages/web/src/common/store/lineup/sagas.js b/packages/web/src/common/store/lineup/sagas.js index c088ed6007..58484e31a3 100644 --- a/packages/web/src/common/store/lineup/sagas.js +++ b/packages/web/src/common/store/lineup/sagas.js @@ -24,7 +24,8 @@ import { take, takeEvery, takeLatest, - getContext + getContext, + race } from 'redux-saga/effects' import { getToQueue } from 'common/store/queue/sagas' @@ -122,7 +123,7 @@ function* fetchLineupMetadatasAsync( ) : initLineup.prefix - const task = yield fork(function* () { + function* fetchLineupMetadatasTask() { try { yield put( lineupActions.fetchLineupMetadatasRequested( @@ -284,15 +285,26 @@ function* fetchLineupMetadatasAsync( console.error(err) yield put(lineupActions.fetchLineupMetadatasFailed()) } - }) - const { source: resetSource } = yield take( - baseLineupActions.addPrefix(lineupPrefix, baseLineupActions.RESET) - ) - // If a source is specified in the reset action, make sure it matches the lineup source - // If not specified, cancel the fetchTrackMetdatas - if (!resetSource || resetSource === initSource) { - yield cancel(task) } + + function* shouldCancelTask() { + while (true) { + const { source: resetSource } = yield take( + baseLineupActions.addPrefix(lineupPrefix, baseLineupActions.RESET) + ) + + // If a source is specified in the reset action, make sure it matches the lineup source + // If not specified, cancel the fetchTrackMetdatas + if (!resetSource || resetSource === initSource) { + return true + } + } + } + + yield race({ + task: call(fetchLineupMetadatasTask), + cancel: call(shouldCancelTask) + }) } function* updateQueueLineup(lineupPrefix, source, lineupEntries) {