QF | Line Diagram PDF schedules - #3481
Conversation
joshlarson
left a comment
There was a problem hiding this comment.
Noice! Left two code-style suggestions - take 'em or leave 'em.
| date = Map.get(socket.assigns, :date, @date_time_module.now()) | ||
|
|
||
| pdfs = | ||
| Dotcom.RoutePdfs.fetch_and_choose_pdfs( | ||
| route_id, | ||
| date | ||
| ) |
There was a problem hiding this comment.
Suggestion (non-blocking): You could restructure this whole thing to first assign a date if missing, using assign_new, and then add a separate assign_pdfs function. Like so:
def mount(...) do
{:ok,
socket
|> assign(:route_id, route_id)
# ... more assigns
|> assign(:tab_params, tab_params)
|> assign_new(:date, &@date_time_module.now/0)
|> assign_pdfs()}
end
# ...
defp assign_pdfs(%{assigns: %{date: date}} = socket) do
pdfs =
Dotcom.RoutePdfs.fetch_and_choose_pdfs(
route_id,
date
)
assign(socket, :route_pdfs, pdfs)
endA few things to note about ☝️:
assign_new/3takes a 0-arity function, not a value, hence&@date_time_module.now/0rather than@date_time_module.now()- Given that
assign_pdfsis called afterassign_new(:date, ...), you wouldn't need to worry about handling the case where the socket doesn't have adateassigned.
I recognize that this is kind of an aesthetic thing - I find it easier to follow mount/3 when it's defined as a simple list of socket |> assign_this(...) |> do_that(...) |> assign_frobnicator(...). Hence why the comment is non-blocking 🙂
| case Map.get(assigns, :route_pdfs, []) do | ||
| {:error, _} -> [] | ||
| pdfs when is_list(pdfs) -> pdfs | ||
| end |
There was a problem hiding this comment.
Suggestion (non-blocking): Would it make sense to move this to the assigned route_pdfs field, rather than doing this logic in the component?
If you follow the suggestion in my earlier comment about adding an assign_pdfs/1 function, then I think that function could be a good place to transform {:error, _} into [] as well.
Scope
Asana Ticket: QF | 💈 PDF schedules
Implementation
Added Route PDF Schedules and Maps to the Right Rail of the new Line Diagram
Updated the styles to reflect the new design
Screenshots
How to test
http://localhost:4001/schedules/CR-NewBedford/line_new - (or any route with PDFs) Confirm that the PDF link shows up and goes to the correct PDF