pass host to api functions from state

This commit is contained in:
bill bittner 2018-03-15 16:31:01 -07:00
parent 097e454069
commit acd36414f5
7 changed files with 23 additions and 17 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
import Request from 'utils/request';
export function getLongClaimId (name, modifier) {
export function getLongClaimId (host, name, modifier) {
let body = {};
// create request params
if (modifier) {
@ -18,17 +18,17 @@ export function getLongClaimId (name, modifier) {
body : JSON.stringify(body),
};
// create url
const url = `/api/claim/long-id`;
const url = `${host}/api/claim/long-id`;
// return the request promise
return Request(url, params);
};
export function getShortId (name, claimId) {
const url = `/api/claim/short-id/${claimId}/${name}`;
export function getShortId (host, name, claimId) {
const url = `${host}/api/claim/short-id/${claimId}/${name}`;
return Request(url);
};
export function getClaimData (name, claimId) {
const url = `/api/claim/data/${name}/${claimId}`;
export function getClaimData (host, name, claimId) {
const url = `${host}/api/claim/data/${name}/${claimId}`;
return Request(url);
};

View file

@ -3,6 +3,7 @@ import * as actions from 'constants/show_action_types';
import { addRequestToRequestList, onRequestError, onRequestUpdate, addAssetToAssetList } from 'actions/show';
import { getLongClaimId, getShortId, getClaimData } from 'api/assetApi';
import { selectShowState } from 'selectors/show';
import { selectSiteHost } from 'selectors/site';
export function * newAssetRequest (action) {
const { requestType, requestId, name, modifier } = action.data;
@ -11,13 +12,14 @@ export function * newAssetRequest (action) {
// is this an existing request?
// If this uri is in the request list, it's already been fetched
const state = yield select(selectShowState);
const host = yield select(selectSiteHost);
if (state.requestList[requestId]) {
return null;
}
// get long id && add request to request list
let longId;
try {
({data: longId} = yield call(getLongClaimId, name, modifier));
({data: longId} = yield call(getLongClaimId, host, name, modifier));
} catch (error) {
return yield put(onRequestError(error.message));
}
@ -31,14 +33,14 @@ export function * newAssetRequest (action) {
// get short Id
let shortId;
try {
({data: shortId} = yield call(getShortId, name, longId));
({data: shortId} = yield call(getShortId, host, name, longId));
} catch (error) {
return yield put(onRequestError(error.message));
}
// get asset claim data
let claimData;
try {
({data: claimData} = yield call(getClaimData, name, longId));
({data: claimData} = yield call(getClaimData, host, name, longId));
} catch (error) {
return yield put(onRequestError(error.message));
}

View file

@ -1,3 +1,7 @@
export const selectSiteState = (state) => {
return state.site;
};
export const selectSiteHost = (state) => {
return state.site.host;
};