www.spaceplanner.app

Web client to the spaceplanner API
git clone git://jacobedwards.org/www.spaceplanner.app
Log | Files | Refs

commit cc1ad4d482f8b92b57df5f054d67050201ee3422
parent 72e7a74eb1c672ef8b0248fee6714b1517a30b37
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date:   Tue, 15 Oct 2024 10:22:21 -0700

Fix use of deleted server ids

When objects were deleted from the server, they're id mapping to
local ids wouldn't be removed and so in the case of undoing and
then redoing actions those ids would be used when they no longer
existed.

Now when they're deleted from the server they're deleted from our
id maps.

Diffstat:
Mfiles/floorplans/floorplan/backend.js | 24++++++++++++++++++++++++
1 file changed, 24 insertions(+), 0 deletions(-)

diff --git a/files/floorplans/floorplan/backend.js b/files/floorplans/floorplan/backend.js @@ -738,6 +738,15 @@ export class FloorplanBackend { let backend = this return api.fetch("PATCH", this.endpoint, patch) .then(function(data) { + if (newpos < backend.serverPosition) { + for (let i = 0; i < patch.length; ++i) { + if (patch[i].op === "remove") { + let id = parsePath(patch[i].path) + backend.unmapID(id) + } + } + } + backend.serverPosition = newpos updateIDs(backend, data) for (let i in dirty) { @@ -761,6 +770,11 @@ export class FloorplanBackend { return api.fetch("PUT", this.endpoint, this.cache) .then(function(data) { + for (let k in backend.serverIDs) { + if (backend.serverIDs[k] !== null) { + backend.unmapID(backend.serverIDs[k]) + } + } updateIDs(backend, data) backend.serverPosition = backend.history.place }) @@ -965,6 +979,16 @@ export class FloorplanBackend { this.serverIDs[localID] = serverID } + unmapID(serverID) { + console.debug("Backend.unmapID", serverID) + let local = this.localIDs[serverID] + if (local == null) { + throw new Error(serverID + ": Expected mapped id") + } + this.serverIDs[local] = null + delete this.localIDs[serverID] + } + remapID(localID, serverID, options) { options = options ?? {} options.remap = true