-
Notifications
You must be signed in to change notification settings - Fork 111
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
Fix offline collections not loading if started offline C-3187 #6245
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,39 +117,36 @@ export const useCollectionsScreenData = ({ | |
return [] | ||
} | ||
|
||
return fetchedCollectionIds.filter((collectionId) => { | ||
const collection = getCollection(state, { id: collectionId }) | ||
if (collection == null) { | ||
console.error( | ||
`Unexpected missing fetched collection: ${collectionId}` | ||
) | ||
return false | ||
} | ||
|
||
if (!isReachable) { | ||
const offlineCollectionsStatus = getOfflineCollectionsStatus(state) | ||
const offlineCollectionsStatus = getOfflineCollectionsStatus(state) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm trying to remember which parts of state here might be best to select from. When we do the initial step where we load the offline data into the store, what do we use to determine which are avail? Is it just a crawl through the directory or do we use the status like you are using here? I wonder if there is a way to add a selector to kinda say "get downloaded collections"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We definitely could roll this into a complex selector per the pattern we adopted during offline mode. |
||
const offlineCollectionIds = Object.keys(offlineCollectionsStatus).filter( | ||
(k) => offlineCollectionsStatus[k] === OfflineDownloadStatus.SUCCESS | ||
) | ||
return offlineCollectionIds | ||
.map((stringId) => Number(stringId)) | ||
.filter((collectionId) => { | ||
const collection = getCollection(state, { id: collectionId }) | ||
if (collection == null) { | ||
console.error( | ||
`Unexpected missing fetched collection: ${collectionId}` | ||
) | ||
return false | ||
} | ||
const trackIds = | ||
collection.playlist_contents.track_ids.map( | ||
(trackData) => trackData.track | ||
) ?? [] | ||
const collectionDownloadStatus = | ||
offlineCollectionsStatus[collection.playlist_id] | ||
// Don't show a playlist in Offline Mode if it has at least one track but none of the tracks have been downloaded yet OR if it is not marked for download | ||
return ( | ||
Boolean(collectionDownloadStatus) && | ||
collectionDownloadStatus !== OfflineDownloadStatus.INACTIVE && | ||
(trackIds.length === 0 || | ||
trackIds.some((t) => { | ||
return ( | ||
offlineTracksStatus && | ||
offlineTracksStatus[t.toString()] === | ||
OfflineDownloadStatus.SUCCESS | ||
) | ||
})) | ||
trackIds.length === 0 || | ||
trackIds.some((t) => { | ||
return ( | ||
offlineTracksStatus && | ||
offlineTracksStatus[t.toString()] === | ||
OfflineDownloadStatus.SUCCESS | ||
) | ||
}) | ||
) | ||
} | ||
return true | ||
}) | ||
}) | ||
}, | ||
[ | ||
fetchedCollectionIds, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before the library work,
fetchedCollectionIds
was always populated even when offline bc we were using the collections value in the account object. Now,fetchedCollectionIds
always comes from API (since we can't rely on the account object collections, since they only include the user's Favorites), so it'll be empty if we start the session offline. So to fix the issue we can just gather the downloaded collection IDS from theofflineCollectionStatus
data in the store.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this change and makes a ton of sense