From 53f1a4e67d67360ff034ea59072c71bc041f9aec Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 2 Jun 2023 09:04:50 +0100 Subject: [PATCH] Update builder socket to ignore own events, and ensure table creation updates state without depending on the websocket --- .../builder/src/builderStore/websocket.js | 30 +++++++++---------- packages/builder/src/stores/backend/tables.js | 2 +- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/packages/builder/src/builderStore/websocket.js b/packages/builder/src/builderStore/websocket.js index 6a3ce76ae6..e27e08e31d 100644 --- a/packages/builder/src/builderStore/websocket.js +++ b/packages/builder/src/builderStore/websocket.js @@ -15,25 +15,23 @@ export const createBuilderWebsocket = appId => { socket.on("connect_error", err => { console.log("Failed to connect to builder websocket:", err.message) }) - - // User events - socket.on(SocketEvent.UserUpdate, userStore.actions.updateUser) - socket.on(SocketEvent.UserDisconnect, userStore.actions.removeUser) - - // Table events - socket.on(BuilderSocketEvent.TableChange, ({ id, table }) => { - tables.replaceTable(id, table) - }) - - // Datasource events - socket.on(BuilderSocketEvent.DatasourceChange, ({ id, datasource }) => { - datasources.replaceDatasource(id, datasource) - }) - - // Clean up user store on disconnect socket.on("disconnect", () => { userStore.actions.reset() }) + // User events + socket.onOther(SocketEvent.UserUpdate, userStore.actions.updateUser) + socket.onOther(SocketEvent.UserDisconnect, userStore.actions.removeUser) + + // Table events + socket.onOther(BuilderSocketEvent.TableChange, ({ id, table }) => { + tables.replaceTable(id, table) + }) + + // Datasource events + socket.onOther(BuilderSocketEvent.DatasourceChange, ({ id, datasource }) => { + datasources.replaceDatasource(id, datasource) + }) + return socket } diff --git a/packages/builder/src/stores/backend/tables.js b/packages/builder/src/stores/backend/tables.js index a36c91d1b1..f8796712a8 100644 --- a/packages/builder/src/stores/backend/tables.js +++ b/packages/builder/src/stores/backend/tables.js @@ -62,7 +62,7 @@ export function createTablesStore() { } const savedTable = await API.saveTable(updatedTable) - replaceTable(table._id, savedTable) + replaceTable(savedTable._id, savedTable) await datasources.fetch() select(savedTable._id) return savedTable