Skip to content

Commit

Permalink
hotfix error on empty applications
Browse files Browse the repository at this point in the history
  • Loading branch information
adriansalamon committed Aug 28, 2024
1 parent 26ff94a commit 6e1188b
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lib/haj_web/live/applications_live/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ defmodule HajWeb.ApplicationsLive.Index do
applications = Applications.list_applications_for_show(current_spex.id)

most_popular_group =
applications
|> Enum.flat_map(fn app -> app.application_show_groups end)
|> Enum.group_by(fn asg -> asg.show_group_id end)
|> Enum.map(fn {_, asgs} -> {hd(asgs).show_group.group, length(asgs)} end)
|> Enum.sort_by(fn {_, asgs} -> asgs end, :desc)
|> Enum.take(1)
|> hd()
|> elem(0)
case applications do
[] ->
%Spex.Group{name: "Inga ansökningar"}

apps ->
apps
|> Enum.flat_map(fn app -> app.application_show_groups end)
|> Enum.group_by(fn asg -> asg.show_group_id end)
|> Enum.map(fn {_, asgs} -> {hd(asgs).show_group.group, length(asgs)} end)
|> Enum.sort_by(fn {_, asgs} -> asgs end, :desc)
|> Enum.take(1)
|> List.first()
|> elem(0)
end

stats = %{
apps: length(applications),
Expand Down

0 comments on commit 6e1188b

Please sign in to comment.