about summary refs log tree commit diff
path: root/src/components/hooks/useStarterPackEntry.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/hooks/useStarterPackEntry.ts')
-rw-r--r--src/components/hooks/useStarterPackEntry.ts29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/components/hooks/useStarterPackEntry.ts b/src/components/hooks/useStarterPackEntry.ts
new file mode 100644
index 000000000..dba801e09
--- /dev/null
+++ b/src/components/hooks/useStarterPackEntry.ts
@@ -0,0 +1,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
+}