Skip to content

Commit

Permalink
added app-store detctor for directing users to the right app store ba…
Browse files Browse the repository at this point in the history
…sed on device OS, intended for when scanning an app QR Code
  • Loading branch information
Quinn Patwardhan committed Jul 23, 2023
1 parent 9b5d01f commit df170e3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"@types/node": "^16.18.3",
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.9",
"platform": "^1.3.6",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-ga": "^3.3.1",
Expand Down
5 changes: 5 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Solutions from "./Pages/Solutions";
import Contact from "./Pages/Contact";
import { Helmet } from "react-helmet";
import Projects from "./Pages/Projects";
import AppStoreRedirecter from "./Pages/AppStoreRedirecter";

function App() {
return (
Expand All @@ -34,6 +35,10 @@ function App() {
</Helmet>
<Router>
<Routes>
<Route
path="/determine-appstore/ios/:IOS_LINK/android/:ANDROID_LINK"
element={<AppStoreRedirecter />}
/>
<Route path="/blog/post/:id" element={<BlogPost />} />
<Route path="/login/:des" element={<Login />} />
<Route path="/login" element={<Login />} />
Expand Down
33 changes: 33 additions & 0 deletions src/Pages/AppStoreRedirecter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React, { useEffect } from "react";
import { Routes, Route, useParams } from "react-router-dom";

export default function AppStoreRedirecter() {
let { IOS_LINK, ANDROID_LINK } = useParams();
function detectMobileOS() {
const userAgent = navigator.userAgent;
if (/android/i.test(userAgent)) {
return "Android";
} else if (/iPad|iPhone|iPod/i.test(userAgent)) {
return "iOS";
} else {
return "Unknown";
}
}
useEffect(() => {
console.log(IOS_LINK);
console.log(ANDROID_LINK);
if (detectMobileOS() === "iOS") {
window.location.replace(new URL(IOS_LINK ?? ""));
} else if (detectMobileOS() === "Android") {
window.location.replace(new URL(ANDROID_LINK ?? ""));
} else {
window.location.replace(new URL("https://quinnpatwardhan.com"));
}
}, []);

return (
<div>
{IOS_LINK} - {ANDROID_LINK}
</div>
);
}

0 comments on commit df170e3

Please sign in to comment.