From ffdc3dca696e59f7e0ae98c545f97fbe8f257884 Mon Sep 17 00:00:00 2001 From: Hailey Date: Mon, 17 Jun 2024 20:57:50 -0700 Subject: [PATCH 1/4] change to bool --- src/state/persisted/schema.ts | 4 ++-- src/state/preferences/used-starter-packs.tsx | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/state/persisted/schema.ts b/src/state/persisted/schema.ts index c9eb4909e6..71a498538b 100644 --- a/src/state/persisted/schema.ts +++ b/src/state/persisted/schema.ts @@ -95,7 +95,7 @@ export const schema = z.object({ isClip: z.boolean().optional(), }) .optional(), - usedStarterPacks: z.array(z.string()).optional(), + hasCheckedForStarterPack: z.boolean().optional(), }) export type Schema = z.infer @@ -135,5 +135,5 @@ export const defaults: Schema = { disableAutoplay: prefersReducedMotion, kawaii: false, currentStarterPack: undefined, - usedStarterPacks: [], + hasCheckedForStarterPack: false, } diff --git a/src/state/preferences/used-starter-packs.tsx b/src/state/preferences/used-starter-packs.tsx index b04698caca..51f180b322 100644 --- a/src/state/preferences/used-starter-packs.tsx +++ b/src/state/preferences/used-starter-packs.tsx @@ -2,25 +2,25 @@ import React from 'react' import * as persisted from '#/state/persisted' -type StateContext = string[] | undefined -type SetContext = (v: string) => void +type StateContext = boolean | undefined +type SetContext = (v: boolean) => void -const stateContext = React.createContext([]) -const setContext = React.createContext((_: string) => {}) +const stateContext = React.createContext(false) +const setContext = React.createContext((_: boolean) => {}) export function Provider({children}: {children: React.ReactNode}) { const [state, setState] = React.useState(() => - persisted.get('usedStarterPacks'), + persisted.get('hasCheckedForStarterPack'), ) - const setStateWrapped = (v: string) => { - persisted.write('usedStarterPacks', [...(state ? state : []), v]) - setState(prev => [...(prev ? prev : []), v]) + const setStateWrapped = (v: boolean) => { + setState(v) + persisted.write('hasCheckedForStarterPack', v) } React.useEffect(() => { return persisted.onUpdate(() => { - setState(persisted.get('usedStarterPacks')) + setState(persisted.get('hasCheckedForStarterPack')) }) }, []) From f6a77cb56198dfdaa0869cbd77214c1509193227 Mon Sep 17 00:00:00 2001 From: Hailey Date: Mon, 17 Jun 2024 21:04:28 -0700 Subject: [PATCH 2/4] simplify logic to avoid reusing starter pack flowo n native --- .../hooks/useStarterPackEntry.native.ts | 17 ++++++++----- src/screens/Onboarding/StepFinished.tsx | 5 ---- src/state/preferences/used-starter-packs.tsx | 4 +-- src/view/screens/Home.tsx | 25 +++---------------- 4 files changed, 17 insertions(+), 34 deletions(-) diff --git a/src/components/hooks/useStarterPackEntry.native.ts b/src/components/hooks/useStarterPackEntry.native.ts index 44299dafd2..2cbb5caf68 100644 --- a/src/components/hooks/useStarterPackEntry.native.ts +++ b/src/components/hooks/useStarterPackEntry.native.ts @@ -3,20 +3,20 @@ import React from 'react' import {createStarterPackLinkFromAndroidReferrer} from 'lib/strings/starter-pack' import {isAndroid} from 'platform/detection' import {useSetCurrentStarterPack} from 'state/preferences/starter-pack' -import {useUsedStarterPacks} from 'state/preferences/used-starter-packs' +import {useHasCheckedForStarterPack} from 'state/preferences/used-starter-packs' import SwissArmyKnife from '../../../modules/expo-bluesky-swiss-army' import GooglePlayReferrer from '../../../modules/expo-google-play-referrer' export function useStarterPackEntry() { const [ready, setReady] = React.useState(false) const setCurrentStarterPack = useSetCurrentStarterPack() - const usedStarterPacks = useUsedStarterPacks() - const hasRan = React.useRef(false) + const hasCheckedForStarterPack = useHasCheckedForStarterPack() + const setHasCheckedForStarterPack = useHasCheckedForStarterPack() React.useEffect(() => { - if (ready || hasRan.current) return + if (ready || hasCheckedForStarterPack) return - hasRan.current = true + setHasCheckedForStarterPack(true) ;(async () => { let uri: string | null | undefined @@ -38,7 +38,12 @@ export function useStarterPackEntry() { setReady(true) })() - }, [ready, setCurrentStarterPack, usedStarterPacks]) + }, [ + ready, + setCurrentStarterPack, + setHasCheckedForStarterPack, + hasCheckedForStarterPack, + ]) return ready } diff --git a/src/screens/Onboarding/StepFinished.tsx b/src/screens/Onboarding/StepFinished.tsx index 8df50d6ba9..6e4177d213 100644 --- a/src/screens/Onboarding/StepFinished.tsx +++ b/src/screens/Onboarding/StepFinished.tsx @@ -15,12 +15,10 @@ import {useAgent} from '#/state/session' import {useOnboardingDispatch} from '#/state/shell' import {uploadBlob} from 'lib/api' import {useRequestNotificationsPermission} from 'lib/notifications/notifications' -import {makeStarterPackLink} from 'lib/routes/links' import { useCurrentStarterPack, useSetCurrentStarterPack, } from 'state/preferences/starter-pack' -import {useAddUsedStarterPack} from 'state/preferences/used-starter-packs' import { DescriptionText, OnboardingControls, @@ -50,7 +48,6 @@ export function StepFinished() { const requestNotificationsPermission = useRequestNotificationsPermission() const currentStarterPack = useCurrentStarterPack() const setCurrentStarterPack = useSetCurrentStarterPack() - const addUsedStarterPack = useAddUsedStarterPack() const finishOnboarding = React.useCallback(async () => { setSaving(true) @@ -102,7 +99,6 @@ export function StepFinished() { initialFeed: 'following', }) } - addUsedStarterPack(makeStarterPackLink(starterPack)) } })(), (async () => { @@ -182,7 +178,6 @@ export function StepFinished() { currentStarterPack, state, requestNotificationsPermission, - addUsedStarterPack, setCurrentStarterPack, ]) diff --git a/src/state/preferences/used-starter-packs.tsx b/src/state/preferences/used-starter-packs.tsx index 51f180b322..8d5d9e8283 100644 --- a/src/state/preferences/used-starter-packs.tsx +++ b/src/state/preferences/used-starter-packs.tsx @@ -33,5 +33,5 @@ export function Provider({children}: {children: React.ReactNode}) { ) } -export const useUsedStarterPacks = () => React.useContext(stateContext) -export const useAddUsedStarterPack = () => React.useContext(setContext) +export const useHasCheckedForStarterPack = () => React.useContext(stateContext) +export const useSetHasCheckedForStarterPack = () => React.useContext(setContext) diff --git a/src/view/screens/Home.tsx b/src/view/screens/Home.tsx index 48a33a092c..fde9354046 100644 --- a/src/view/screens/Home.tsx +++ b/src/view/screens/Home.tsx @@ -26,7 +26,6 @@ import { useCurrentStarterPack, useSetCurrentStarterPack, } from 'state/preferences/starter-pack' -import {useUsedStarterPacks} from 'state/preferences/used-starter-packs' import {useLoggedOutViewControls} from 'state/shell/logged-out' import {FeedPage} from 'view/com/feeds/FeedPage' import {Pager, PagerRef, RenderTabBarFnProps} from 'view/com/pager/Pager' @@ -42,30 +41,14 @@ export function HomeScreen(props: Props) { const {data: pinnedFeedInfos, isLoading: isPinnedFeedsLoading} = usePinnedFeedsInfos() const currentStarterPack = useCurrentStarterPack() - const usedStarterPacks = useUsedStarterPacks() const {setShowLoggedOut, requestSwitchToAccount} = useLoggedOutViewControls() React.useEffect(() => { - if (currentStarterPack && !currentStarterPack?.initialFeed) { - // In test environments, the URL won't start with `https://bsky.app`, so we want to find it by the route - try { - 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 - } + if (currentStarterPack?.uri && !currentStarterPack?.initialFeed) { + setShowLoggedOut(true) + requestSwitchToAccount({requestedAccount: 'starterpack'}) } - }, [ - setShowLoggedOut, - requestSwitchToAccount, - currentStarterPack?.initialFeed, - currentStarterPack, - usedStarterPacks, - ]) + }, [setShowLoggedOut, requestSwitchToAccount, currentStarterPack]) if (preferences && pinnedFeedInfos && !isPinnedFeedsLoading) { return ( From 86dd49c4c1bb7ca80df313d64194046a8e0b91cd Mon Sep 17 00:00:00 2001 From: Hailey Date: Mon, 17 Jun 2024 21:11:19 -0700 Subject: [PATCH 3/4] lint --- src/components/hooks/useStarterPackEntry.native.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/components/hooks/useStarterPackEntry.native.ts b/src/components/hooks/useStarterPackEntry.native.ts index 2cbb5caf68..94180a68e1 100644 --- a/src/components/hooks/useStarterPackEntry.native.ts +++ b/src/components/hooks/useStarterPackEntry.native.ts @@ -3,7 +3,10 @@ import React from 'react' import {createStarterPackLinkFromAndroidReferrer} from 'lib/strings/starter-pack' import {isAndroid} from 'platform/detection' import {useSetCurrentStarterPack} from 'state/preferences/starter-pack' -import {useHasCheckedForStarterPack} from 'state/preferences/used-starter-packs' +import { + useHasCheckedForStarterPack, + useSetHasCheckedForStarterPack, +} from 'state/preferences/used-starter-packs' import SwissArmyKnife from '../../../modules/expo-bluesky-swiss-army' import GooglePlayReferrer from '../../../modules/expo-google-play-referrer' @@ -11,11 +14,10 @@ export function useStarterPackEntry() { const [ready, setReady] = React.useState(false) const setCurrentStarterPack = useSetCurrentStarterPack() const hasCheckedForStarterPack = useHasCheckedForStarterPack() - const setHasCheckedForStarterPack = useHasCheckedForStarterPack() + const setHasCheckedForStarterPack = useSetHasCheckedForStarterPack() React.useEffect(() => { if (ready || hasCheckedForStarterPack) return - setHasCheckedForStarterPack(true) ;(async () => { let uri: string | null | undefined @@ -30,7 +32,7 @@ export function useStarterPackEntry() { uri = await SwissArmyKnife.getStringValueAsync('starterPackUri', true) } - if (uri && !usedStarterPacks?.includes(uri)) { + if (uri) { setCurrentStarterPack({ uri, }) From a539f9068358a593c9a29c022911b52aa968052d Mon Sep 17 00:00:00 2001 From: Hailey Date: Tue, 18 Jun 2024 08:57:53 -0700 Subject: [PATCH 4/4] oops --- src/components/hooks/useStarterPackEntry.native.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/hooks/useStarterPackEntry.native.ts b/src/components/hooks/useStarterPackEntry.native.ts index 94180a68e1..575d00a6a8 100644 --- a/src/components/hooks/useStarterPackEntry.native.ts +++ b/src/components/hooks/useStarterPackEntry.native.ts @@ -17,7 +17,12 @@ export function useStarterPackEntry() { const setHasCheckedForStarterPack = useSetHasCheckedForStarterPack() React.useEffect(() => { - if (ready || hasCheckedForStarterPack) return + if (ready) return + if (hasCheckedForStarterPack) { + setReady(true) + return + } + setHasCheckedForStarterPack(true) ;(async () => { let uri: string | null | undefined