handle used URLs nicely

This commit is contained in:
Hailey
2024-06-17 00:21:39 -07:00
parent 02f4477067
commit c7ddaa1c4d
5 changed files with 38 additions and 4 deletions
+1
View File
@@ -102,6 +102,7 @@ export function StepFinished() {
initialFeed: 'following',
})
}
console.log('ADDING PACK')
addUsedStarterPack(makeStarterPackLink(starterPack))
}
})(),
@@ -287,6 +287,20 @@ function LandingScreenInner({
)}
</View>
</View>
<Button
label={_(msg`Signup without a starter pack`)}
variant="ghost"
color="secondary"
size="medium"
style={[a.mt_2xl]}
onPress={() => {
setCurrentStarterPack(undefined)
setScreenState(LoggedOutScreenState.S_CreateAccount)
}}>
<ButtonText>
<Trans>Signup without a starter pack</Trans>
</ButtonText>
</Button>
</ScrollView>
<AppClipOverlay
visible={appClipOverlayVisible}
+3 -1
View File
@@ -16,7 +16,9 @@ const stateContext = React.createContext<StateContext>(undefined)
const setContext = React.createContext<SetContext>((_: StateContext) => {})
export function Provider({children}: {children: React.ReactNode}) {
const [state, setState] = React.useState<StateContext>()
const [state, setState] = React.useState<StateContext>(() =>
persisted.get('currentStarterPack'),
)
const setStateWrapped = (v: StateContext) => {
setState(v)
+4 -1
View File
@@ -9,9 +9,12 @@ 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 [state, setState] = React.useState<StateContext>(() =>
persisted.get('usedStarterPacks'),
)
const setStateWrapped = (v: string) => {
console.log('ADDING!!!', v)
persisted.write('usedStarterPacks', [...(state ? state : []), v])
setState(prev => [...(prev ? prev : []), v])
}
+16 -2
View File
@@ -26,6 +26,7 @@ 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'
@@ -41,18 +42,27 @@ 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) {
setShowLoggedOut(true)
requestSwitchToAccount({requestedAccount: 'starterpack'})
// 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 {}
}
}, [
setShowLoggedOut,
requestSwitchToAccount,
currentStarterPack?.initialFeed,
currentStarterPack,
usedStarterPacks,
])
if (preferences && pinnedFeedInfos && !isPinnedFeedsLoading) {
@@ -103,6 +113,10 @@ function HomeScreenReady({
const lastPagerReportedIndexRef = React.useRef(selectedIndex)
React.useLayoutEffect(() => {
let initialIndex = selectedIndex
console.log(
'currentStarterPack.initialFeed',
currentStarterPack?.initialFeed,
)
if (currentStarterPack?.initialFeed) {
if (currentStarterPack.initialFeed === 'following') {
initialIndex = 1