Skip to content

Commit

Permalink
[C-3821] Fix native double save (#7609)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjeffers authored Feb 15, 2024
1 parent 75925a9 commit 862c9e6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/mobile/src/screens/favorites-screen/TracksTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export const TracksTab = () => {
// Need to fetch saves when the filterValue or selectedCategory (by way of fetchSaves) changes
if (isReachable) {
fetchSaves()
setFetchPage((fetchPage) => fetchPage + 1)
}
}, [isReachable, fetchSaves])

Expand Down
24 changes: 17 additions & 7 deletions packages/web/src/common/store/pages/saved/lineups/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ function* getTracks({ offset, limit }: { offset: number; limit: number }) {
}, {})

const localLibraryAdditions = yield* select(getSelectedCategoryLocalTrackAdds)
const localLibraryAdditionsTrackIds = Object.keys(
localLibraryAdditions
).filter((savedTrackId) => !savedTrackTimestamps[savedTrackId])
const localLibraryAdditionsTrackIds = Object.keys(localLibraryAdditions)
.filter((savedTrackId) => !savedTrackTimestamps[savedTrackId])
.map((trackId) => Number(trackId))

const localLibraryAdditionsTimestamps = localLibraryAdditionsTrackIds.reduce(
(map, saveId) => {
map[saveId] = Date.now()
Expand All @@ -71,10 +72,19 @@ function* getTracks({ offset, limit }: { offset: number; limit: number }) {
{}
)

const allSavedTrackIds = uniq([
...localLibraryAdditionsTrackIds,
...savedTrackIds
])
let allSavedTrackIds: (number | string)[] = []

if (isNativeMobile && offset !== 0) {
allSavedTrackIds = savedTrackIds.filter(
(s) => !localLibraryAdditionsTrackIds.includes(s)
)
} else {
allSavedTrackIds = uniq([
...localLibraryAdditionsTrackIds,
...savedTrackIds
])
}

const allSavedTrackTimestamps = {
...localLibraryAdditionsTimestamps,
...savedTrackTimestamps
Expand Down

0 comments on commit 862c9e6

Please sign in to comment.