1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2025-12-07 02:28:54 +08:00

refactor reading predefined queries

This commit is contained in:
lana-k
2021-01-21 13:25:29 +01:00
parent 6886b7903f
commit 8652edc139
3 changed files with 16 additions and 30 deletions

View File

@@ -13,35 +13,7 @@ import '@/assets/styles/scrollbars.css'
export default {
name: 'MainView',
components: { MainMenu },
created () {
this.readPredefinedQueries()
.then(queries => {
this.$store.commit('updatePredefinedQueries', queries)
})
.catch(console.error)
},
methods: {
readPredefinedQueries () {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest()
xhr.open('GET', './queries.json')
xhr.onload = () => {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
resolve(JSON.parse(xhr.responseText || '[]'))
} else {
reject(xhr.statusText)
}
}
}
xhr.onerror = () => {
reject(xhr.statusText)
}
xhr.send()
})
}
}
components: { MainMenu }
}
</script>
<style scoped>

View File

@@ -214,7 +214,14 @@ export default {
}
},
created () {
this.queries = storedQueries.getStoredQueries()
storedQueries.readPredefinedQueries()
.then(queries => {
this.$store.commit('updatePredefinedQueries', queries)
})
.catch(console.error)
.finally(() => {
this.queries = storedQueries.getStoredQueries()
})
},
mounted () {
this.resizeObserver = new ResizeObserver(this.calcMaxTableHeight)