From f53dcbb5a0209b71e79365be02a55997263aba40 Mon Sep 17 00:00:00 2001 From: Jeff Davidson Date: Mon, 21 Oct 2024 21:41:30 -0700 Subject: [PATCH] Revert DeepLinks in favor of regular links. This component was originally added in 2017 to deep link to native Sheets/Docs apps when installed on mobile devices. On reasonably modern devices, regular HTTP links should be intercepted by native apps when present, so no special machinery is needed. Fixes #1963 Fixes #2282 --- imports/client/components/DeepLink.tsx | 80 ------------------- imports/client/components/DocumentDisplay.tsx | 12 +-- 2 files changed, 3 insertions(+), 89 deletions(-) delete mode 100644 imports/client/components/DeepLink.tsx diff --git a/imports/client/components/DeepLink.tsx b/imports/client/components/DeepLink.tsx deleted file mode 100644 index 5caf3485e..000000000 --- a/imports/client/components/DeepLink.tsx +++ /dev/null @@ -1,80 +0,0 @@ -import { Meteor } from "meteor/meteor"; -import React, { useCallback, useState } from "react"; - -interface DeepLinkProps extends React.HTMLAttributes { - children: React.ReactNode; - nativeUrl: string; - browserUrl: string; -} - -enum DeepLinkLoadState { - IDLE = "idle", - ATTEMPTING_NATIVE = "attemptingNative", -} - -type DeepLinkState = - | { - state: DeepLinkLoadState.IDLE; - } - | { - state: DeepLinkLoadState.ATTEMPTING_NATIVE; - startNativeLoad: Date; - }; - -const DeepLink = ({ - children, - nativeUrl, - browserUrl, - ...rest -}: DeepLinkProps) => { - const [state, setState] = useState({ - state: DeepLinkLoadState.IDLE, - }); - - const browserOpen = useCallback(() => { - window.open(browserUrl, "_blank"); - }, [browserUrl]); - - const onAttemptingNativeTimeout = useCallback(() => { - if (state.state === DeepLinkLoadState.IDLE) { - return; - } - - setState({ state: DeepLinkLoadState.IDLE }); - if (new Date().getTime() - state.startNativeLoad.getTime() < 10000) { - browserOpen(); - } - }, [state, browserOpen]); - - const onClick = useCallback( - (e: React.MouseEvent) => { - e.preventDefault(); - // window.orientation is a good proxy for mobile device - if (window.screen?.orientation) { - setState({ - state: DeepLinkLoadState.ATTEMPTING_NATIVE, - startNativeLoad: new Date(), - }); - Meteor.setTimeout(onAttemptingNativeTimeout, 25); - } else { - browserOpen(); - } - }, - [browserOpen, onAttemptingNativeTimeout], - ); - - const nativeIframe = () => { - return ( -