-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed multiple fetches of docmap data
- Loading branch information
Showing
3 changed files
with
84 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import httpClient from '../lib/http' | ||
import { BASE_URL } from '../lib/http' | ||
import { parseDocmaps } from '@source-data/render-rev' | ||
|
||
const docmapsApiPath = (doi) => `${BASE_URL}/api/v2/docmap/${doi}` | ||
|
||
export const byArticleId = { | ||
namespaced: true, | ||
state: { | ||
reviewProcesses: {}, | ||
}, | ||
getters: { | ||
getReviewProcessForDoi: (state) => (doi) => { | ||
const data = state.reviewProcesses[doi] | ||
if (!data) { | ||
return undefined | ||
} | ||
const { reviewProcess } = data | ||
return reviewProcess | ||
} | ||
}, | ||
mutations: { | ||
setReviewProcessForDoi(state, {doi, data}) { | ||
state.reviewProcesses[doi] = data | ||
}, | ||
}, | ||
actions: { | ||
async fetchReviewProcessForDoi({ commit, state }, doi) { | ||
if (state.reviewProcesses[doi]) { | ||
const { promise } = state.reviewProcesses[doi] | ||
return promise | ||
} | ||
// First we get the docmaps | ||
const url = docmapsApiPath(doi) | ||
const promise = httpClient.get(url) | ||
.then((response) => parseDocmaps(response.data)) | ||
.then((reviewProcess) => { | ||
const data = { promise: Promise.resolve(), reviewProcess } | ||
commit('setReviewProcessForDoi', {doi, data}) | ||
}) | ||
.catch(function (error) { | ||
if (error.response.status === 400) { | ||
commit("setSnack", | ||
{ message: "snack.message.error.request", | ||
color: "red" }, | ||
{ root: true }); | ||
} else { | ||
commit("setSnack", | ||
{ message: "snack.message.error.server", | ||
color: "red" }, | ||
{ root: true }); | ||
} | ||
}) | ||
const data = { promise, reviewProcess: undefined } | ||
commit('setReviewProcessForDoi', {doi, data}) | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters