From ac8925992424b44662bdf3b70bc38358a6580558 Mon Sep 17 00:00:00 2001 From: lana-k Date: Mon, 24 May 2021 21:45:51 +0200 Subject: [PATCH] Always create empty db on start #46 --- src/router.js | 11 +++++++++++ src/views/Main/Editor/index.vue | 15 +++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/router.js b/src/router.js index cf80201..5fcb24f 100644 --- a/src/router.js +++ b/src/router.js @@ -4,6 +4,8 @@ import Editor from '@/views/Main/Editor' import MyQueries from '@/views/Main/MyQueries' import Welcome from '@/views/Welcome' import Main from '@/views/Main' +import store from '@/store' +import database from '@/lib/database' Vue.use(VueRouter) @@ -36,4 +38,13 @@ const router = new VueRouter({ routes }) +router.beforeEach(async (to, from, next) => { + if (!store.state.db) { + const newDb = database.getNewDatabase() + await newDb.loadDb() + store.commit('setDb', newDb) + } + next() +}) + export default router diff --git a/src/views/Main/Editor/index.vue b/src/views/Main/Editor/index.vue index 35c448c..dc5b023 100644 --- a/src/views/Main/Editor/index.vue +++ b/src/views/Main/Editor/index.vue @@ -19,8 +19,6 @@ import Splitpanes from '@/components/Splitpanes' import Schema from './Schema' import Tabs from './Tabs' -import database from '@/lib/database' -import store from '@/store' export default { name: 'Editor', @@ -29,11 +27,9 @@ export default { Splitpanes, Tabs }, - async beforeRouteEnter (to, from, next) { - if (!store.state.db) { - const newDb = database.getNewDatabase() - await newDb.loadDb() - store.commit('setDb', newDb) + async beforeCreate () { + const schema = this.$store.state.db.schema + if (!schema || schema.length === 0) { const stmt = [ '/*', ' * Your database is empty. In order to start building charts', @@ -51,10 +47,9 @@ export default { "('Slytherin', 80);" ].join('\n') - const tabId = await store.dispatch('addTab', { query: stmt }) - store.commit('setCurrentTabId', tabId) + const tabId = await this.$store.dispatch('addTab', { query: stmt }) + this.$store.commit('setCurrentTabId', tabId) } - next() } }