diff options
Diffstat (limited to 'app/assets/javascripts/whats_new/store/actions.js')
-rw-r--r-- | app/assets/javascripts/whats_new/store/actions.js | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/app/assets/javascripts/whats_new/store/actions.js b/app/assets/javascripts/whats_new/store/actions.js index a84dfb399d8..532febd61cb 100644 --- a/app/assets/javascripts/whats_new/store/actions.js +++ b/app/assets/javascripts/whats_new/store/actions.js @@ -1,5 +1,6 @@ import * as types from './mutation_types'; import axios from '~/lib/utils/axios_utils'; +import { parseIntPagination, normalizeHeaders } from '~/lib/utils/common_utils'; export default { closeDrawer({ commit }) { @@ -12,9 +13,33 @@ export default { localStorage.setItem(storageKey, JSON.stringify(false)); } }, - fetchItems({ commit }) { - return axios.get('/-/whats_new').then(({ data }) => { - commit(types.SET_FEATURES, data); - }); + fetchItems({ commit, state }, page) { + if (state.fetching) { + return false; + } + + commit(types.SET_FETCHING, true); + + return axios + .get('/-/whats_new', { + params: { + page, + }, + }) + .then(({ data, headers }) => { + commit(types.ADD_FEATURES, data); + + const normalizedHeaders = normalizeHeaders(headers); + const { nextPage } = parseIntPagination(normalizedHeaders); + commit(types.SET_PAGE_INFO, { + nextPage, + }); + }) + .finally(() => { + commit(types.SET_FETCHING, false); + }); + }, + setDrawerBodyHeight({ commit }, height) { + commit(types.SET_DRAWER_BODY_HEIGHT, height); }, }; |