Stackedit/src/components/App.vue

113 lines
2.5 KiB
Vue
Raw Normal View History

2017-07-23 18:42:08 +00:00
<template>
2018-01-10 21:45:34 +00:00
<div class="app" :class="themeClasses">
2017-12-10 23:49:20 +00:00
<splash-screen v-if="!ready"></splash-screen>
<layout v-else></layout>
<modal v-if="showModal"></modal>
2017-09-23 19:01:50 +00:00
<notification></notification>
2018-03-09 21:18:20 +00:00
<context-menu></context-menu>
2017-07-23 18:42:08 +00:00
</div>
</template>
<script>
import Vue from 'vue';
2017-07-23 18:42:08 +00:00
import Layout from './Layout';
import Modal from './Modal';
2017-09-23 19:01:50 +00:00
import Notification from './Notification';
2018-03-09 21:18:20 +00:00
import ContextMenu from './ContextMenu';
2017-10-02 00:34:48 +00:00
import SplashScreen from './SplashScreen';
2017-12-10 23:49:20 +00:00
import syncSvc from '../services/syncSvc';
2017-12-11 00:53:46 +00:00
import networkSvc from '../services/networkSvc';
import sponsorSvc from '../services/sponsorSvc';
2018-03-15 13:51:39 +00:00
import tempFileSvc from '../services/tempFileSvc';
2017-11-15 08:12:56 +00:00
import timeSvc from '../services/timeSvc';
import store from '../store';
2017-07-23 18:42:08 +00:00
// Global directives
Vue.directive('focus', {
inserted(el) {
el.focus();
2017-11-26 20:58:24 +00:00
const value = el.value;
if (value && el.setSelectionRange) {
el.setSelectionRange(0, value.length);
}
},
});
2017-10-07 11:22:24 +00:00
const setVisible = (el, value) => {
el.style.display = value ? '' : 'none';
if (value) {
el.removeAttribute('aria-hidden');
} else {
el.setAttribute('aria-hidden', 'true');
}
};
Vue.directive('show', {
bind(el, { value }) {
setVisible(el, value);
},
update(el, { value, oldValue }) {
if (value !== oldValue) {
setVisible(el, value);
}
},
});
Vue.directive('title', {
bind(el, { value }) {
el.title = value;
el.setAttribute('aria-label', value);
},
});
2017-11-15 08:12:56 +00:00
// Global filters
Vue.filter('formatTime', time =>
// Access the minute counter for reactive refresh
timeSvc.format(time, store.state.minuteCounter));
2018-01-10 21:45:34 +00:00
const themeClasses = {
light: ['app--light'],
dark: ['app--dark'],
};
2017-07-23 18:42:08 +00:00
export default {
components: {
Layout,
Modal,
2017-09-23 19:01:50 +00:00
Notification,
2018-03-09 21:18:20 +00:00
ContextMenu,
2017-10-02 00:34:48 +00:00
SplashScreen,
2017-07-23 18:42:08 +00:00
},
2017-12-10 23:49:20 +00:00
data: () => ({
ready: false,
}),
2017-07-28 07:40:24 +00:00
computed: {
2018-01-10 21:45:34 +00:00
themeClasses() {
const result = themeClasses[this.$store.getters['data/computedSettings'].colorTheme];
return Array.isArray(result) ? result : themeClasses.light;
},
showModal() {
2017-09-23 19:01:50 +00:00
return !!this.$store.getters['modal/config'];
},
2017-07-28 07:40:24 +00:00
},
2017-12-10 23:49:20 +00:00
created() {
syncSvc.init()
.then(() => {
2017-12-11 00:53:46 +00:00
networkSvc.init();
sponsorSvc.init();
2017-12-10 23:49:20 +00:00
this.ready = true;
2018-03-15 13:51:39 +00:00
tempFileSvc.setReady();
2017-12-17 15:08:52 +00:00
})
.catch((err) => {
if (err && err.message !== 'reload') {
console.error(err); // eslint-disable-line no-console
this.$store.dispatch('notification/error', err);
}
2017-12-10 23:49:20 +00:00
});
},
2017-07-23 18:42:08 +00:00
};
</script>
<style lang="scss">
2017-07-28 20:04:12 +00:00
@import 'common/app';
2017-07-23 18:42:08 +00:00
</style>