From 170e427530ee0d5211ca3889798bda1889d4d460 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 8 Feb 2020 09:38:19 +0100 Subject: [PATCH] Ensured domain is passed when loading detail for a short URL on a specific domain --- src/visits/ShortUrlVisits.js | 14 +++++++------- src/visits/reducers/shortUrlDetail.js | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/visits/ShortUrlVisits.js b/src/visits/ShortUrlVisits.js index 36565e75..df8ba732 100644 --- a/src/visits/ShortUrlVisits.js +++ b/src/visits/ShortUrlVisits.js @@ -33,8 +33,8 @@ const ShortUrlVisits = ( }; state = { startDate: undefined, endDate: undefined }; - loadVisits = () => { - const { match: { params }, location: { search }, getShortUrlVisits } = this.props; + loadVisits = (loadDetail = false) => { + const { match: { params }, location: { search }, getShortUrlVisits, getShortUrlDetail } = this.props; const { shortCode } = params; const dates = mapObjIndexed(formatDate(), this.state); const { startDate, endDate } = dates; @@ -44,15 +44,15 @@ const ShortUrlVisits = ( // While the "page" is loaded, use the timestamp + filtering dates as memoization IDs for stats calculations this.memoizationId = `${this.timeWhenMounted}_${shortCode}_${startDate}_${endDate}`; getShortUrlVisits(shortCode, { startDate, endDate, domain }); + + if (loadDetail) { + getShortUrlDetail(shortCode, domain); + } }; componentDidMount() { - const { match: { params }, getShortUrlDetail } = this.props; - const { shortCode } = params; - this.timeWhenMounted = new Date().getTime(); - this.loadVisits(); - getShortUrlDetail(shortCode); + this.loadVisits(true); } componentWillUnmount() { diff --git a/src/visits/reducers/shortUrlDetail.js b/src/visits/reducers/shortUrlDetail.js index 893c12ac..2f22243c 100644 --- a/src/visits/reducers/shortUrlDetail.js +++ b/src/visits/reducers/shortUrlDetail.js @@ -26,13 +26,13 @@ export default handleActions({ [GET_SHORT_URL_DETAIL]: (state, { shortUrl }) => ({ shortUrl, loading: false, error: false }), }, initialState); -export const getShortUrlDetail = (buildShlinkApiClient) => (shortCode) => async (dispatch, getState) => { +export const getShortUrlDetail = (buildShlinkApiClient) => (shortCode, domain) => async (dispatch, getState) => { dispatch({ type: GET_SHORT_URL_DETAIL_START }); const { getShortUrl } = await buildShlinkApiClient(getState); try { - const shortUrl = await getShortUrl(shortCode); + const shortUrl = await getShortUrl(shortCode, domain); dispatch({ shortUrl, type: GET_SHORT_URL_DETAIL }); } catch (e) {