Skip to content

Commit

Permalink
Added a named function for flexzone page grouping keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaddox5 committed Aug 28, 2023
1 parent 88ded56 commit feba683
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions lib/screens/v2/screen_data.ex
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ defmodule Screens.V2.ScreenData do
screen_data = fetch_data(config)

full_page_data = screen_data |> resolve_paging(refresh_rate) |> serialize()
paged_slot_data = screen_data |> get_paged_slots() |> serialize_paged_slots()
paged_slot_data = screen_data |> get_paged_slots() |> serialize_paged_slots(config.app_id)

response(data: %{full_page: full_page_data, flex_zone: paged_slot_data})
end
Expand Down Expand Up @@ -401,7 +401,7 @@ defmodule Screens.V2.ScreenData do
Template.position_widget_instances(layout, serialized_instance_map, paging_metadata)
end

defp serialize_paged_slots({instance_map, layout}) do
defp serialize_paged_slots({instance_map, layout}, app_id) do
# instance_map looks like:
# %{{page_index, slot_id} => instance}

Expand All @@ -410,14 +410,7 @@ defmodule Screens.V2.ScreenData do

instance_map
|> Enum.group_by(
fn
{paged_slot_id, instance} ->
if Map.has_key?(instance, :is_full_screen) and instance.is_full_screen do
Template.get_slot_id(paged_slot_id)
else
Template.get_page(paged_slot_id)
end
end,
&paged_slot_key(&1, app_id),
fn {paged_slot_id, instance} -> {Template.unpage(paged_slot_id), instance} end
)
# %{page_index => [{slot_id, instance}]}
Expand Down Expand Up @@ -495,4 +488,7 @@ defmodule Screens.V2.ScreenData do

:ok = ScreensByAlert.put_data(screen_id, alert_ids)
end

defp paged_slot_key({paged_slot_id, _}, :pre_fare_v2), do: Template.get_slot_id(paged_slot_id)
defp paged_slot_key({paged_slot_id, _}, _), do: Template.get_page(paged_slot_id)
end

0 comments on commit feba683

Please sign in to comment.