Merge branch 'hailey/rework-next-check' into hailey/signup-screen-starter-context
This commit is contained in:
@@ -3,20 +3,27 @@ import React from 'react'
|
|||||||
import {createStarterPackLinkFromAndroidReferrer} from 'lib/strings/starter-pack'
|
import {createStarterPackLinkFromAndroidReferrer} from 'lib/strings/starter-pack'
|
||||||
import {isAndroid} from 'platform/detection'
|
import {isAndroid} from 'platform/detection'
|
||||||
import {useSetCurrentStarterPack} from 'state/preferences/starter-pack'
|
import {useSetCurrentStarterPack} from 'state/preferences/starter-pack'
|
||||||
import {useUsedStarterPacks} from 'state/preferences/used-starter-packs'
|
import {
|
||||||
|
useHasCheckedForStarterPack,
|
||||||
|
useSetHasCheckedForStarterPack,
|
||||||
|
} from 'state/preferences/used-starter-packs'
|
||||||
import SwissArmyKnife from '../../../modules/expo-bluesky-swiss-army'
|
import SwissArmyKnife from '../../../modules/expo-bluesky-swiss-army'
|
||||||
import GooglePlayReferrer from '../../../modules/expo-google-play-referrer'
|
import GooglePlayReferrer from '../../../modules/expo-google-play-referrer'
|
||||||
|
|
||||||
export function useStarterPackEntry() {
|
export function useStarterPackEntry() {
|
||||||
const [ready, setReady] = React.useState(false)
|
const [ready, setReady] = React.useState(false)
|
||||||
const setCurrentStarterPack = useSetCurrentStarterPack()
|
const setCurrentStarterPack = useSetCurrentStarterPack()
|
||||||
const usedStarterPacks = useUsedStarterPacks()
|
const hasCheckedForStarterPack = useHasCheckedForStarterPack()
|
||||||
const hasRan = React.useRef(false)
|
const setHasCheckedForStarterPack = useSetHasCheckedForStarterPack()
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (ready || hasRan.current) return
|
if (ready) return
|
||||||
|
if (hasCheckedForStarterPack) {
|
||||||
|
setReady(true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
hasRan.current = true
|
setHasCheckedForStarterPack(true)
|
||||||
;(async () => {
|
;(async () => {
|
||||||
let uri: string | null | undefined
|
let uri: string | null | undefined
|
||||||
|
|
||||||
@@ -30,7 +37,7 @@ export function useStarterPackEntry() {
|
|||||||
uri = await SwissArmyKnife.getStringValueAsync('starterPackUri', true)
|
uri = await SwissArmyKnife.getStringValueAsync('starterPackUri', true)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uri && !usedStarterPacks?.includes(uri)) {
|
if (uri) {
|
||||||
setCurrentStarterPack({
|
setCurrentStarterPack({
|
||||||
uri,
|
uri,
|
||||||
})
|
})
|
||||||
@@ -38,7 +45,12 @@ export function useStarterPackEntry() {
|
|||||||
|
|
||||||
setReady(true)
|
setReady(true)
|
||||||
})()
|
})()
|
||||||
}, [ready, setCurrentStarterPack, usedStarterPacks])
|
}, [
|
||||||
|
ready,
|
||||||
|
setCurrentStarterPack,
|
||||||
|
setHasCheckedForStarterPack,
|
||||||
|
hasCheckedForStarterPack,
|
||||||
|
])
|
||||||
|
|
||||||
return ready
|
return ready
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,12 +15,10 @@ import {useAgent} from '#/state/session'
|
|||||||
import {useOnboardingDispatch} from '#/state/shell'
|
import {useOnboardingDispatch} from '#/state/shell'
|
||||||
import {uploadBlob} from 'lib/api'
|
import {uploadBlob} from 'lib/api'
|
||||||
import {useRequestNotificationsPermission} from 'lib/notifications/notifications'
|
import {useRequestNotificationsPermission} from 'lib/notifications/notifications'
|
||||||
import {makeStarterPackLink} from 'lib/routes/links'
|
|
||||||
import {
|
import {
|
||||||
useCurrentStarterPack,
|
useCurrentStarterPack,
|
||||||
useSetCurrentStarterPack,
|
useSetCurrentStarterPack,
|
||||||
} from 'state/preferences/starter-pack'
|
} from 'state/preferences/starter-pack'
|
||||||
import {useAddUsedStarterPack} from 'state/preferences/used-starter-packs'
|
|
||||||
import {
|
import {
|
||||||
DescriptionText,
|
DescriptionText,
|
||||||
OnboardingControls,
|
OnboardingControls,
|
||||||
@@ -50,7 +48,6 @@ export function StepFinished() {
|
|||||||
const requestNotificationsPermission = useRequestNotificationsPermission()
|
const requestNotificationsPermission = useRequestNotificationsPermission()
|
||||||
const currentStarterPack = useCurrentStarterPack()
|
const currentStarterPack = useCurrentStarterPack()
|
||||||
const setCurrentStarterPack = useSetCurrentStarterPack()
|
const setCurrentStarterPack = useSetCurrentStarterPack()
|
||||||
const addUsedStarterPack = useAddUsedStarterPack()
|
|
||||||
|
|
||||||
const finishOnboarding = React.useCallback(async () => {
|
const finishOnboarding = React.useCallback(async () => {
|
||||||
setSaving(true)
|
setSaving(true)
|
||||||
@@ -102,7 +99,6 @@ export function StepFinished() {
|
|||||||
initialFeed: 'following',
|
initialFeed: 'following',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
addUsedStarterPack(makeStarterPackLink(starterPack))
|
|
||||||
}
|
}
|
||||||
})(),
|
})(),
|
||||||
(async () => {
|
(async () => {
|
||||||
@@ -182,7 +178,6 @@ export function StepFinished() {
|
|||||||
currentStarterPack,
|
currentStarterPack,
|
||||||
state,
|
state,
|
||||||
requestNotificationsPermission,
|
requestNotificationsPermission,
|
||||||
addUsedStarterPack,
|
|
||||||
setCurrentStarterPack,
|
setCurrentStarterPack,
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ export const schema = z.object({
|
|||||||
isClip: z.boolean().optional(),
|
isClip: z.boolean().optional(),
|
||||||
})
|
})
|
||||||
.optional(),
|
.optional(),
|
||||||
usedStarterPacks: z.array(z.string()).optional(),
|
hasCheckedForStarterPack: z.boolean().optional(),
|
||||||
})
|
})
|
||||||
export type Schema = z.infer<typeof schema>
|
export type Schema = z.infer<typeof schema>
|
||||||
|
|
||||||
@@ -135,5 +135,5 @@ export const defaults: Schema = {
|
|||||||
disableAutoplay: prefersReducedMotion,
|
disableAutoplay: prefersReducedMotion,
|
||||||
kawaii: false,
|
kawaii: false,
|
||||||
currentStarterPack: undefined,
|
currentStarterPack: undefined,
|
||||||
usedStarterPacks: [],
|
hasCheckedForStarterPack: false,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,25 +2,25 @@ import React from 'react'
|
|||||||
|
|
||||||
import * as persisted from '#/state/persisted'
|
import * as persisted from '#/state/persisted'
|
||||||
|
|
||||||
type StateContext = string[] | undefined
|
type StateContext = boolean | undefined
|
||||||
type SetContext = (v: string) => void
|
type SetContext = (v: boolean) => void
|
||||||
|
|
||||||
const stateContext = React.createContext<StateContext>([])
|
const stateContext = React.createContext<StateContext>(false)
|
||||||
const setContext = React.createContext<SetContext>((_: string) => {})
|
const setContext = React.createContext<SetContext>((_: boolean) => {})
|
||||||
|
|
||||||
export function Provider({children}: {children: React.ReactNode}) {
|
export function Provider({children}: {children: React.ReactNode}) {
|
||||||
const [state, setState] = React.useState<StateContext>(() =>
|
const [state, setState] = React.useState<StateContext>(() =>
|
||||||
persisted.get('usedStarterPacks'),
|
persisted.get('hasCheckedForStarterPack'),
|
||||||
)
|
)
|
||||||
|
|
||||||
const setStateWrapped = (v: string) => {
|
const setStateWrapped = (v: boolean) => {
|
||||||
persisted.write('usedStarterPacks', [...(state ? state : []), v])
|
setState(v)
|
||||||
setState(prev => [...(prev ? prev : []), v])
|
persisted.write('hasCheckedForStarterPack', v)
|
||||||
}
|
}
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
return persisted.onUpdate(() => {
|
return persisted.onUpdate(() => {
|
||||||
setState(persisted.get('usedStarterPacks'))
|
setState(persisted.get('hasCheckedForStarterPack'))
|
||||||
})
|
})
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
@@ -33,5 +33,5 @@ export function Provider({children}: {children: React.ReactNode}) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useUsedStarterPacks = () => React.useContext(stateContext)
|
export const useHasCheckedForStarterPack = () => React.useContext(stateContext)
|
||||||
export const useAddUsedStarterPack = () => React.useContext(setContext)
|
export const useSetHasCheckedForStarterPack = () => React.useContext(setContext)
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import {
|
|||||||
useCurrentStarterPack,
|
useCurrentStarterPack,
|
||||||
useSetCurrentStarterPack,
|
useSetCurrentStarterPack,
|
||||||
} from 'state/preferences/starter-pack'
|
} from 'state/preferences/starter-pack'
|
||||||
import {useUsedStarterPacks} from 'state/preferences/used-starter-packs'
|
|
||||||
import {useLoggedOutViewControls} from 'state/shell/logged-out'
|
import {useLoggedOutViewControls} from 'state/shell/logged-out'
|
||||||
import {FeedPage} from 'view/com/feeds/FeedPage'
|
import {FeedPage} from 'view/com/feeds/FeedPage'
|
||||||
import {Pager, PagerRef, RenderTabBarFnProps} from 'view/com/pager/Pager'
|
import {Pager, PagerRef, RenderTabBarFnProps} from 'view/com/pager/Pager'
|
||||||
@@ -42,30 +41,14 @@ export function HomeScreen(props: Props) {
|
|||||||
const {data: pinnedFeedInfos, isLoading: isPinnedFeedsLoading} =
|
const {data: pinnedFeedInfos, isLoading: isPinnedFeedsLoading} =
|
||||||
usePinnedFeedsInfos()
|
usePinnedFeedsInfos()
|
||||||
const currentStarterPack = useCurrentStarterPack()
|
const currentStarterPack = useCurrentStarterPack()
|
||||||
const usedStarterPacks = useUsedStarterPacks()
|
|
||||||
const {setShowLoggedOut, requestSwitchToAccount} = useLoggedOutViewControls()
|
const {setShowLoggedOut, requestSwitchToAccount} = useLoggedOutViewControls()
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (currentStarterPack && !currentStarterPack?.initialFeed) {
|
if (currentStarterPack?.uri && !currentStarterPack?.initialFeed) {
|
||||||
// In test environments, the URL won't start with `https://bsky.app`, so we want to find it by the route
|
setShowLoggedOut(true)
|
||||||
try {
|
requestSwitchToAccount({requestedAccount: 'starterpack'})
|
||||||
const route = new URL(currentStarterPack.uri).pathname
|
|
||||||
const foundIndex = usedStarterPacks?.findIndex(p => p.includes(route))
|
|
||||||
if (foundIndex === -1) {
|
|
||||||
setShowLoggedOut(true)
|
|
||||||
requestSwitchToAccount({requestedAccount: 'starterpack'})
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// Don't need to handle anything here, just put the user on the home screen
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, [
|
}, [setShowLoggedOut, requestSwitchToAccount, currentStarterPack])
|
||||||
setShowLoggedOut,
|
|
||||||
requestSwitchToAccount,
|
|
||||||
currentStarterPack?.initialFeed,
|
|
||||||
currentStarterPack,
|
|
||||||
usedStarterPacks,
|
|
||||||
])
|
|
||||||
|
|
||||||
if (preferences && pinnedFeedInfos && !isPinnedFeedsLoading) {
|
if (preferences && pinnedFeedInfos && !isPinnedFeedsLoading) {
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user