-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Start: new home page * Compressed itinerary into a more mobile friendly row * Tidy UI and show link to campaigns * Add empty state when rider has no campaigns for today * Pair with Max on new home stats query * Add: bike brigade week stat to rider home page. * Copy change * Add personalization to home page / change wording. * Add: show urgent delivery callout * Add: home page stats, CTA, and campaign_id list * fmt * Make urgent signup look more urgent * Add "Home" to rider sidebar, remove itinerary * Test: Home page. * Fmt + clean up image on desktop * Default to home page when logging in * Differentiat campaign list from urgent campaign list * Make suggested changes * Add: tests for suggested changes. * Simplify setup block * Fix: make requested changes. - Fix: reset showing_urgent_campaigns to false in handle params - Fix: Dial back red on "available campaigns" in campaign signup index - Add button to urgent campaign list to take rider back to full campaign list - Use better string list joining func (see Util.join) * Use ecto where rather than Enum.filter * Remove random bg-red-400 🙃 * Remove unecessary filter --------- Co-authored-by: Max Veytsman <[email protected]>
- Loading branch information
Showing
11 changed files
with
560 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
defmodule BikeBrigadeWeb.RiderHomeLive.Index do | ||
use BikeBrigadeWeb, :live_view | ||
|
||
alias BikeBrigade.{Delivery, Riders, Stats, LocalizedDateTime} | ||
|
||
import BikeBrigadeWeb.CampaignHelpers | ||
|
||
alias BikeBrigade.Utils | ||
|
||
@impl true | ||
def mount(_params, _session, socket) do | ||
today = LocalizedDateTime.today() | ||
rider_id = socket.assigns.current_user.rider_id | ||
|
||
{:ok, | ||
socket | ||
|> assign(:page, :home) | ||
|> assign(:page_title, "Home") | ||
|> assign(:stats, Stats.home_stats()) | ||
|> assign(:rider, Riders.get_rider!(rider_id)) | ||
|> assign(:urgent_campaigns, Delivery.list_urgent_campaigns()) | ||
|> load_itinerary(today)} | ||
end | ||
|
||
defp load_itinerary(socket, date) do | ||
rider_id = socket.assigns.current_user.rider_id | ||
|
||
if rider_id do | ||
socket | ||
|> assign( | ||
:campaign_riders, | ||
Riders.get_itinerary(rider_id, date) | ||
) | ||
else | ||
socket | ||
|> assign(:campaign_riders, []) | ||
|> put_flash(:error, "User is not associated with a rider!") | ||
end | ||
|> assign(:date, date) | ||
end | ||
|
||
defp get_location(assigns) do | ||
~H""" | ||
<div class="sm:flex sm:justify-between"> | ||
<p class="flex items-center"> | ||
<Heroicons.map_pin aria-label="Location" class="flex-shrink-0 w-4 h-4 mr-1 text-gray-400" /> | ||
<%= @campaign.location.address %> | ||
</p> | ||
</div> | ||
""" | ||
end | ||
|
||
defp get_pickup_window(assigns) do | ||
~H""" | ||
<div class="sm:flex sm:justify-between"> | ||
<p class="flex items-center"> | ||
<Heroicons.clock aria-label="Pickup Time" class="flex-shrink-0 w-4 h-4 mr-1 text-gray-400" /> | ||
<%= pickup_window(@campaign) %> | ||
</p> | ||
</div> | ||
""" | ||
end | ||
|
||
# Note Utils has a `humanized_task_count/1` which is similar but breaks | ||
# things down by delivery type | ||
defp delivery_count(tasks) do | ||
task_count = Utils.task_count(tasks) | ||
"#{task_count} #{Inflex.inflect("delivery", task_count)}" | ||
end | ||
|
||
defp has_urgent_campaigns?(urgent_campaigns) do | ||
Enum.count(urgent_campaigns) > 0 | ||
end | ||
|
||
defp num_unassigned_tasks_and_campaigns(urgent_campaigns) do | ||
# formats a string so that we see: "program 1, program 2, and program 3" (ie, we want that 'and') in there. | ||
campaign_ids = urgent_campaigns |> Enum.map(& &1.id) | ||
|
||
campaign_names = | ||
urgent_campaigns | ||
|> Enum.map(& &1.program.name) | ||
|> Enum.uniq() | ||
|> Utils.join() | ||
|
||
deliveries_without_riders = | ||
urgent_campaigns | ||
|> Enum.flat_map(& &1.tasks) | ||
|> Enum.count(fn task -> task.assigned_rider_id == nil end) | ||
|
||
{deliveries_without_riders, campaign_names, campaign_ids} | ||
end | ||
end |
Oops, something went wrong.