about summary refs log tree commit diff
path: root/src/components/hooks/useStarterPackEntry.ts
blob: dba801e0939c8e8e4985538a65c23792f50f8a11 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import React from 'react'

import {httpStarterPackUriToAtUri} from 'lib/strings/starter-pack'
import {useSetActiveStarterPack} from 'state/shell/starter-pack'

export function useStarterPackEntry() {
  const [ready, setReady] = React.useState(false)

  const setActiveStarterPack = useSetActiveStarterPack()

  React.useEffect(() => {
    const href = window.location.href
    const atUri = httpStarterPackUriToAtUri(href)

    if (atUri) {
      const url = new URL(href)
      // Determines if an App Clip is loading this landing page
      const isClip = url.searchParams.get('clip') === 'true'
      setActiveStarterPack({
        uri: atUri,
        isClip,
      })
    }

    setReady(true)
  }, [setActiveStarterPack])

  return ready
}