diff --git a/client/test/stop_test.gleam b/client/test/stop_test.gleam index 0374115..61cea28 100644 --- a/client/test/stop_test.gleam +++ b/client/test/stop_test.gleam @@ -17,7 +17,7 @@ import subway_gleam/shared/util/time.{type Time, Time} import subway_gleam/client/stop.{type Msg, ToggleFavBtnPressed, update} as _ import subway_gleam/shared/route/stop.{ - type Arrival, type Model, Arrival, Model, Transfer, view, + type Arrival, type Model, Arrival, Model, view, } as _ pub fn arrivals_are_in_correct_format_test() -> Nil { @@ -37,28 +37,6 @@ pub fn arrivals_are_in_correct_format_test() -> Nil { ) } -pub fn transfer_for_current_stop_is_highlighted_test() -> Nil { - let transfer = Transfer(destination: stop_id_a27, routes: [route_bullet_a]) - - let app = - simulate( - Model(..default_model(), transfers: [ - Transfer(destination: st.StopId("0"), routes: []), - transfer, - Transfer(destination: st.StopId("1"), routes: []), - Transfer(destination: st.StopId("2"), routes: []), - ]), - ) - - let transfers = query.find_all(transfers(), in: simulate.view(app)) - let highlighted = - list.map(transfers, fn(transfer) { - transfer |> query.matches(query.class("highlight")) - }) - - assert highlighted == [False, True, False, False] -} - pub fn highlighted_train_is_highlighted_test() -> Nil { let highlighted = Arrival( @@ -211,8 +189,3 @@ fn arrival_lists() -> Query { fn arrival_lis() -> Query { query.child(of: arrival_lists(), matching: query.tag("li")) } - -fn transfers() -> Query { - query.element(query.id("transfers")) - |> query.descendant(matching: query.class("bullet-group")) -} diff --git a/server/src/subway_gleam/server/route/stop.gleam b/server/src/subway_gleam/server/route/stop.gleam index 2dcaf6a..3a2edfd 100644 --- a/server/src/subway_gleam/server/route/stop.gleam +++ b/server/src/subway_gleam/server/route/stop.gleam @@ -134,6 +134,7 @@ fn transfers(schedule: st.Schedule, stop: st.Stop) -> List(stop.Transfer) { |> dict.get(stop.id) |> result.unwrap(or: set.new()) |> set.map(fn(transfer) { + let st.StopId(desination_id) = transfer.destination let routes = schedule |> st.daytime_routes(for: transfer.destination) @@ -145,7 +146,11 @@ fn transfers(schedule: st.Schedule, stop: st.Stop) -> List(stop.Transfer) { |> list.sort(st.route_compare) |> list.map(route_bullet.from_route_data) - stop.Transfer(destination: transfer.destination, routes:) + stop.Transfer( + destination_url: "/stop/" <> desination_id <> "/", + routes:, + highlighted: transfer.destination == stop.id, + ) }) // TODO: also need to sort each group in sort order |> set.to_list diff --git a/shared/src/subway_gleam/shared/route/stop.gleam b/shared/src/subway_gleam/shared/route/stop.gleam index cf8f49d..f5cc6ea 100644 --- a/shared/src/subway_gleam/shared/route/stop.gleam +++ b/shared/src/subway_gleam/shared/route/stop.gleam @@ -23,7 +23,6 @@ import subway_gleam/shared/component/route_bullet.{ import subway_gleam/shared/route/stops import subway_gleam/shared/util import subway_gleam/shared/util/live_status.{type LiveStatus} -import subway_gleam/shared/util/stop_id_json import subway_gleam/shared/util/time.{type Time} import subway_gleam/shared/util/timestamp_json @@ -52,7 +51,7 @@ pub type Model { // TODO: should the Msg type be moved in here? pub fn view(model: Model, toggle_fav_btn_pressed_msg: msg) -> Element(msg) { let Model( - id:, + id: _, name:, last_updated:, transfers:, @@ -75,14 +74,12 @@ pub fn view(model: Model, toggle_fav_btn_pressed_msg: msg) -> Element(msg) { let transfers = list.map(transfers, fn(transfer) { let routes = list.map(transfer.routes, route_bullet.route_bullet) - let highlighted = transfer.destination == id - let st.StopId(id) = transfer.destination html.a( [ attribute.class("bullet-group"), - attribute.classes([#("highlight", highlighted)]), - attribute.href("/stop/" <> id <> "/"), + attribute.classes([#("highlight", transfer.highlighted)]), + attribute.href(transfer.destination_url), ], routes, ) @@ -250,22 +247,28 @@ pub fn model_to_json(model: Model) -> json.Json { } pub type Transfer { - Transfer(destination: st.StopId, routes: List(route_bullet.RouteBullet)) + Transfer( + destination_url: String, + routes: List(route_bullet.RouteBullet), + highlighted: Bool, + ) } fn transfer_decoder() -> decode.Decoder(Transfer) { - use destination <- decode.field("destination", stop_id_json.decoder()) + use destination_url <- decode.field("destination_url", decode.string) use routes <- decode.field("routes", decode.list(route_bullet.decoder())) + use highlighted <- decode.field("highlighted", decode.bool) - decode.success(Transfer(destination:, routes:)) + decode.success(Transfer(destination_url:, routes:, highlighted:)) } fn transfer_to_json(transfer: Transfer) -> json.Json { - let Transfer(destination:, routes:) = transfer + let Transfer(destination_url:, routes:, highlighted:) = transfer json.object([ - #("destination", stop_id_json.to_json(destination)), + #("destination", json.string(destination_url)), #("routes", json.array(routes, route_bullet.to_json)), + #("higlighted", json.bool(highlighted)), ]) }