diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-08 12:09:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-08 12:09:42 +0000 |
commit | 403678e00406edc8094f087ec70e00aa29e49bef (patch) | |
tree | 447d6d4967e9a11895683b27e637a50bd9fc0602 /app/assets/javascripts/static_site_editor | |
parent | f5050253469fc0961c02deec0e698ad62bdd9de5 (diff) | |
download | gitlab-ce-403678e00406edc8094f087ec70e00aa29e49bef.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/static_site_editor')
8 files changed, 57 insertions, 4 deletions
diff --git a/app/assets/javascripts/static_site_editor/components/static_site_editor.vue b/app/assets/javascripts/static_site_editor/components/static_site_editor.vue index 4a0e153eb33..f06d48ee4f5 100644 --- a/app/assets/javascripts/static_site_editor/components/static_site_editor.vue +++ b/app/assets/javascripts/static_site_editor/components/static_site_editor.vue @@ -1,5 +1,5 @@ <script> -import { mapState, mapActions } from 'vuex'; +import { mapState, mapGetters, mapActions } from 'vuex'; import { GlSkeletonLoader } from '@gitlab/ui'; import EditArea from './edit_area.vue'; @@ -10,7 +10,8 @@ export default { GlSkeletonLoader, }, computed: { - ...mapState(['content', 'isContentLoaded', 'isLoadingContent']), + ...mapState(['content', 'isLoadingContent']), + ...mapGetters(['isContentLoaded']), }, mounted() { this.loadContent(); diff --git a/app/assets/javascripts/static_site_editor/index.js b/app/assets/javascripts/static_site_editor/index.js index 4290cb9a9ba..22f96a60df0 100644 --- a/app/assets/javascripts/static_site_editor/index.js +++ b/app/assets/javascripts/static_site_editor/index.js @@ -3,7 +3,11 @@ import StaticSiteEditor from './components/static_site_editor.vue'; import createStore from './store'; const initStaticSiteEditor = el => { - const store = createStore(); + const { projectId, path: sourcePath } = el.dataset; + + const store = createStore({ + initialState: { projectId, sourcePath }, + }); return new Vue({ el, diff --git a/app/assets/javascripts/static_site_editor/store/actions.js b/app/assets/javascripts/static_site_editor/store/actions.js new file mode 100644 index 00000000000..192345f3749 --- /dev/null +++ b/app/assets/javascripts/static_site_editor/store/actions.js @@ -0,0 +1,18 @@ +import createFlash from '~/flash'; +import { __ } from '~/locale'; + +import * as mutationTypes from './mutation_types'; +import loadSourceContent from '~/static_site_editor/services/load_source_content'; + +export const loadContent = ({ commit, state: { sourcePath, projectId } }) => { + commit(mutationTypes.LOAD_CONTENT); + + return loadSourceContent({ sourcePath, projectId }) + .then(data => commit(mutationTypes.RECEIVE_CONTENT_SUCCESS, data)) + .catch(() => { + commit(mutationTypes.RECEIVE_CONTENT_ERROR); + createFlash(__('An error ocurred while loading your content. Please try again.')); + }); +}; + +export default () => {}; diff --git a/app/assets/javascripts/static_site_editor/store/getters.js b/app/assets/javascripts/static_site_editor/store/getters.js new file mode 100644 index 00000000000..8baa2941594 --- /dev/null +++ b/app/assets/javascripts/static_site_editor/store/getters.js @@ -0,0 +1,2 @@ +// eslint-disable-next-line import/prefer-default-export +export const isContentLoaded = ({ content }) => Boolean(content); diff --git a/app/assets/javascripts/static_site_editor/store/index.js b/app/assets/javascripts/static_site_editor/store/index.js index 653c2532ee6..43256979ddd 100644 --- a/app/assets/javascripts/static_site_editor/store/index.js +++ b/app/assets/javascripts/static_site_editor/store/index.js @@ -1,12 +1,18 @@ import Vuex from 'vuex'; import Vue from 'vue'; import createState from './state'; +import * as getters from './getters'; +import * as actions from './actions'; +import mutations from './mutations'; Vue.use(Vuex); const createStore = ({ initialState } = {}) => { return new Vuex.Store({ state: createState(initialState), + getters, + actions, + mutations, }); }; diff --git a/app/assets/javascripts/static_site_editor/store/mutation_types.js b/app/assets/javascripts/static_site_editor/store/mutation_types.js new file mode 100644 index 00000000000..cbe51180541 --- /dev/null +++ b/app/assets/javascripts/static_site_editor/store/mutation_types.js @@ -0,0 +1,3 @@ +export const LOAD_CONTENT = 'loadContent'; +export const RECEIVE_CONTENT_SUCCESS = 'receiveContentSuccess'; +export const RECEIVE_CONTENT_ERROR = 'receiveContentError'; diff --git a/app/assets/javascripts/static_site_editor/store/mutations.js b/app/assets/javascripts/static_site_editor/store/mutations.js new file mode 100644 index 00000000000..88cb74d2b11 --- /dev/null +++ b/app/assets/javascripts/static_site_editor/store/mutations.js @@ -0,0 +1,15 @@ +import * as types from './mutation_types'; + +export default { + [types.LOAD_CONTENT](state) { + state.isLoadingContent = true; + }, + [types.RECEIVE_CONTENT_SUCCESS](state, { title, content }) { + state.isLoadingContent = false; + state.title = title; + state.content = content; + }, + [types.RECEIVE_CONTENT_ERROR](state) { + state.isLoadingContent = false; + }, +}; diff --git a/app/assets/javascripts/static_site_editor/store/state.js b/app/assets/javascripts/static_site_editor/store/state.js index 68a7f95760c..b68e73f06f5 100644 --- a/app/assets/javascripts/static_site_editor/store/state.js +++ b/app/assets/javascripts/static_site_editor/store/state.js @@ -1,8 +1,12 @@ const createState = (initialState = {}) => ({ + projectId: null, + sourcePath: null, + isLoadingContent: false, - isContentLoaded: false, content: '', + title: '', + ...initialState, }); |