Skip to content

Commit

Permalink
Refactor app init routines to load config/i18n before main app mount.
Browse files Browse the repository at this point in the history
Move config/language loading outside the main Vue() instance mount
as the app dependencies require i18n before they are mounted.

This commit moves config/language loading outside the app routines
to plain API calls, which on success, initialize and mount the main
view App instance.
  • Loading branch information
knadh committed Mar 1, 2022
1 parent 76a86fa commit e87c80e
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions frontend/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ const i18n = new VueI18n();
Vue.use(Buefy, {});
Vue.config.productionTip = false;

// Globals.
Vue.prototype.$utils = new Utils(i18n);
Vue.prototype.$api = api;


// Setup the router.
router.beforeEach((to, from, next) => {
Expand All @@ -30,12 +28,13 @@ router.beforeEach((to, from, next) => {

router.afterEach((to) => {
Vue.nextTick(() => {
const t = to.meta.title ? `${i18n.tc(to.meta.title, 0)} /` : '';
const t = to.meta.title && i18n.te(to.meta.title) ? `${i18n.tc(to.meta.title, 0)} /` : '';
document.title = `${t} listmonk`;
});
});

new Vue({

const v = new Vue({
router,
store,
i18n,
Expand All @@ -45,20 +44,28 @@ new Vue({
isLoaded: false,
},

methods: {
loadConfig() {
api.getServerConfig().then((data) => {
api.getLang(data.lang).then((lang) => {
i18n.locale = data.lang;
i18n.setLocaleMessage(i18n.locale, lang);
this.isLoaded = true;
});
});
},
mounted() {
v.isLoaded = true;
},
});

created() {
this.loadConfig();
api.getSettings();
},
}).$mount('#app');

// Load server side config and language before mounting the app.
api.getServerConfig().then((data) => {
api.getLang(data.lang).then((lang) => {
i18n.locale = data.lang;
i18n.setLocaleMessage(i18n.locale, lang);

Vue.prototype.$utils = new Utils(i18n);
Vue.prototype.$api = api;

// Set the page title after i18n has loaded.
const to = router.history.current;
const t = to.meta.title ? `${i18n.tc(to.meta.title, 0)} /` : '';
document.title = `${t} listmonk`;

v.$mount('#app');
});
});

api.getSettings();

0 comments on commit e87c80e

Please sign in to comment.