Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show the ad for the mobile app to everyone not on an android #2203

Merged
merged 7 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 29 additions & 12 deletions assets/js/mobile-app-banner.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,45 @@
const isAlertsPage = () => {
const url = window.location.href;

return /\/alerts\/[\w.-]+/.test(url);
const isAlertsPage = url => {
return /\/alerts/.test(url);
};

const isIPhone = () => {
return /iPhone/.test(navigator.userAgent);
const isNotAndroid = () => {
return !/Android/.test(navigator.userAgent);
};

const isSchedulePage = () => {
const url = window.location.href;
const isNotCommuterRail = url => {
return !/\/schedules\/CR-/.test(url);
anthonyshull marked this conversation as resolved.
Show resolved Hide resolved
};

const isSchedulePage = url => {
return /\/schedules\/[\w.-]+\/line/.test(url);
};

const isStopPage = () => {
const url = window.location.href;

const isStopPage = url => {
return /\/stops\/[\w.-]+/.test(url);
};

const isTransitNearMePage = url => {
return /\/transit-near-me/.test(url);
};

const is = url => {
return (
isAlertsPage(url) ||
isSchedulePage(url) ||
isStopPage(url) ||
isTransitNearMePage(url)
);
};

const isNot = url => {
return isNotAndroid() && isNotCommuterRail(url);
};

// Show the mobile app banner
export default function mobileAppBanner() {
if (isIPhone() && (isAlertsPage() || isSchedulePage() || isStopPage())) {
const url = window.location.href;

if (is(url) && isNot(url)) {
document.querySelector("#mobile-app-banner").style.display = "block";
anthonyshull marked this conversation as resolved.
Show resolved Hide resolved
}
}
8 changes: 4 additions & 4 deletions assets/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"leaflet": "^1.4.0",
"leaflet-rotatedmarker": "^0.2.0",
"lodash": "^4.17.21",
"mbta_metro": "^0.0.49",
"mbta_metro": "^0.0.50",
"mobile-detect": "^1.4.5",
"phoenix": "file:../deps/phoenix",
"phoenix_html": "file:../deps/phoenix_html",
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ defmodule DotCom.Mixfile do
{:jason, "1.4.4", override: true},
{:logster, "1.1.1"},
{:mail, "0.3.1"},
{:mbta_metro, "0.0.49"},
{:mbta_metro, "0.0.50"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was upgrading metro necessary as part of this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but we might as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't block approval on this, but in general I don't like lumping library upgrades together with unrelated features. It runs the risk of creating hard-to-revert surprises, especially when the library is in alpha, as metro is.

{:mock, "0.3.8", [only: :test]},
{:mox, "1.1.0", [only: :test]},
{:nebulex, "2.6.3"},
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"makeup_elixir": {:hex, :makeup_elixir, "0.16.2", "627e84b8e8bf22e60a2579dad15067c755531fea049ae26ef1020cad58fe9578", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "41193978704763f6bbe6cc2758b84909e62984c7752b3784bd3c218bb341706b"},
"makeup_erlang": {:hex, :makeup_erlang, "1.0.1", "c7f58c120b2b5aa5fd80d540a89fdf866ed42f1f3994e4fe189abebeab610839", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "8a89a1eeccc2d798d6ea15496a6e4870b75e014d1af514b1b71fa33134f57814"},
"makeup_html": {:hex, :makeup_html, "0.1.1", "c3d4abd39d5f7e925faca72ada6e9cc5c6f5fa7cd5bc0158315832656cf14d7f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "44f2a61bc5243645dd7fafeaa6cc28793cd22f3c76b861e066168f9a5b2c26a4"},
"mbta_metro": {:hex, :mbta_metro, "0.0.49", "a2fc42c79ed3f6ca16c29c9b6fb254dff739ad3f4568a852d02dc93bc3b44f2f", [:mix], [{:heroicons, "0.5.6", [hex: :heroicons, repo: "hexpm", optional: true]}, {:jason, "1.4.4", [hex: :jason, repo: "hexpm", optional: false]}, {:phoenix, "1.7.14", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_live_view, "1.0.0-rc.6", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:phoenix_storybook, "0.6.4", [hex: :phoenix_storybook, repo: "hexpm", optional: false]}, {:timex, "3.7.11", [hex: :timex, repo: "hexpm", optional: false]}], "hexpm", "fa1c321860d774445595be88b7b1d70ced29761181a3c5389f032df32c05aa34"},
"mbta_metro": {:hex, :mbta_metro, "0.0.50", "26592935c4f2016d436ce277998e2ce67c0787cfd20b20e9bd5d5db1e57a2c10", [:mix], [{:heroicons, "0.5.6", [hex: :heroicons, repo: "hexpm", optional: true]}, {:jason, "1.4.4", [hex: :jason, repo: "hexpm", optional: false]}, {:phoenix, "1.7.14", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_live_view, "1.0.0-rc.6", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:phoenix_storybook, "0.6.4", [hex: :phoenix_storybook, repo: "hexpm", optional: false]}, {:timex, "3.7.11", [hex: :timex, repo: "hexpm", optional: false]}], "hexpm", "ff5e9c3862556a3424f458a05e224fad7e634193bd75c1f1e24df9e01bdd2152"},
"meck": {:hex, :meck, "0.9.2", "85ccbab053f1db86c7ca240e9fc718170ee5bda03810a6292b5306bf31bae5f5", [:rebar3], [], "hexpm", "81344f561357dc40a8344afa53767c32669153355b626ea9fcbc8da6b3045826"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
"mime": {:hex, :mime, "2.0.6", "8f18486773d9b15f95f4f4f1e39b710045fa1de891fada4516559967276e4dc2", [:mix], [], "hexpm", "c9945363a6b26d747389aac3643f8e0e09d30499a138ad64fe8fd1d13d9b153e"},
Expand Down
Loading