From cfda0b75f8c24891ff3d1d710f31b3f0fafd042e Mon Sep 17 00:00:00 2001 From: smolgrrr Date: Mon, 20 Nov 2023 00:18:04 +1100 Subject: [PATCH] add PWA detector --- client/src/App.tsx | 2 + client/src/components/Forms/PostFormCard.tsx | 2 +- client/src/components/Header/Header.tsx | 3 - .../Modals/CheckMobile/CheckMobile.tsx | 73 +++++++++++++++++++ client/tailwind.config.js | 17 ++++- 5 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 client/src/components/Modals/CheckMobile/CheckMobile.tsx diff --git a/client/src/App.tsx b/client/src/App.tsx index 226fe4a..c189d16 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -4,6 +4,7 @@ import Settings from "./components/Settings"; import { BrowserRouter as Router, Route, Routes } from "react-router-dom"; import Thread from "./components/Thread"; import Header from "./components/Header/Header"; +import AddToHomeScreenPrompt from "./components/Modals/CheckMobile/CheckMobile"; function App() { @@ -15,6 +16,7 @@ function App() { } /> } /> + ); } diff --git a/client/src/components/Forms/PostFormCard.tsx b/client/src/components/Forms/PostFormCard.tsx index 8d25dd6..238a457 100644 --- a/client/src/components/Forms/PostFormCard.tsx +++ b/client/src/components/Forms/PostFormCard.tsx @@ -267,7 +267,7 @@ const NewNoteCard = ({ diff --git a/client/src/components/Modals/CheckMobile/CheckMobile.tsx b/client/src/components/Modals/CheckMobile/CheckMobile.tsx new file mode 100644 index 0000000..4233ac5 --- /dev/null +++ b/client/src/components/Modals/CheckMobile/CheckMobile.tsx @@ -0,0 +1,73 @@ +import React, { useState, useEffect } from 'react'; +import { XMarkIcon } from "@heroicons/react/24/solid"; +import { ArrowUpOnSquareIcon, PlusCircleIcon } from '@heroicons/react/24/outline'; + +declare global { + interface Navigator { + standalone?: boolean; + } +} + +const AddToHomeScreenPrompt: React.FC = () => { + const [inMobileBrowser, setInMobileBrowser] = useState(false); + + useEffect(() => { + const checkPWA = () => { + return ( + !window.navigator.standalone || + !window.matchMedia('(display-mode: standalone)').matches + ); + }; + + // Function to detect mobile browser + const detectMobileBrowser = () => { + return ( + (navigator.userAgent.match(/Android/i) || + navigator.userAgent.match(/webOS/i) || + navigator.userAgent.match(/iPhone/i) || + navigator.userAgent.match(/iPad/i) || + navigator.userAgent.match(/iPod/i) || + navigator.userAgent.match(/Windows Phone/i)) + ); + }; + + const timer = setTimeout(() => { + setInMobileBrowser(Boolean(checkPWA() && detectMobileBrowser())); + }, 2000); // 3000 milliseconds = 3 seconds + + // Cleanup function to clear the timeout if the component unmounts before the timeout finishes + return () => clearTimeout(timer); + }, []); + + if (!inMobileBrowser) { + return null; + } + + return ( +
+
+
+ Stay Wired +

Add Wired to your home screen for a better experience

+
    +
  • +
    + {'>'} Click on Share +
    +
  • +
  • +
    + {'>'} Click Add to Home Screen +
    +
  • +
+
+ +
+
+ ); +}; + +export default AddToHomeScreenPrompt; diff --git a/client/tailwind.config.js b/client/tailwind.config.js index 68dbaf4..ee90009 100644 --- a/client/tailwind.config.js +++ b/client/tailwind.config.js @@ -2,7 +2,22 @@ module.exports = { content: ["./src/**/*.{js,jsx,ts,tsx}"], theme: { - extend: {}, + extend: { + animation: { + 'fade-in': 'fadeIn 0.25s ease-in-out', + 'slide-up': 'slideUp 0.25s ease-in-out', + }, + keyframes: { + fadeIn: { + '0%': { opacity: '0' }, + '100%': { opacity: '1' }, + }, + slideUp: { + '0%': { transform: 'translateY(100%)' }, + '100%': { transform: 'translateY(0)' }, + }, + }, + }, }, plugins: [ require('@tailwindcss/forms'),