From c13c754c4caecd9953590760a9d0ccc80c2b33e4 Mon Sep 17 00:00:00 2001 From: NGPixel Date: Fri, 26 May 2017 00:12:38 -0400 Subject: [PATCH] refactor: vue comp: page-loader + modal-create-page --- client/js/app.js | 3 +++ client/js/components/modal-create-page.vue | 25 ++++++++++++++++------ client/js/components/page-loader.js | 14 ------------ client/js/components/page-loader.vue | 24 +++++++++++++++++++++ client/js/helpers/index.js | 17 ++++++++++++--- client/js/pages/source-view.component.js | 5 ++--- client/js/store/index.js | 4 +++- client/js/store/modules/page-loader.js | 17 +++++++++++++++ client/scss/layout/_loader.scss | 14 +++++------- server/views/pages/source.pug | 8 ++----- 10 files changed, 89 insertions(+), 42 deletions(-) delete mode 100644 client/js/components/page-loader.js create mode 100644 client/js/components/page-loader.vue create mode 100644 client/js/store/modules/page-loader.js diff --git a/client/js/app.js b/client/js/app.js index 516a8d96..8ebb1922 100644 --- a/client/js/app.js +++ b/client/js/app.js @@ -33,6 +33,7 @@ import colorPickerComponent from './components/color-picker.vue' import loadingSpinnerComponent from './components/loading-spinner.vue' import modalCreatePageComponent from './components/modal-create-page.vue' import modalCreateUserComponent from './components/modal-create-user.vue' +import pageLoaderComponent from './components/page-loader.vue' import searchComponent from './components/search.vue' import treeComponent from './components/tree.vue' @@ -49,6 +50,7 @@ Vue.use(VueResource) Vue.use(VueClipboards) Vue.use(VueI18Next) Vue.use(VueLodash, _) +Vue.use(helpers) i18next .use(i18nextXHR) @@ -98,6 +100,7 @@ $(() => { loadingSpinner: loadingSpinnerComponent, modalCreatePage: modalCreatePageComponent, modalCreateUser: modalCreateUserComponent, + pageLoader: pageLoaderComponent, search: searchComponent, sourceView: sourceViewComponent, tree: treeComponent diff --git a/client/js/components/modal-create-page.vue b/client/js/components/modal-create-page.vue index b7701933..889b2645 100644 --- a/client/js/components/modal-create-page.vue +++ b/client/js/components/modal-create-page.vue @@ -7,7 +7,7 @@ section label.label Enter the new document path: p.control.is-fullwidth(v-bind:class='{ "is-loading": isLoading }') - input.input(type='text', placeholder='page-name', v-model='entrypath', autofocus) + input.input(type='text', placeholder='page-name', v-model='entrypath', ref='createPageInput', @keyup.enter='create', @keyup.esc='cancel') span.help.is-danger(v-show='isInvalid') This document path is invalid! footer a.button.is-grey.is-outlined(v-on:click='cancel') Discard @@ -15,28 +15,39 @@ diff --git a/client/js/components/page-loader.js b/client/js/components/page-loader.js deleted file mode 100644 index 8d610162..00000000 --- a/client/js/components/page-loader.js +++ /dev/null @@ -1,14 +0,0 @@ -'use strict' - -import $ from 'jquery' -import _ from 'lodash' - -module.exports = { - - complete() { - $('#page-loader').addClass('is-loaded') - _.delay(() => { - $('#page-loader').addClass('is-hidden') - }, 1100) - } -} diff --git a/client/js/components/page-loader.vue b/client/js/components/page-loader.vue new file mode 100644 index 00000000..8f7071e3 --- /dev/null +++ b/client/js/components/page-loader.vue @@ -0,0 +1,24 @@ + + + diff --git a/client/js/helpers/index.js b/client/js/helpers/index.js index 7bdce36a..bd94a1e8 100644 --- a/client/js/helpers/index.js +++ b/client/js/helpers/index.js @@ -1,8 +1,19 @@ 'use strict' +const helpers = { + form: require('./form'), + pages: require('./pages') +} + export default { - helpers: { - form: require('./form'), - pages: require('./pages') + install(Vue) { + Vue.$helpers = helpers + Object.defineProperties(Vue.prototype, { + $helpers: { + get() { + return helpers + } + } + }) } } diff --git a/client/js/pages/source-view.component.js b/client/js/pages/source-view.component.js index 8a169d33..3c265ab9 100644 --- a/client/js/pages/source-view.component.js +++ b/client/js/pages/source-view.component.js @@ -2,14 +2,13 @@ /* global FuseBox */ -import pageLoader from '../components/page-loader' - export default { name: 'source-view', data() { return {} }, mounted() { + let self = this FuseBox.import('/js/ace/source-view.js', (ace) => { let scEditor = ace.edit('source-display') scEditor.setTheme('ace/theme/dawn') @@ -20,7 +19,7 @@ export default { scEditor.setReadOnly(true) scEditor.renderer.updateFull() scEditor.renderer.on('afterRender', () => { - pageLoader.complete() + self.$store.dispatch('pageLoader/complete') }) }) } diff --git a/client/js/store/index.js b/client/js/store/index.js index 89195897..d99e4890 100644 --- a/client/js/store/index.js +++ b/client/js/store/index.js @@ -5,6 +5,7 @@ import alert from './modules/alert' import anchor from './modules/anchor' import modalCreatePage from './modules/modal-create-page' import modalCreateUser from './modules/modal-create-user' +import pageLoader from './modules/page-loader' Vue.use(Vuex) @@ -24,6 +25,7 @@ export default new Vuex.Store({ alert, anchor, modalCreatePage, - modalCreateUser + modalCreateUser, + pageLoader } }) diff --git a/client/js/store/modules/page-loader.js b/client/js/store/modules/page-loader.js new file mode 100644 index 00000000..9b5d3be2 --- /dev/null +++ b/client/js/store/modules/page-loader.js @@ -0,0 +1,17 @@ +'use strict' + +export default { + namespaced: true, + state: { + shown: true, + msg: 'Loading...' + }, + getters: {}, + mutations: { + shownChange: (state, shownState) => { state.shown = shownState }, + msgChange: (state, newText) => { state.msg = newText } + }, + actions: { + complete({ commit }) { commit('shownChange', false) } + } +} diff --git a/client/scss/layout/_loader.scss b/client/scss/layout/_loader.scss index 4dd2b2b1..d8204c39 100644 --- a/client/scss/layout/_loader.scss +++ b/client/scss/layout/_loader.scss @@ -1,4 +1,4 @@ -#page-loader { +.page-loader { position: fixed; top: 0; left: 0; @@ -28,6 +28,10 @@ } } + &-leave-active { + animation: pageLoaderExit 1s ease forwards; + } + @include keyframes(pageLoaderExit) { 0% { opacity: 1; @@ -43,12 +47,4 @@ } } - &.is-loaded { - animation: pageLoaderExit 1s ease forwards; - } - - &.is-hidden { - display: none !important; - } - } diff --git a/server/views/pages/source.pug b/server/views/pages/source.pug index 2bdc5696..995fe440 100644 --- a/server/views/pages/source.pug +++ b/server/views/pages/source.pug @@ -23,14 +23,10 @@ block rootNavRight block content - source-view(inline-template, data-entrypath=pageData.meta.path) + source-view(inline-template, data-entrypath=pageData.meta.path, v-cloak) .ace-container #source-display= pageData.markdown include ../modals/create.pug include ../modals/move.pug - -block outside - #page-loader - i - span= t('loading.source') + page-loader(text=t('loading.source'))