update tables select method

This commit is contained in:
Keviin Åberg Kultalahti 2021-03-23 12:04:01 +01:00
parent 54b99d6d4b
commit 2d1683c785
1 changed files with 15 additions and 7 deletions

View File

@ -19,13 +19,21 @@ function createTablesStore() {
const tables = await tablesResponse.json()
update(state => ({...state, list: tables}))
},
select: table =>
update(state => ({
...state,
selected: table,
draft: cloneDeep(table),
view: { name: `all_${table._id}` }
})),
select: table => {
if (!table) {
update(state => ({
...state,
selected: {}
}))
} else {
update(state => ({
...state,
selected: table,
draft: cloneDeep(table),
view: { name: `all_${table._id}` }
}))
}
},
save: async table => {
const updatedTable = cloneDeep(table)
const oldTable = get(store).list.filter(t => t._id === table._id)[0]