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

fix state updating

This commit is contained in:
lana-k
2020-12-24 15:40:54 +01:00
parent 07cc00671f
commit d66eb48088
3 changed files with 12 additions and 9 deletions

View File

@@ -16,7 +16,7 @@
<button <button
v-if="currentQuery" v-if="currentQuery"
class="primary" class="primary"
:disabled="currentQuery && !currentQuery.isUnsaved" :disabled="currentQuery && !isUnsaved"
@click="checkQueryBeforeSave" @click="checkQueryBeforeSave"
> >
Save Save
@@ -72,6 +72,13 @@ export default {
currentQuery () { currentQuery () {
return this.$store.state.currentTab return this.$store.state.currentTab
}, },
isUnsaved () {
if (!this.currentQuery) {
return false
}
const tabIndex = this.currentQuery.tabIndex
return this.$store.state.tabs[tabIndex].isUnsaved
},
isPredefined () { isPredefined () {
if (this.currentQuery) { if (this.currentQuery) {
return this.currentQuery.isPredefined return this.currentQuery.isPredefined

View File

@@ -34,7 +34,7 @@
:sql-result="result" :sql-result="result"
:init-chart="initChart" :init-chart="initChart"
ref="chart" ref="chart"
@update="isUnsaved = true" @update="$store.commit('updateTabState', { index: tabIndex, isUnsaved: true })"
/> />
</div> </div>
</template> </template>
@@ -65,7 +65,6 @@ export default {
result: null, result: null,
view: 'table', view: 'table',
tableViewHeight: 0, tableViewHeight: 0,
isUnsaved: !this.initName,
isGettingResults: false, isGettingResults: false,
error: null, error: null,
resizeObserver: null resizeObserver: null
@@ -94,10 +93,7 @@ export default {
} }
}, },
query () { query () {
this.isUnsaved = true this.$store.commit('updateTabState', { index: this.tabIndex, isUnsaved: true })
},
isUnsaved () {
this.$store.commit('updateTabState', { index: this.tabIndex, newValue: this.isUnsaved })
} }
}, },
methods: { methods: {

View File

@@ -95,9 +95,9 @@ export default new Vuex.Store({
Vue.set(state.tabs, index, tab) Vue.set(state.tabs, index, tab)
}, },
updateTabState (state, { index, newValue }) { updateTabState (state, { index, isUnsaved }) {
const tab = state.tabs[index] const tab = state.tabs[index]
tab.isUnsaved = newValue tab.isUnsaved = isUnsaved
Vue.set(state.tabs, index, tab) Vue.set(state.tabs, index, tab)
}, },
deleteTab (state, index) { deleteTab (state, index) {