Delete fix

This commit is contained in:
AlacrisDevs
2026-02-08 23:59:00 +02:00
parent 4ee2c0ac07
commit 9cb047c8b6

View File

@@ -1008,9 +1008,22 @@
return; return;
} }
const layerId = payload.new?.layer_id ?? payload.old?.layer_id; let layerId = payload.new?.layer_id ?? payload.old?.layer_id;
if (!layerId) return;
if (payload.event === "DELETE") {
if (!layerId)
layerId = layers.find((l) =>
l.pins.some((p) => p.id === id),
)?.id;
if (!layerId) return;
layers = layers.map((l) =>
l.id === layerId
? { ...l, pins: l.pins.filter((p) => p.id !== id) }
: l,
);
if (selectedObjectId === id) deselectAll();
} else {
if (!layerId) return;
if (payload.event === "INSERT") { if (payload.event === "INSERT") {
layers = layers.map((l) => layers = layers.map((l) =>
l.id === layerId l.id === layerId
@@ -1034,13 +1047,7 @@
} }
: l, : l,
); );
} else if (payload.event === "DELETE") { }
layers = layers.map((l) =>
l.id === layerId
? { ...l, pins: l.pins.filter((p) => p.id !== id) }
: l,
);
if (selectedObjectId === id) deselectAll();
} }
const layerIdx = layers.findIndex((l) => l.id === layerId); const layerIdx = layers.findIndex((l) => l.id === layerId);
@@ -1055,16 +1062,34 @@
return; return;
} }
const layerId = payload.new?.layer_id ?? payload.old?.layer_id; let layerId = payload.new?.layer_id ?? payload.old?.layer_id;
if (!layerId) return;
if (payload.event === "DELETE") {
if (!layerId)
layerId = layers.find((l) =>
(l.shapes ?? []).some((s) => s.id === id),
)?.id;
if (!layerId) return;
layers = layers.map((l) =>
l.id === layerId
? {
...l,
shapes: (l.shapes ?? []).filter((s) => s.id !== id),
}
: l,
);
if (selectedObjectId === id) deselectAll();
} else {
if (!layerId) return;
if (payload.event === "INSERT") { if (payload.event === "INSERT") {
layers = layers.map((l) => layers = layers.map((l) =>
l.id === layerId l.id === layerId
? { ? {
...l, ...l,
shapes: [ shapes: [
...(l.shapes ?? []).filter((s) => s.id !== id), ...(l.shapes ?? []).filter(
(s) => s.id !== id,
),
payload.new, payload.new,
], ],
} }
@@ -1081,16 +1106,7 @@
} }
: l, : l,
); );
} else if (payload.event === "DELETE") {
layers = layers.map((l) =>
l.id === layerId
? {
...l,
shapes: (l.shapes ?? []).filter((s) => s.id !== id),
} }
: l,
);
if (selectedObjectId === id) deselectAll();
} }
const layerIdx = layers.findIndex((l) => l.id === layerId); const layerIdx = layers.findIndex((l) => l.id === layerId);
@@ -1439,7 +1455,7 @@
> >
<span <span
class="material-symbols-rounded" class="material-symbols-rounded"
style={icon("", 13)}>close</span style={icon("", 13)}>delete</span
> >
</button> </button>
{/if} {/if}
@@ -1510,7 +1526,7 @@
> >
<span <span
class="material-symbols-rounded" class="material-symbols-rounded"
style={icon("", 13)}>close</span style={icon("", 13)}>delete</span
> >
</button> </button>
{/if} {/if}