Skip to content

Commit

Permalink
Review: handle sorting in live view not in context
Browse files Browse the repository at this point in the history
  • Loading branch information
teesloane committed Apr 26, 2024
1 parent 62c8228 commit 39635a2
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
4 changes: 1 addition & 3 deletions lib/bike_brigade/delivery.ex
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,7 @@ defmodule BikeBrigade.Delivery do
|> Repo.preload(:location)

# Does a nested preload to get tasks' assigned riders without doing an extra db query
tasks =
Repo.preload(all_tasks, assigned_rider: fn _ -> all_riders end)
|> Enum.sort_by(fn t -> t.dropoff_location.neighborhood.name end)
tasks = Repo.preload(all_tasks, assigned_rider: fn _ -> all_riders end)

riders = Repo.preload(all_riders, assigned_tasks: fn _ -> all_tasks end)

Expand Down
2 changes: 1 addition & 1 deletion lib/bike_brigade_web/live/campaign_signup_live/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ defmodule BikeBrigadeWeb.CampaignSignupLive.Show do

def handle_event("signup_rider", %{"rider_id" => rider_id, "task_id" => task_id}, socket) do
%{campaign: campaign, tasks: tasks} = socket.assigns

task = Enum.find(tasks, fn task -> task.id == task_id end)

attrs = %{
Expand Down Expand Up @@ -173,6 +172,7 @@ defmodule BikeBrigadeWeb.CampaignSignupLive.Show do

defp assign_campaign(socket, campaign) do
{riders, tasks} = Delivery.campaign_riders_and_tasks(campaign)
tasks = Enum.sort_by(tasks, fn t -> t.dropoff_location.neighborhood.name end)

socket
|> assign(:campaign, campaign)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</:col>
<:col :let={task} label="Recipient"><%= first_initial(task.dropoff_name) %></:col>
<:col :let={task} label="Dropoff Neighbourhood">
<%= task.dropoff_location.neighborhood.name %>
<%= Locations.neighborhood(task.dropoff_location) %>
</:col>
<:col :let={task} label="Notes"><%= task.delivery_status_notes %>
<.truncated_riders_notes note={task.rider_notes || "--"} /></:col>
Expand Down

0 comments on commit 39635a2

Please sign in to comment.