Starter Packs (#4332)
Co-authored-by: Dan Abramov <dan.abramov@gmail.com> Co-authored-by: Paul Frazee <pfrazee@gmail.com> Co-authored-by: Eric Bailey <git@esb.lol> Co-authored-by: Samuel Newman <mozzius@protonmail.com>
This commit is contained in:
parent
35f64535cb
commit
f089f45781
115 changed files with 6336 additions and 237 deletions
68
src/components/hooks/useStarterPackEntry.native.ts
Normal file
68
src/components/hooks/useStarterPackEntry.native.ts
Normal file
|
@ -0,0 +1,68 @@
|
|||
import React from 'react'
|
||||
|
||||
import {
|
||||
createStarterPackLinkFromAndroidReferrer,
|
||||
httpStarterPackUriToAtUri,
|
||||
} from 'lib/strings/starter-pack'
|
||||
import {isAndroid} from 'platform/detection'
|
||||
import {useHasCheckedForStarterPack} from 'state/preferences/used-starter-packs'
|
||||
import {useSetActiveStarterPack} from 'state/shell/starter-pack'
|
||||
import {DevicePrefs, Referrer} from '../../../modules/expo-bluesky-swiss-army'
|
||||
|
||||
export function useStarterPackEntry() {
|
||||
const [ready, setReady] = React.useState(false)
|
||||
const setActiveStarterPack = useSetActiveStarterPack()
|
||||
const hasCheckedForStarterPack = useHasCheckedForStarterPack()
|
||||
|
||||
React.useEffect(() => {
|
||||
if (ready) return
|
||||
|
||||
// On Android, we cannot clear the referral link. It gets stored for 90 days and all we can do is query for it. So,
|
||||
// let's just ensure we never check again after the first time.
|
||||
if (hasCheckedForStarterPack) {
|
||||
setReady(true)
|
||||
return
|
||||
}
|
||||
|
||||
// Safety for Android. Very unlike this could happen, but just in case. The response should be nearly immediate
|
||||
const timeout = setTimeout(() => {
|
||||
setReady(true)
|
||||
}, 500)
|
||||
|
||||
;(async () => {
|
||||
let uri: string | null | undefined
|
||||
|
||||
if (isAndroid) {
|
||||
const res = await Referrer.getGooglePlayReferrerInfoAsync()
|
||||
|
||||
if (res && res.installReferrer) {
|
||||
uri = createStarterPackLinkFromAndroidReferrer(res.installReferrer)
|
||||
}
|
||||
} else {
|
||||
const res = await DevicePrefs.getStringValueAsync(
|
||||
'starterPackUri',
|
||||
true,
|
||||
)
|
||||
|
||||
if (res) {
|
||||
uri = httpStarterPackUriToAtUri(res)
|
||||
DevicePrefs.setStringValueAsync('starterPackUri', null, true)
|
||||
}
|
||||
}
|
||||
|
||||
if (uri) {
|
||||
setActiveStarterPack({
|
||||
uri,
|
||||
})
|
||||
}
|
||||
|
||||
setReady(true)
|
||||
})()
|
||||
|
||||
return () => {
|
||||
clearTimeout(timeout)
|
||||
}
|
||||
}, [ready, setActiveStarterPack, hasCheckedForStarterPack])
|
||||
|
||||
return ready
|
||||
}
|
29
src/components/hooks/useStarterPackEntry.ts
Normal file
29
src/components/hooks/useStarterPackEntry.ts
Normal file
|
@ -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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue