diff options
Diffstat (limited to 'src/redux')
| -rw-r--r-- | src/redux/github/actions.js | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/redux/github/actions.js b/src/redux/github/actions.js index 7f843c4..a22612b 100644 --- a/src/redux/github/actions.js +++ b/src/redux/github/actions.js @@ -9,6 +9,23 @@ import { const API_URL = 'https://api.github.com/search/repositories'; +const transformFilters = (filters) => { + const transformedFilters = {}; + + const reposDate = `created:${filters.dateRange.start}..${filters.dateRange.end}`; + const reposLanguage = filters.language ? `language:${filters.language} ` : ''; + + if (filters.token) { + transformedFilters.access_token = filters.token; + } + + transformedFilters.q = reposLanguage + reposDate; + transformedFilters.sort = 'stars'; + transformedFilters.order = 'desc'; + + return transformedFilters; +}; + /** * @param {object} filters * @returns {Function} @@ -18,7 +35,7 @@ export const fetchTrending = function (filters) { dispatch({ type: PROCESS_FETCH_TRENDING }); axios.get(API_URL, { - params: filters + params: transformFilters(filters) }).then(response => { dispatch({ type: FETCH_TRENDING_SUCCESS, |
