Skip to content

Commit

Permalink
No blocking while loading predifined #107
Browse files Browse the repository at this point in the history
  • Loading branch information
lana-k committed May 17, 2023
1 parent 6320f81 commit 4e13a16
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 22 deletions.
22 changes: 12 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sqliteviz",
"version": "0.21.1",
"version": "0.22.0",
"license": "Apache-2.0",
"private": true,
"scripts": {
Expand Down
6 changes: 6 additions & 0 deletions src/store/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,11 @@ export default {
},
updatePredefinedInquiries (state, inquiries) {
state.predefinedInquiries = Array.isArray(inquiries) ? inquiries : [inquiries]
},
setLoadingPredefinedInquiries (state, value) {
state.loadingPredefinedInquiries = value
},
setPredefinedInquiriesLoaded (state, value) {
state.predefinedInquiriesLoaded = value
}
}
2 changes: 2 additions & 0 deletions src/store/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ export default {
currentTabId: null,
untitledLastIndex: 0,
predefinedInquiries: [],
loadingPredefinedInquiries: false,
predefinedInquiriesLoaded: false,
db: null
}
50 changes: 40 additions & 10 deletions src/views/Main/Inquiries/index.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
<template>
<div>
<div id="my-inquiries-container">
<div id="start-guide" v-if="allInquiries.length === 0">
You don't have saved inquiries so far.
<span class="link" @click="$root.$emit('createNewInquiry')">Create</span>
the one from scratch or
<span @click="importInquiries" class="link">import</span> from a file.
</div>
<div
id="loading-predefined-status"
v-if="$store.state.loadingPredefinedInquiries"
>
<loading-indicator/>
Loading predefined inquiries...
</div>
<div id="my-inquiries-content" ref="my-inquiries-content" v-show="allInquiries.length > 0">
<div id="my-inquiries-toolbar">
<div id="toolbar-buttons">
Expand Down Expand Up @@ -157,6 +164,7 @@ import DeleteIcon from './svg/delete'
import CloseIcon from '@/components/svg/close'
import TextField from '@/components/TextField'
import CheckBox from '@/components/CheckBox'
import LoadingIndicator from '@/components/LoadingIndicator'
import tooltipMixin from '@/tooltipMixin'
import storedInquiries from '@/lib/storedInquiries'
Expand All @@ -169,7 +177,8 @@ export default {
DeleteIcon,
CloseIcon,
TextField,
CheckBox
CheckBox,
LoadingIndicator
},
mixins: [tooltipMixin],
data () {
Expand Down Expand Up @@ -248,15 +257,21 @@ export default {
}
}
},
created () {
storedInquiries.readPredefinedInquiries()
.then(inquiries => {
async created () {
this.inquiries = storedInquiries.getStoredInquiries()
const loadingPredefinedInquiries = this.$store.state.loadingPredefinedInquiries
const predefinedInquiriesLoaded = this.$store.state.predefinedInquiriesLoaded
if (!predefinedInquiriesLoaded && !loadingPredefinedInquiries) {
try {
this.$store.commit('setLoadingPredefinedInquiries', true)
const inquiries = await storedInquiries.readPredefinedInquiries()
this.$store.commit('updatePredefinedInquiries', inquiries)
})
.catch(console.error)
.finally(() => {
this.inquiries = storedInquiries.getStoredInquiries()
})
this.$store.commit('setPredefinedInquiriesLoaded', true)
} catch (e) {
console.error(e)
}
this.$store.commit('setLoadingPredefinedInquiries', false)
}
},
mounted () {
this.resizeObserver = new ResizeObserver(this.calcMaxTableHeight)
Expand Down Expand Up @@ -441,6 +456,21 @@ export default {
</script>

<style scoped>
#my-inquiries-container {
position: relative;
}
#loading-predefined-status {
position: absolute;
right: 0;
display: flex;
gap: 4px;
font-size: 12px;
color: var(--color-text-light-2);
align-items: center;
padding: 8px;
}
#start-guide {
position: absolute;
top: 50%;
Expand Down
22 changes: 21 additions & 1 deletion tests/store/mutations.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const {
setCurrentTabId,
setCurrentTab,
updatePredefinedInquiries,
setDb
setDb,
setLoadingPredefinedInquiries,
setPredefinedInquiriesLoaded
} = mutations

describe('mutations', () => {
Expand Down Expand Up @@ -377,4 +379,22 @@ describe('mutations', () => {
updatePredefinedInquiries(state, inquiries)
expect(state.predefinedInquiries).to.eql(inquiries)
})

it('setLoadingPredefinedInquiries', () => {
const state = {
loadingPredefinedInquiries: false
}

setLoadingPredefinedInquiries(state, true)
expect(state.loadingPredefinedInquiries).to.equal(true)
})

it('setPredefinedInquiriesLoaded', () => {
const state = {
predefinedInquiriesLoaded: false
}

setPredefinedInquiriesLoaded(state, true)
expect(state.predefinedInquiriesLoaded).to.equal(true)
})
})

0 comments on commit 4e13a16

Please sign in to comment.