Skip to content

Commit

Permalink
[C-2418] Fix mobile web open in app banner (#3173)
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondjacobson committed Apr 7, 2023
1 parent 443ee56 commit 98c33af
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ async function handleEvent(event) {

const is204 = pathname === '/204'
if (is204) {
return new Response(undefined, { status: 204 })
const response = new Response(undefined, { status: 204 })
response.headers.set('access-control-allow-methods', '*')
response.headers.set('access-control-allow-origin', '*')
return response
}

const isBot = checkIsBot(userAgent)
Expand Down
10 changes: 1 addition & 9 deletions apps/audius-client/packages/web/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,10 @@ import './services/webVitals'
import './index.css'

type AudiusAppProps = {
setReady: () => void
isReady: boolean
shouldShowPopover: boolean
}

const AudiusApp = ({
setReady,
isReady,
shouldShowPopover
}: AudiusAppProps) => {
const AudiusApp = ({ shouldShowPopover }: AudiusAppProps) => {
return (
<Provider store={store}>
<ConnectedRouter history={history}>
Expand All @@ -50,8 +44,6 @@ const AudiusApp = ({
<AppErrorBoundary>
<CoinbasePayButtonProvider>
<App
setReady={setReady}
isReady={isReady}
mainContentRef={mainContentRef}
shouldShowPopover={shouldShowPopover}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ const springProps = {
}

type AppRedirectPopoverProps = {
enablePopover: boolean
incrementScroll: () => void
decrementScroll: () => void
onBeforeClickApp?: () => void
Expand All @@ -85,7 +84,6 @@ type AppRedirectPopoverProps = {
* if no app is installed.
*/
export const AppRedirectPopover = ({
enablePopover,
incrementScroll,
decrementScroll,
onBeforeClickApp = () => {},
Expand All @@ -95,8 +93,8 @@ export const AppRedirectPopover = ({

const [animDelay, setAnimDelay] = useState(false)
useEffect(() => {
enablePopover && setTimeout(() => setAnimDelay(true), 1000)
}, [enablePopover])
setTimeout(() => setAnimDelay(true), 1000)
}, [])

const shouldShow =
!matchPath(window.location.pathname, { path: '/', exact: true }) &&
Expand Down
2 changes: 0 additions & 2 deletions apps/audius-client/packages/web/src/pages/App.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { MutableRefObject } from 'react'

type AppProps = {
setReady: () => void
isReady: boolean
mainContentRef: MutableRefObject<HTMLDivElement | undefined>
shouldShowPopover: boolean
}
Expand Down
21 changes: 0 additions & 21 deletions apps/audius-client/packages/web/src/pages/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,21 +364,6 @@ class App extends Component {
this.setState({ showWeb3ErrorBanner: true })
}

// Once the user is loaded, we can mark the page as ready for UI
// Alternatively, if the page is the signup page, say we're ready without a user
// This is necessary for the AppRedirectPopover to load
if (
(prevProps.accountStatus === Status.LOADING &&
this.props.accountStatus !== Status.LOADING) ||
matchPath(getPathname(this.props.location), {
path: SIGN_UP_PAGE,
exact: true
})
) {
// Let the UI flush
setImmediate(this.props.setReady)
}

if (prevProps.theme !== this.props.theme) {
this.handleTheme()
}
Expand Down Expand Up @@ -452,7 +437,6 @@ class App extends Component {
render() {
const {
theme,
isReady,
incrementScroll,
decrementScroll,
shouldShowPopover,
Expand Down Expand Up @@ -971,11 +955,9 @@ class App extends Component {
</Suspense>
</div>
<PlayBarProvider />

<Suspense fallback={null}>
<Modals />
</Suspense>

{
<Suspense fallback={null}>
<ConnectedMusicConfetti />
Expand All @@ -986,19 +968,16 @@ class App extends Component {
<RewardClaimedToast />
</Suspense>
}

{/* Non-mobile */}
{!isMobileClient ? <Konami /> : null}
{!isMobileClient ? <ConfirmerPreview /> : null}
{!isMobileClient ? <DiscoveryNodeSelection /> : null}
{!isMobileClient ? <Visualizer /> : null}
{!isMobileClient ? <PinnedTrackConfirmation /> : null}
{!isMobileClient ? <DevModeMananger /> : null}

{/* Mobile-only */}
{isMobileClient && shouldShowPopover ? (
<AppRedirectPopover
enablePopover={isReady}
incrementScroll={incrementScroll}
decrementScroll={decrementScroll}
/>
Expand Down
7 changes: 1 addition & 6 deletions apps/audius-client/packages/web/src/pages/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@ describe('smoke test', () => {
ReactDOM.render(
<Provider store={store}>
<ConnectedRouter history={history}>
<App
shouldShowPopover={false}
isReady
setReady={() => {}}
mainContentRef={mainContentRef}
/>
<App shouldShowPopover={false} mainContentRef={mainContentRef} />
</ConnectedRouter>
</Provider>,
rootNode
Expand Down
11 changes: 2 additions & 9 deletions apps/audius-client/packages/web/src/root.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Suspense, useState, useEffect, useCallback, lazy } from 'react'
import { Suspense, useState, useEffect, lazy } from 'react'

import { useAsync } from 'react-use'

Expand All @@ -23,7 +23,6 @@ const isPublicSiteSubRoute = (location = window.location) => {
const clientIsElectron = isElectron()

const Root = () => {
const [dappReady, setDappReady] = useState(false)
const [renderPublicSite, setRenderPublicSite] = useState(isPublicSiteRoute())
const isMobileClient = useIsMobile()

Expand All @@ -38,8 +37,6 @@ const Root = () => {
}
}, [])

const setReady = useCallback(() => setDappReady(true), [])

const [shouldShowPopover, setShouldShowPopover] = useState(true)

const shouldRedirectToApp = foundUser && !isPublicSiteSubRoute()
Expand All @@ -58,11 +55,7 @@ const Root = () => {

return (
<>
<Dapp
isReady={dappReady}
setReady={setReady}
shouldShowPopover={shouldShowPopover}
/>
<Dapp shouldShowPopover={shouldShowPopover} />
</>
)
}
Expand Down

0 comments on commit 98c33af

Please sign in to comment.