Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

[C-403] Fix lineup with artist pick #1246

Merged
merged 3 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/mobile/src/components/lineup/Lineup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ export const Lineup = ({
const countOrDefault = count !== undefined ? count : MAX_TILES_COUNT

const handleLoadMore = useCallback(() => {
const { deleted, entries, hasMore, page, status } = lineup
const { deleted, nullCount, entries, hasMore, page, status } = lineup

const lineupLength = entries.length
const offset = lineupLength + deleted
const offset = lineupLength + deleted + nullCount

const shouldLoadMore =
// Lineup has more items to load
Expand Down
2 changes: 2 additions & 0 deletions packages/web/src/common/models/Lineup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type Lineup<T, ExtraProps = {}> = {
}
total: number
deleted: number
nullCount: number
status: Status
hasMore: boolean
inView: boolean
Expand All @@ -29,6 +30,7 @@ export type LineupState<T> = {
order: Order
total: number
deleted: number
nullCount: number
status: Status
hasMore: boolean
inView: boolean
Expand Down
6 changes: 4 additions & 2 deletions packages/web/src/common/store/lineup/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,16 @@ export class LineupActions {
entries: unknown,
offset: number,
limit: number,
deleted: boolean
deleted: boolean,
nullCount: boolean
) {
return {
type: addPrefix(this.prefix, FETCH_LINEUP_METADATAS_SUCCEEDED),
entries,
offset,
limit,
deleted
deleted,
nullCount
}
}

Expand Down
5 changes: 4 additions & 1 deletion packages/web/src/common/store/lineup/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const initialLineupState = {
isMetadataLoading: false,
total: 0,
deleted: 0,
nullCount: 0,
status: Status.LOADING,
hasMore: true,
inView: false,
Expand Down Expand Up @@ -58,6 +59,7 @@ type FetchLineupMetadatasSucceededAction<T> = {
type: typeof FETCH_LINEUP_METADATAS_SUCCEEDED
entries: LineupStateTrack<T>[]
deleted: number
nullCount: number
limit: number
offset: number
}
Expand Down Expand Up @@ -158,7 +160,8 @@ export const actionsMap = {
} else {
newState.entries = newState.entries.concat(action.entries)
}
newState.deleted += action.deleted || 0
newState.deleted += Math.max(action.deleted || 0, 0)
newState.nullCount += Math.max(action.nullCount || 0, 0)
newState.entries.forEach((entry, i) => {
if (!entry.uid) entry.uid = `${entry.id.toString()}-${i.toString()}`
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ function* getTracks({ offset, limit, payload }) {
return pinnedTrack.concat(processed)
} else {
// If we're paginating w/ offset > 0
// just slice out the pinned track because
// we already have it.
// set the pinned track as null.
// This will be handled by `filterDeletes` via `nullCount`
if (pinnedTrackIndex !== -1) {
return processed
.slice(0, pinnedTrackIndex)
.concat(processed.slice(pinnedTrackIndex + 1))
return processed.map((track, i) =>
i === pinnedTrackIndex ? null : track
)
}
return processed
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const initialState: SearchPageState = {
order: {},
total: 0,
deleted: 0,
nullCount: 0,
status: Status.LOADING,
hasMore: true,
inView: false,
Expand Down
1 change: 1 addition & 0 deletions packages/web/src/components/lineup/Lineup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Lineup.defaultProps = {
order: {},
total: 0,
deleted: 0,
nullCount: 0,
status: Status.LOADING,
hasMore: true,
inView: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/components/lineup/LineupProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class LineupProvider extends PureComponent<CombinedProps, LineupProviderState> {
initialTrackLoadCount
} = this.state
const lineupLength = lineup.entries.length
const offset = lineupLength + lineup.deleted
const offset = lineupLength + lineup.deleted + lineup.nullCount
if (
(!limit || lineupLength !== limit) &&
loadMore &&
Expand Down
16 changes: 14 additions & 2 deletions packages/web/src/store/lineup/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ function* filterDeletes(tracksMetadata, removeDeleted) {
const users = yield select(getUsers)
return tracksMetadata
.map(metadata => {
// If the incoming metadata is null, return null
// This will be accounted for in `nullCount`
if (metadata === null) {
return null
}
// If we said to remove deleted tracks and it is deleted, remove it
if (removeDeleted && metadata.is_delete) return null
// If we said to remove deleted and the track/playlist owner is deactivated, remove it
Expand Down Expand Up @@ -157,6 +162,12 @@ function* fetchLineupMetadatasAsync(
lineupMetadatasResponse,
removeDeleted
)

const nullCount = lineupMetadatasResponse.reduce(
(result, current) => (current === null ? result + 1 : result),
0
)

const allMetadatas = responseFilteredDeletes.map(item => {
const id = item.track_id
if (id && uidForSource[id] && uidForSource[id].length > 0) {
Expand Down Expand Up @@ -240,13 +251,14 @@ function* fetchLineupMetadatasAsync(
return true
})

const deletedCount = action.limit - lineupEntries.length
const deletedCount = action.limit - lineupEntries.length - nullCount
yield put(
lineupActions.fetchLineupMetadatasSucceeded(
lineupEntries,
action.offset,
action.limit,
deletedCount
deletedCount,
nullCount
)
)

Expand Down