debian-mirror-gitlab/app/assets/javascripts/whats_new/store/actions.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-10-24 23:57:45 +05:30
import * as types from './mutation_types';
2021-01-03 14:25:43 +05:30
import axios from '~/lib/utils/axios_utils';
2021-01-29 00:20:46 +05:30
import { parseIntPagination, normalizeHeaders } from '~/lib/utils/common_utils';
2020-10-24 23:57:45 +05:30
export default {
closeDrawer({ commit }) {
commit(types.CLOSE_DRAWER);
},
2021-01-03 14:25:43 +05:30
openDrawer({ commit }, storageKey) {
2020-10-24 23:57:45 +05:30
commit(types.OPEN_DRAWER);
2021-01-03 14:25:43 +05:30
if (storageKey) {
localStorage.setItem(storageKey, JSON.stringify(false));
}
},
2021-02-22 17:27:13 +05:30
fetchItems({ commit, state }, { page, version } = { page: null, version: null }) {
2021-01-29 00:20:46 +05:30
if (state.fetching) {
return false;
}
commit(types.SET_FETCHING, true);
return axios
.get('/-/whats_new', {
params: {
page,
2021-02-22 17:27:13 +05:30
version,
2021-01-29 00:20:46 +05:30
},
})
.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);
2020-10-24 23:57:45 +05:30
},
};