This commit is contained in:
AlacrisDevs
2026-02-08 23:51:49 +02:00
parent 302fc69218
commit 4ee2c0ac07
3 changed files with 21 additions and 1 deletions

View File

@@ -266,7 +266,8 @@ export function subscribeToMapLayers(
onShapeChange: (payload: RealtimeMapPayload<MapShape>) => void, onShapeChange: (payload: RealtimeMapPayload<MapShape>) => void,
) { ) {
const layerIdSet = new Set(layerIds); const layerIdSet = new Set(layerIds);
const channel = supabase.channel(`map:${layerIds.join(',')}`); const channelName = `map:${layerIds[0]?.slice(0, 8) ?? 'x'}-${Date.now()}`;
const channel = supabase.channel(channelName);
channel channel
.on('postgres_changes', { event: '*', schema: 'public', table: 'map_pins' }, .on('postgres_changes', { event: '*', schema: 'public', table: 'map_pins' },

View File

@@ -13,6 +13,7 @@
type MapPin as MapPinType, type MapPin as MapPinType,
type MapShape, type MapShape,
type RealtimeMapPayload, type RealtimeMapPayload,
fetchMapLayers,
createMapLayer, createMapLayer,
updateMapLayer, updateMapLayer,
deleteMapLayer, deleteMapLayer,
@@ -1118,6 +1119,20 @@
await import("leaflet/dist/leaflet.css"); await import("leaflet/dist/leaflet.css");
L = leaflet.default ?? leaflet; L = leaflet.default ?? leaflet;
// Always fetch fresh data from DB so expand/collapse gets latest state
try {
const fresh = await fetchMapLayers(supabase, departmentId);
if (fresh.length > 0) {
layers = fresh;
activeLayerIdx = Math.min(activeLayerIdx, layers.length - 1);
showLayerOnMap(layers[activeLayerIdx]);
setupRealtime();
return;
}
} catch {
// Fall through to initialLayers or create default
}
if (layers.length === 0) { if (layers.length === 0) {
try { try {
const layer = await createMapLayer(supabase, departmentId, { const layer = await createMapLayer(supabase, departmentId, {

View File

@@ -0,0 +1,4 @@
-- Revert REPLICA IDENTITY FULL back to DEFAULT
ALTER TABLE map_layers REPLICA IDENTITY DEFAULT;
ALTER TABLE map_pins REPLICA IDENTITY DEFAULT;
ALTER TABLE map_shapes REPLICA IDENTITY DEFAULT;