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

Commit

Permalink
Move setCollectionPermalink within fetchCollectionSucceeded action (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sabrina-kiam authored Aug 15, 2023
1 parent 9165c76 commit 594b5c4
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 24 deletions.
8 changes: 2 additions & 6 deletions packages/common/src/store/pages/collection/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ export const RESET_COLLECTION = 'RESET_COLLECTION'
export const RESET_AND_FETCH_COLLECTION_TRACKS =
'RESET_AND_FETCH_COLLECTION_TRACKS'
export const SET_SMART_COLLECTION = 'SET_SMART_COLLECTION'
export const SET_COLLECTION_PERMALINK = 'SET_COLLECTION_PERMALINK'

export const setCollectionPermalink = (permalink: string) => ({
type: SET_COLLECTION_PERMALINK,
permalink
})

export const fetchCollection = (
id: Nullable<number>,
Expand All @@ -29,11 +23,13 @@ export const fetchCollection = (
export const fetchCollectionSucceeded = (
collectionId: ID,
collectionUid: string,
collectionPermalink: string,
userUid: string
) => ({
type: FETCH_COLLECTION_SUCCEEDED,
collectionId,
collectionUid,
collectionPermalink,
userUid
})

Expand Down
15 changes: 5 additions & 10 deletions packages/common/src/store/pages/collection/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import {
FETCH_COLLECTION_SUCCEEDED,
FETCH_COLLECTION_FAILED,
RESET_COLLECTION,
SET_SMART_COLLECTION,
SET_COLLECTION_PERMALINK
SET_SMART_COLLECTION
} from './actions'
import { PREFIX as tracksPrefix } from './lineup/actions'

Expand All @@ -22,7 +21,8 @@ export const initialState = {
userUid: null,
status: null,
smartCollectionVariant: null,
tracks: initialLineupState
tracks: initialLineupState,
collectionPermalink: null
}

const actionsMap = {
Expand All @@ -33,19 +33,14 @@ const actionsMap = {
smartCollectionVariant: null
}
},
[SET_COLLECTION_PERMALINK](state, action) {
return {
...state,
permalink: action.permalink
}
},
[FETCH_COLLECTION_SUCCEEDED](state, action) {
return {
...state,
collectionId: action.collectionId,
collectionUid: action.collectionUid,
userUid: action.userUid,
status: Status.SUCCESS
status: Status.SUCCESS,
collectionPermalink: action.collectionPermalink
}
},
[FETCH_COLLECTION_FAILED](state, action) {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/store/pages/collection/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const getCollectionStatus = (state: CommonState) =>
export const getSmartCollectionVariant = (state: CommonState) =>
state.pages.collection.smartCollectionVariant
export const getCollectionPermalink = (state: CommonState) =>
state.pages.collection.permalink
state.pages.collection.collectionPermalink
export const getCollection = (state: CommonState, params?: { id: ID }) => {
const smartCollectionVariant = getSmartCollectionVariant(state)
if (smartCollectionVariant) {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/store/pages/collection/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type CollectionTrack = LineupTrack & { dateAdded: Moment } & {
}

export type CollectionsPageState = {
permalink: string
collectionPermalink: string
collectionId: ID | null
collectionUid: UID | null
status: Status | null
Expand Down
1 change: 1 addition & 0 deletions packages/web/src/common/store/pages/collection/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ function* watchFetchCollection() {
fetchCollectionSucceeded(
collection.playlist_id,
collectionUid,
collection.permalink,
userUid,
collection.playlist_contents.track_ids.length
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,12 @@ class CollectionPage extends Component<
if (metadata && metadata._moved && !updatingRoute) {
this.setState({ updatingRoute: true })
const collectionId = Uid.fromString(metadata._moved).id
// TODO: Put fetch collection succeeded and then replace route
fetchCollectionSucceeded(collectionId, metadata._moved, userUid)
fetchCollectionSucceeded(
collectionId,
metadata._moved,
metadata.permalink || '',
userUid
)
const newPath = pathname.replace(
`${metadata.playlist_id}`,
collectionId.toString()
Expand Down Expand Up @@ -364,7 +368,6 @@ class CollectionPage extends Component<
if (params?.permalink) {
const { permalink, collectionId } = params
if (forceFetch || params.permalink) {
this.props.setCollectionPermalink(permalink)
this.props.fetchCollection(collectionId, permalink)
this.props.fetchTracks()
}
Expand All @@ -389,7 +392,6 @@ class CollectionPage extends Component<

resetCollection = () => {
const { collectionUid, userUid } = this.props
this.props.setCollectionPermalink('')
this.props.resetCollection(collectionUid, userUid)
}

Expand Down Expand Up @@ -875,8 +877,6 @@ function mapDispatchToProps(dispatch: Dispatch) {
dispatch(collectionActions.fetchCollection(id, permalink)),
fetchTracks: () =>
dispatch(tracksActions.fetchLineupMetadatas(0, 200, false, undefined)),
setCollectionPermalink: (permalink: string) =>
dispatch(collectionActions.setCollectionPermalink(permalink)),
resetCollection: (collectionUid: string, userUid: string) =>
dispatch(collectionActions.resetCollection(collectionUid, userUid)),
goToRoute: (route: string) => dispatch(pushRoute(route)),
Expand Down Expand Up @@ -977,12 +977,14 @@ function mapDispatchToProps(dispatch: Dispatch) {
fetchCollectionSucceeded: (
collectionId: ID,
collectionUid: string,
collectionPermalink: string,
userId: string
) =>
dispatch(
collectionActions.fetchCollectionSucceeded(
collectionId,
collectionUid,
collectionPermalink,
userId
)
),
Expand Down

0 comments on commit 594b5c4

Please sign in to comment.