feat: explicitly reset filter state on room geometry change

This commit is contained in:
2026-05-20 18:20:42 +02:00
parent 6b79c4ca29
commit c9b65c7013
+19 -2
View File
@@ -93,12 +93,23 @@ defmodule Localiser.Localisation.Tag.Filter do
end
end
# Room geometry changed: reload the rooms cache so containment checks stay accurate.
@impl true
def handle_info({event, _}, state) when event in [:room_created, :room_updated] do
def handle_info({:room_created, _room}, state) do
{:noreply, %{state | rooms: load_rooms()}}
end
def handle_info({:room_updated, updated_room}, state) do
new_rooms = load_rooms()
old_room = Enum.find(state.rooms, &(&1.id == updated_room.id))
if geometry_changed?(old_room, updated_room) do
{:ok, new_filter_state} = state.filter_module.init([], rooms: new_rooms)
{:noreply, %{state | rooms: new_rooms, filter_state: new_filter_state}}
else
{:noreply, %{state | rooms: new_rooms}}
end
end
def handle_info({:room_deleted, _room_id, _floor_id}, state) do
{:noreply, %{state | rooms: load_rooms()}}
end
@@ -131,6 +142,12 @@ defmodule Localiser.Localisation.Tag.Filter do
|> Enum.flat_map(& &1.rooms)
end
defp geometry_changed?(nil, _), do: true
defp geometry_changed?(old, new) do
old.x != new.x or old.y != new.y or
old.width != new.width or old.height != new.height
end
defp find_room(rooms, x, y) do
Enum.find(rooms, fn room ->
ox = room.x || 0.0