rework state
This commit is contained in:
@@ -1,16 +1,14 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
import {makeStarterPackLink} from 'lib/routes/links'
|
import {makeStarterPackLink} from 'lib/routes/links'
|
||||||
import {
|
import {useSetCurrentStarterPack} from 'state/preferences/starter-pack'
|
||||||
useSetUsedStarterPack,
|
import {useUsedStarterPacks} from 'state/preferences/used-starter-packs'
|
||||||
useUsedStarterPack,
|
|
||||||
} from 'state/preferences/starter-pack'
|
|
||||||
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 usedStarterPack = useUsedStarterPack()
|
const setCurrentStarterPack = useSetCurrentStarterPack()
|
||||||
const setUsedStarterPack = useSetUsedStarterPack()
|
const usedStarterPacks = useUsedStarterPacks()
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (ready) return
|
if (ready) return
|
||||||
@@ -32,8 +30,8 @@ export function useStarterPackEntry() {
|
|||||||
// We won't actually set `lastUsedUri` until a _successful_ use of the starter pack, meaning a new account
|
// We won't actually set `lastUsedUri` until a _successful_ use of the starter pack, meaning a new account
|
||||||
// has actually completed onboarding with the given starter pack.
|
// has actually completed onboarding with the given starter pack.
|
||||||
const uri = makeStarterPackLink(sourceParts[1], sourceParts[2])
|
const uri = makeStarterPackLink(sourceParts[1], sourceParts[2])
|
||||||
if (uri !== usedStarterPack?.lastUsedUri) {
|
if (!usedStarterPacks?.includes(uri)) {
|
||||||
setUsedStarterPack({
|
setCurrentStarterPack({
|
||||||
uri: makeStarterPackLink(sourceParts[1], sourceParts[2]),
|
uri: makeStarterPackLink(sourceParts[1], sourceParts[2]),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -41,7 +39,7 @@ export function useStarterPackEntry() {
|
|||||||
}
|
}
|
||||||
setReady(true)
|
setReady(true)
|
||||||
})()
|
})()
|
||||||
}, [ready, setUsedStarterPack, usedStarterPack?.lastUsedUri])
|
}, [ready, setCurrentStarterPack, usedStarterPacks])
|
||||||
|
|
||||||
return ready
|
return ready
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
import {useSetUsedStarterPack} from 'state/preferences/starter-pack'
|
import {useSetCurrentStarterPack} from 'state/preferences/starter-pack'
|
||||||
|
|
||||||
export function useStarterPackEntry() {
|
export function useStarterPackEntry() {
|
||||||
const setUsedStarterPack = useSetUsedStarterPack()
|
const setCurrentStarterPack = useSetCurrentStarterPack()
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
const url = new URL(window.location.href)
|
const url = new URL(window.location.href)
|
||||||
@@ -12,13 +12,13 @@ export function useStarterPackEntry() {
|
|||||||
const isClip = url.searchParams.get('clip') === 'true'
|
const isClip = url.searchParams.get('clip') === 'true'
|
||||||
|
|
||||||
if (name && rkey) {
|
if (name && rkey) {
|
||||||
setUsedStarterPack({
|
setCurrentStarterPack({
|
||||||
uri: window.location.href,
|
uri: window.location.href,
|
||||||
isClip,
|
isClip,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [setUsedStarterPack])
|
}, [setCurrentStarterPack])
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,10 +15,12 @@ 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 {
|
||||||
useSetUsedStarterPack,
|
useCurrentStarterPack,
|
||||||
useUsedStarterPack,
|
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,
|
||||||
@@ -46,17 +48,18 @@ export function StepFinished() {
|
|||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const agent = useAgent()
|
const agent = useAgent()
|
||||||
const requestNotificationsPermission = useRequestNotificationsPermission()
|
const requestNotificationsPermission = useRequestNotificationsPermission()
|
||||||
const usedStarterPack = useUsedStarterPack()
|
const currentStarterPack = useCurrentStarterPack()
|
||||||
const setUsedStarterPack = useSetUsedStarterPack()
|
const setCurrentStarterPack = useSetCurrentStarterPack()
|
||||||
|
const addUsedStarterPack = useAddUsedStarterPack()
|
||||||
|
|
||||||
const finishOnboarding = React.useCallback(async () => {
|
const finishOnboarding = React.useCallback(async () => {
|
||||||
setSaving(true)
|
setSaving(true)
|
||||||
try {
|
try {
|
||||||
let starterPack: AppBskyGraphDefs.StarterPackView | undefined
|
let starterPack: AppBskyGraphDefs.StarterPackView | undefined
|
||||||
let listItems: AppBskyGraphDefs.ListItemView[] | undefined
|
let listItems: AppBskyGraphDefs.ListItemView[] | undefined
|
||||||
if (usedStarterPack) {
|
if (currentStarterPack) {
|
||||||
const spRes = await agent.app.bsky.graph.getStarterPack({
|
const spRes = await agent.app.bsky.graph.getStarterPack({
|
||||||
starterPack: usedStarterPack.uri,
|
starterPack: currentStarterPack.uri,
|
||||||
})
|
})
|
||||||
starterPack = spRes.data.starterPack
|
starterPack = spRes.data.starterPack
|
||||||
|
|
||||||
@@ -133,12 +136,12 @@ export function StepFinished() {
|
|||||||
requestNotificationsPermission('AfterOnboarding'),
|
requestNotificationsPermission('AfterOnboarding'),
|
||||||
])
|
])
|
||||||
|
|
||||||
if (usedStarterPack) {
|
if (currentStarterPack && starterPack) {
|
||||||
setUsedStarterPack({
|
setCurrentStarterPack({
|
||||||
...usedStarterPack,
|
...currentStarterPack,
|
||||||
initialFeed: starterPack?.feeds?.[0].uri ?? 'following',
|
initialFeed: starterPack?.feeds?.[0].uri ?? 'following',
|
||||||
lastUsedUri: usedStarterPack.uri,
|
|
||||||
})
|
})
|
||||||
|
addUsedStarterPack(makeStarterPackLink(starterPack))
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
logger.info(`onboarding: bulk save failed`)
|
logger.info(`onboarding: bulk save failed`)
|
||||||
@@ -171,10 +174,11 @@ export function StepFinished() {
|
|||||||
dispatch,
|
dispatch,
|
||||||
onboardDispatch,
|
onboardDispatch,
|
||||||
track,
|
track,
|
||||||
usedStarterPack,
|
currentStarterPack,
|
||||||
state,
|
state,
|
||||||
requestNotificationsPermission,
|
requestNotificationsPermission,
|
||||||
setUsedStarterPack,
|
setCurrentStarterPack,
|
||||||
|
addUsedStarterPack,
|
||||||
])
|
])
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {Pressable, ScrollView, View} from 'react-native'
|
import {Pressable, ScrollView, View} from 'react-native'
|
||||||
import Animated, {FadeIn, FadeOut} from 'react-native-reanimated'
|
import Animated, {FadeIn, FadeOut} from 'react-native-reanimated'
|
||||||
import {AppBskyGraphDefs, AppBskyGraphStarterpack} from '@atproto/api'
|
import {AppBskyGraphDefs, AppBskyGraphStarterpack, AtUri} from '@atproto/api'
|
||||||
import {msg, Trans} from '@lingui/macro'
|
import {msg, Trans} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
|
|
||||||
import {isAndroidWeb} from 'lib/browser'
|
import {isAndroidWeb} from 'lib/browser'
|
||||||
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
||||||
import {
|
import {
|
||||||
useSetUsedStarterPack,
|
useCurrentStarterPack,
|
||||||
useUsedStarterPack,
|
useSetCurrentStarterPack,
|
||||||
} from 'state/preferences/starter-pack'
|
} from 'state/preferences/starter-pack'
|
||||||
import {useResolveDidQuery} from 'state/queries/resolve-uri'
|
import {useResolveDidQuery} from 'state/queries/resolve-uri'
|
||||||
import {useStarterPackQuery} from 'state/queries/useStarterPackQuery'
|
import {useStarterPackQuery} from 'state/queries/useStarterPackQuery'
|
||||||
@@ -40,11 +40,15 @@ function postAppClipMessage(message: AppClipMessage) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function parseStarterPackHttpUri(uri: string): {name?: string; rkey?: string} {
|
function parseStarterPackHttpUri(uri: string): {name?: string; rkey?: string} {
|
||||||
const parsed = new URL(uri)
|
try {
|
||||||
const [_, _path, name, rkey] = parsed.pathname.split('/')
|
const parsed = new URL(uri)
|
||||||
return {
|
const [_, _path, name, rkey] = parsed.pathname.split('/')
|
||||||
name,
|
return {
|
||||||
rkey,
|
name,
|
||||||
|
rkey,
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,8 +61,9 @@ export function LandingScreen({
|
|||||||
}: {
|
}: {
|
||||||
setScreenState: (state: LoggedOutScreenState) => void
|
setScreenState: (state: LoggedOutScreenState) => void
|
||||||
}) {
|
}) {
|
||||||
const usedStarterPack = useUsedStarterPack()
|
const currentStarterPack = useCurrentStarterPack()
|
||||||
const {name, rkey} = parseStarterPackHttpUri(usedStarterPack?.uri || '')
|
const {name, rkey} =
|
||||||
|
parseStarterPackHttpUri(currentStarterPack?.uri || '') ?? {}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: did,
|
data: did,
|
||||||
@@ -108,8 +113,8 @@ function LandingScreenInner({
|
|||||||
const {record, creator, listItemsSample, feeds, joinedWeekCount} = starterPack
|
const {record, creator, listItemsSample, feeds, joinedWeekCount} = starterPack
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const setUsedStarterPack = useSetUsedStarterPack()
|
const currentStarterPack = useCurrentStarterPack()
|
||||||
const usedStarterPack = useUsedStarterPack()
|
const setCurrentStarterPack = useSetCurrentStarterPack()
|
||||||
const {isTabletOrDesktop} = useWebMediaQueries()
|
const {isTabletOrDesktop} = useWebMediaQueries()
|
||||||
const androidDialogControl = useDialogControl()
|
const androidDialogControl = useDialogControl()
|
||||||
|
|
||||||
@@ -119,14 +124,14 @@ function LandingScreenInner({
|
|||||||
const listItemsCount = starterPack.list?.listItemCount ?? 0
|
const listItemsCount = starterPack.list?.listItemCount ?? 0
|
||||||
|
|
||||||
const onContinue = () => {
|
const onContinue = () => {
|
||||||
setUsedStarterPack({
|
setCurrentStarterPack({
|
||||||
uri: starterPack.uri,
|
uri: starterPack.uri,
|
||||||
})
|
})
|
||||||
setScreenState(LoggedOutScreenState.S_CreateAccount)
|
setScreenState(LoggedOutScreenState.S_CreateAccount)
|
||||||
}
|
}
|
||||||
|
|
||||||
const onJoinPress = () => {
|
const onJoinPress = () => {
|
||||||
if (usedStarterPack?.isClip) {
|
if (currentStarterPack?.isClip) {
|
||||||
setAppClipOverlayVisible(true)
|
setAppClipOverlayVisible(true)
|
||||||
postAppClipMessage({
|
postAppClipMessage({
|
||||||
action: 'present',
|
action: 'present',
|
||||||
@@ -156,7 +161,7 @@ function LandingScreenInner({
|
|||||||
borderBottomLeftRadius: 10,
|
borderBottomLeftRadius: 10,
|
||||||
borderBottomRightRadius: 10,
|
borderBottomRightRadius: 10,
|
||||||
},
|
},
|
||||||
usedStarterPack?.isClip && {
|
currentStarterPack?.isClip && {
|
||||||
paddingTop: 100,
|
paddingTop: 100,
|
||||||
},
|
},
|
||||||
]}>
|
]}>
|
||||||
@@ -210,7 +215,7 @@ function LandingScreenInner({
|
|||||||
{starterPack.feeds?.length ? (
|
{starterPack.feeds?.length ? (
|
||||||
<View style={[a.gap_md]}>
|
<View style={[a.gap_md]}>
|
||||||
<Text style={[a.font_bold, a.text_lg]}>
|
<Text style={[a.font_bold, a.text_lg]}>
|
||||||
Join Bluesky and subscribe to these feeds
|
These great feeds will be available after signing up!
|
||||||
</Text>
|
</Text>
|
||||||
|
|
||||||
<View
|
<View
|
||||||
@@ -240,24 +245,23 @@ function LandingScreenInner({
|
|||||||
{feeds?.length ? (
|
{feeds?.length ? (
|
||||||
<>
|
<>
|
||||||
{listItemsCount <= 8 ? (
|
{listItemsCount <= 8 ? (
|
||||||
<Trans>Also follow these people right away!</Trans>
|
<Trans>
|
||||||
|
You'll also follow these people right away!
|
||||||
|
</Trans>
|
||||||
) : (
|
) : (
|
||||||
<Trans>
|
<Trans>
|
||||||
Also follow these people and {listItemsCount - 8}{' '}
|
You'll also follow these people and{' '}
|
||||||
others!
|
{listItemsCount - 8} others!
|
||||||
</Trans>
|
</Trans>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
{listItemsCount <= 8 ? (
|
{listItemsCount <= 8 ? (
|
||||||
<Trans>
|
<Trans>You'll follow these people right away!</Trans>
|
||||||
Get started by following these people right away!
|
|
||||||
</Trans>
|
|
||||||
) : (
|
) : (
|
||||||
<Trans>
|
<Trans>
|
||||||
Get started by following these people and{' '}
|
You'll follow these people and {listItemsCount - 8}
|
||||||
{listItemsCount - 8}
|
|
||||||
others!
|
others!
|
||||||
</Trans>
|
</Trans>
|
||||||
)}
|
)}
|
||||||
@@ -289,24 +293,31 @@ function LandingScreenInner({
|
|||||||
setIsVisible={setAppClipOverlayVisible}
|
setIsVisible={setAppClipOverlayVisible}
|
||||||
/>
|
/>
|
||||||
<Prompt.Outer control={androidDialogControl}>
|
<Prompt.Outer control={androidDialogControl}>
|
||||||
<Prompt.TitleText />
|
<Prompt.TitleText>
|
||||||
<Prompt.DescriptionText />
|
<Trans>Download Bluesky</Trans>
|
||||||
|
</Prompt.TitleText>
|
||||||
|
<Prompt.DescriptionText>
|
||||||
|
<Trans>
|
||||||
|
The experience is better in the app. Download Bluesky now and we'll
|
||||||
|
pick back up where you left off.
|
||||||
|
</Trans>
|
||||||
|
</Prompt.DescriptionText>
|
||||||
<Prompt.Actions>
|
<Prompt.Actions>
|
||||||
<Prompt.Action
|
|
||||||
cta="Continue on web"
|
|
||||||
color="secondary"
|
|
||||||
onPress={onContinue}
|
|
||||||
/>
|
|
||||||
<Prompt.Action
|
<Prompt.Action
|
||||||
cta="Download on Google Play"
|
cta="Download on Google Play"
|
||||||
color="primary"
|
color="primary"
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
const rkey = parseStarterPackHttpUri(starterPack.uri).rkey
|
const rkey = new AtUri(starterPack.uri).rkey
|
||||||
if (!rkey) return
|
if (!rkey) return
|
||||||
|
|
||||||
window.location.href = createGooglePlayLink(creator.handle, rkey)
|
window.location.href = createGooglePlayLink(creator.handle, rkey)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
<Prompt.Action
|
||||||
|
cta="Continue on web"
|
||||||
|
color="secondary"
|
||||||
|
onPress={onContinue}
|
||||||
|
/>
|
||||||
</Prompt.Actions>
|
</Prompt.Actions>
|
||||||
</Prompt.Outer>
|
</Prompt.Outer>
|
||||||
</CenteredView>
|
</CenteredView>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {CommonNavigatorParams, NavigationProp} from 'lib/routes/types'
|
|||||||
import {shareUrl} from 'lib/sharing'
|
import {shareUrl} from 'lib/sharing'
|
||||||
import {logEvent} from 'lib/statsig/statsig'
|
import {logEvent} from 'lib/statsig/statsig'
|
||||||
import {isWeb} from 'platform/detection'
|
import {isWeb} from 'platform/detection'
|
||||||
import {useSetUsedStarterPack} from 'state/preferences/starter-pack'
|
import {useSetCurrentStarterPack} from 'state/preferences/starter-pack'
|
||||||
import {RQKEY} from 'state/queries/list-members'
|
import {RQKEY} from 'state/queries/list-members'
|
||||||
import {useResolveDidQuery} from 'state/queries/resolve-uri'
|
import {useResolveDidQuery} from 'state/queries/resolve-uri'
|
||||||
import {useStarterPackQuery} from 'state/queries/useStarterPackQuery'
|
import {useStarterPackQuery} from 'state/queries/useStarterPackQuery'
|
||||||
@@ -128,7 +128,7 @@ function Header({
|
|||||||
const agent = useAgent()
|
const agent = useAgent()
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const qrCodeDialogControl = useDialogControl()
|
const qrCodeDialogControl = useDialogControl()
|
||||||
const setUsedStarterPack = useSetUsedStarterPack()
|
const setCurrentStarterPack = useSetCurrentStarterPack()
|
||||||
const {setShowLoggedOut} = useLoggedOutViewControls()
|
const {setShowLoggedOut} = useLoggedOutViewControls()
|
||||||
|
|
||||||
const [isProcessing, setIsProcessing] = React.useState(false)
|
const [isProcessing, setIsProcessing] = React.useState(false)
|
||||||
@@ -190,7 +190,7 @@ function Header({
|
|||||||
color="secondary"
|
color="secondary"
|
||||||
size="small"
|
size="small"
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
setUsedStarterPack({uri: starterPack.uri})
|
setCurrentStarterPack({uri: starterPack.uri})
|
||||||
setShowLoggedOut(true)
|
setShowLoggedOut(true)
|
||||||
}}>
|
}}>
|
||||||
<ButtonText>
|
<ButtonText>
|
||||||
|
|||||||
@@ -88,14 +88,14 @@ export const schema = z.object({
|
|||||||
disableHaptics: z.boolean().optional(),
|
disableHaptics: z.boolean().optional(),
|
||||||
disableAutoplay: z.boolean().optional(),
|
disableAutoplay: z.boolean().optional(),
|
||||||
kawaii: z.boolean().optional(),
|
kawaii: z.boolean().optional(),
|
||||||
usedStarterPack: z
|
currentStarterPack: z
|
||||||
.object({
|
.object({
|
||||||
uri: z.string(),
|
uri: z.string(),
|
||||||
initialFeed: z.string().optional(),
|
initialFeed: z.string().optional(),
|
||||||
isClip: z.boolean().optional(),
|
isClip: z.boolean().optional(),
|
||||||
lastUsedUri: z.string().optional(),
|
|
||||||
})
|
})
|
||||||
.optional(),
|
.optional(),
|
||||||
|
usedStarterPacks: z.array(z.string()).optional(),
|
||||||
})
|
})
|
||||||
export type Schema = z.infer<typeof schema>
|
export type Schema = z.infer<typeof schema>
|
||||||
|
|
||||||
@@ -134,5 +134,6 @@ export const defaults: Schema = {
|
|||||||
disableHaptics: false,
|
disableHaptics: false,
|
||||||
disableAutoplay: prefersReducedMotion,
|
disableAutoplay: prefersReducedMotion,
|
||||||
kawaii: false,
|
kawaii: false,
|
||||||
usedStarterPack: undefined,
|
currentStarterPack: undefined,
|
||||||
|
usedStarterPacks: [],
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import * as persisted from '#/state/persisted'
|
|||||||
type StateContext =
|
type StateContext =
|
||||||
| {
|
| {
|
||||||
uri: string
|
uri: string
|
||||||
|
cid?: string
|
||||||
initialFeed?: string
|
initialFeed?: string
|
||||||
isClip?: boolean
|
isClip?: boolean
|
||||||
lastUsedUri?: string
|
|
||||||
}
|
}
|
||||||
| undefined
|
| undefined
|
||||||
type SetContext = (v: StateContext) => void
|
type SetContext = (v: StateContext) => void
|
||||||
@@ -20,12 +20,12 @@ export function Provider({children}: {children: React.ReactNode}) {
|
|||||||
|
|
||||||
const setStateWrapped = (v: StateContext) => {
|
const setStateWrapped = (v: StateContext) => {
|
||||||
setState(v)
|
setState(v)
|
||||||
persisted.write('usedStarterPack', v)
|
persisted.write('currentStarterPack', v)
|
||||||
}
|
}
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
return persisted.onUpdate(() => {
|
return persisted.onUpdate(() => {
|
||||||
setState(persisted.get('usedStarterPack'))
|
setState(persisted.get('currentStarterPack'))
|
||||||
})
|
})
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
@@ -38,5 +38,5 @@ export function Provider({children}: {children: React.ReactNode}) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useUsedStarterPack = () => React.useContext(stateContext)
|
export const useCurrentStarterPack = () => React.useContext(stateContext)
|
||||||
export const useSetUsedStarterPack = () => React.useContext(setContext)
|
export const useSetCurrentStarterPack = () => React.useContext(setContext)
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
import * as persisted from '#/state/persisted'
|
||||||
|
|
||||||
|
type StateContext = string[] | undefined
|
||||||
|
type SetContext = (v: string) => void
|
||||||
|
|
||||||
|
const stateContext = React.createContext<StateContext>([])
|
||||||
|
const setContext = React.createContext<SetContext>((_: string) => {})
|
||||||
|
|
||||||
|
export function Provider({children}: {children: React.ReactNode}) {
|
||||||
|
const [state, setState] = React.useState<StateContext>()
|
||||||
|
|
||||||
|
const setStateWrapped = (v: StateContext) => {
|
||||||
|
persisted.write('usedStarterPacks', [...state, v])
|
||||||
|
setState(prev => [...prev, v])
|
||||||
|
}
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
return persisted.onUpdate(() => {
|
||||||
|
setState(persisted.get('usedStarterPack'))
|
||||||
|
})
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<stateContext.Provider value={state}>
|
||||||
|
<setContext.Provider value={setStateWrapped}>
|
||||||
|
{children}
|
||||||
|
</setContext.Provider>
|
||||||
|
</stateContext.Provider>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useUsedStarterPacks = () => React.useContext(stateContext)
|
||||||
|
export const useAddUsedStarterPack = () => React.useContext(setContext)
|
||||||
+21
-15
@@ -23,8 +23,8 @@ import {useOTAUpdates} from 'lib/hooks/useOTAUpdates'
|
|||||||
import {useRequestNotificationsPermission} from 'lib/notifications/notifications'
|
import {useRequestNotificationsPermission} from 'lib/notifications/notifications'
|
||||||
import {HomeTabNavigatorParams, NativeStackScreenProps} from 'lib/routes/types'
|
import {HomeTabNavigatorParams, NativeStackScreenProps} from 'lib/routes/types'
|
||||||
import {
|
import {
|
||||||
useSetUsedStarterPack,
|
useCurrentStarterPack,
|
||||||
useUsedStarterPack,
|
useSetCurrentStarterPack,
|
||||||
} from 'state/preferences/starter-pack'
|
} from 'state/preferences/starter-pack'
|
||||||
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'
|
||||||
@@ -40,15 +40,19 @@ export function HomeScreen(props: Props) {
|
|||||||
const {data: preferences} = usePreferencesQuery()
|
const {data: preferences} = usePreferencesQuery()
|
||||||
const {data: pinnedFeedInfos, isLoading: isPinnedFeedsLoading} =
|
const {data: pinnedFeedInfos, isLoading: isPinnedFeedsLoading} =
|
||||||
usePinnedFeedsInfos()
|
usePinnedFeedsInfos()
|
||||||
const usedStarterPack = useUsedStarterPack()
|
const currentStarterPack = useCurrentStarterPack()
|
||||||
const {setShowLoggedOut, requestSwitchToAccount} = useLoggedOutViewControls()
|
const {setShowLoggedOut, requestSwitchToAccount} = useLoggedOutViewControls()
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (usedStarterPack && !usedStarterPack.initialFeed) {
|
if (!currentStarterPack?.initialFeed) {
|
||||||
setShowLoggedOut(true)
|
setShowLoggedOut(true)
|
||||||
requestSwitchToAccount({requestedAccount: 'starterpack'})
|
requestSwitchToAccount({requestedAccount: 'starterpack'})
|
||||||
}
|
}
|
||||||
}, [usedStarterPack, setShowLoggedOut, requestSwitchToAccount])
|
}, [
|
||||||
|
setShowLoggedOut,
|
||||||
|
requestSwitchToAccount,
|
||||||
|
currentStarterPack?.initialFeed,
|
||||||
|
])
|
||||||
|
|
||||||
if (preferences && pinnedFeedInfos && !isPinnedFeedsLoading) {
|
if (preferences && pinnedFeedInfos && !isPinnedFeedsLoading) {
|
||||||
return (
|
return (
|
||||||
@@ -84,8 +88,8 @@ function HomeScreenReady({
|
|||||||
const selectedIndex = Math.max(0, maybeFoundIndex)
|
const selectedIndex = Math.max(0, maybeFoundIndex)
|
||||||
const selectedFeed = allFeeds[selectedIndex]
|
const selectedFeed = allFeeds[selectedIndex]
|
||||||
const requestNotificationsPermission = useRequestNotificationsPermission()
|
const requestNotificationsPermission = useRequestNotificationsPermission()
|
||||||
const usedStarterPack = useUsedStarterPack()
|
const currentStarterPack = useCurrentStarterPack()
|
||||||
const setUsedStarterPack = useSetUsedStarterPack()
|
const setCurrentStarterPack = useSetCurrentStarterPack()
|
||||||
|
|
||||||
useSetTitle(pinnedFeedInfos[selectedIndex]?.displayName)
|
useSetTitle(pinnedFeedInfos[selectedIndex]?.displayName)
|
||||||
useOTAUpdates()
|
useOTAUpdates()
|
||||||
@@ -98,21 +102,18 @@ function HomeScreenReady({
|
|||||||
const lastPagerReportedIndexRef = React.useRef(selectedIndex)
|
const lastPagerReportedIndexRef = React.useRef(selectedIndex)
|
||||||
React.useLayoutEffect(() => {
|
React.useLayoutEffect(() => {
|
||||||
let initialIndex = selectedIndex
|
let initialIndex = selectedIndex
|
||||||
if (usedStarterPack?.initialFeed) {
|
if (currentStarterPack?.initialFeed) {
|
||||||
if (usedStarterPack.initialFeed === 'following') {
|
if (currentStarterPack.initialFeed === 'following') {
|
||||||
initialIndex = allFeeds.findIndex(f => f === 'following')
|
initialIndex = allFeeds.findIndex(f => f === 'following')
|
||||||
} else {
|
} else {
|
||||||
initialIndex = allFeeds.findIndex(
|
initialIndex = allFeeds.findIndex(
|
||||||
f => f === `feedgen|${usedStarterPack.initialFeed}`,
|
f => f === `feedgen|${currentStarterPack.initialFeed}`,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (initialIndex === -1) {
|
if (initialIndex === -1) {
|
||||||
initialIndex = 0
|
initialIndex = 0
|
||||||
}
|
}
|
||||||
setUsedStarterPack({
|
setCurrentStarterPack(undefined)
|
||||||
...usedStarterPack,
|
|
||||||
initialFeed: undefined,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since the pager is not a controlled component, adjust it imperatively
|
// Since the pager is not a controlled component, adjust it imperatively
|
||||||
@@ -125,7 +126,12 @@ function HomeScreenReady({
|
|||||||
lastPagerReportedIndexRef.current = selectedIndex
|
lastPagerReportedIndexRef.current = selectedIndex
|
||||||
pagerRef.current?.setPage(selectedIndex, 'desktop-sidebar-click')
|
pagerRef.current?.setPage(selectedIndex, 'desktop-sidebar-click')
|
||||||
}
|
}
|
||||||
}, [selectedIndex, usedStarterPack, setUsedStarterPack, allFeeds])
|
}, [
|
||||||
|
selectedIndex,
|
||||||
|
allFeeds,
|
||||||
|
currentStarterPack?.initialFeed,
|
||||||
|
setCurrentStarterPack,
|
||||||
|
])
|
||||||
|
|
||||||
const {hasSession} = useSession()
|
const {hasSession} = useSession()
|
||||||
const setMinimalShellMode = useSetMinimalShellMode()
|
const setMinimalShellMode = useSetMinimalShellMode()
|
||||||
|
|||||||
Reference in New Issue
Block a user