Skip to content

Commit

Permalink
fix(actions/versions): Fix clearing compared feed version.
Browse files Browse the repository at this point in the history
  • Loading branch information
binh-dam-ibigroup committed Apr 1, 2022
1 parent f538797 commit 5e857d5
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/manager/actions/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,14 +580,17 @@ export function ensureVersionIndexIsFetched (
feed: Feed,
oneBasedIndex: number
) {
return function (dispatch: dispatchFn, getState: getStateFn) {
const requestedVersion = feed.feedVersions && feed.feedVersions[oneBasedIndex - 1]
return async function (dispatch: dispatchFn, getState: getStateFn) {
console.log('Requesting version ', oneBasedIndex)
if (!oneBasedIndex || oneBasedIndex < 1) return null

const requestedVersion = feed.feedVersions && feed.feedVersions[oneBasedIndex - 1]
if (!requestedVersion) {
if (feed.feedVersionSummaries) {
// If the requested version has not been fetched yet, async fetch it.
const versionId = feed.feedVersionSummaries[oneBasedIndex - 1].id
return dispatch(fetchFeedVersion(versionId))
const { payload } = await dispatch(fetchFeedVersion(versionId))
return payload
}
}
return requestedVersion
Expand All @@ -602,7 +605,7 @@ export function setVersionIndex (
) {
return async function (dispatch: dispatchFn, getState: getStateFn) {
if (feed.feedVersionSummaries) {
const { payload: newActiveVersion } = await dispatch(ensureVersionIndexIsFetched(feed, oneBasedIndex))
const newActiveVersion = await dispatch(ensureVersionIndexIsFetched(feed, oneBasedIndex))
dispatch(setActiveVersion(newActiveVersion))
if (push) {
browserHistory.push(`${isPublic ? '/public' : ''}/feed/${feed.id}/version/${oneBasedIndex}`)
Expand All @@ -623,7 +626,7 @@ export function setComparedVersion (
oneBasedIndex: number
) {
return async function (dispatch: dispatchFn, getState: getStateFn) {
const { payload: newComparedVersion } = await dispatch(ensureVersionIndexIsFetched(feed, oneBasedIndex))
const newComparedVersion = await dispatch(ensureVersionIndexIsFetched(feed, oneBasedIndex))
// Dispatch action to set value in reducer.
dispatch(settingComparedVersion(newComparedVersion))
if (newComparedVersion) {
Expand Down

0 comments on commit 5e857d5

Please # to comment.