Skip to content

Commit

Permalink
don't update entire tables store when only description changes
Browse files Browse the repository at this point in the history
Signed-off-by: grnd-alt <salimbelakkaf@outlook.de>
  • Loading branch information
grnd-alt committed Mar 15, 2024
1 parent 77f5598 commit 052da12
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/modules/main/sections/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default {
async saveDescription() {
if (this.descriptionLastEdited !== 0) return
this.descriptionSaving = true
await this.$store.dispatch('updateTable', { id: this.table.id, data: { description: this.description } })
await this.$store.dispatch('updateTableProperty', { id: this.table.id, data: { description: this.description }, property: 'description' })
this.descriptionLastEdit = 0
this.descriptionSaving = false
},
Expand Down
20 changes: 18 additions & 2 deletions src/store/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default new Vuex.Store({
},
setTable(state, table) {
const index = state.tables.findIndex(t => t.id === table.id)
state.tables[index] = table
state.tables.splice(index, 1, table)
},
setView(state, view) {
const index = state.views.findIndex(v => v.id === view.id)
Expand Down Expand Up @@ -218,6 +218,22 @@ export default new Vuex.Store({
}
return true
},
async updateTableProperty({ state, commit, dispatch }, { id, data, property }) {
let res = null

try {
res = (await axios.put(generateOcsUrl('/apps/tables/api/2/tables/' + id), data)).data.ocs
} catch (e) {
displayError(e, t('tables', 'Could not update table.'))
return false
}

const table = res.data
const tables = state.tables
const index = tables.findIndex(t => t.id === table.id)
Vue.set(state.tables[index], property, data[property])

Check warning on line 234 in src/store/store.js

View workflow job for this annotation

GitHub Actions / NPM lint

Caution: `Vue` also has a named export `set`. Check if you meant to write `import {set} from 'vue'` instead
return true
},
async updateTable({ state, commit, dispatch }, { id, data }) {
let res = null

Expand All @@ -232,7 +248,7 @@ export default new Vuex.Store({
const tables = state.tables
const index = tables.findIndex(t => t.id === table.id)
tables[index] = table
commit('setTable', table)
commit('setTables', [...tables])
return true
},
async favoriteView({ state, commit, dispatch }, { id }) {
Expand Down

0 comments on commit 052da12

Please sign in to comment.