Skip to content

Commit

Permalink
[Experiment] Ignore the persisted tab (#3442)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon authored Apr 8, 2024
1 parent f03390e commit 6d3f939
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/state/shell/selected-feed.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import React from 'react'
import * as persisted from '#/state/persisted'

import {useGate} from '#/lib/statsig/statsig'
import {isWeb} from '#/platform/detection'
import * as persisted from '#/state/persisted'

type StateContext = string
type SetContext = (v: string) => void

const stateContext = React.createContext<StateContext>('home')
const setContext = React.createContext<SetContext>((_: string) => {})

function getInitialFeed() {
function getInitialFeed(startSessionWithFollowing: boolean) {
if (isWeb) {
if (window.location.pathname === '/') {
const params = new URLSearchParams(window.location.search)
Expand All @@ -24,16 +26,21 @@ function getInitialFeed() {
return feedFromSession
}
}
const feedFromPersisted = persisted.get('lastSelectedHomeFeed')
if (feedFromPersisted) {
// Fall back to the last chosen one across all tabs.
return feedFromPersisted
if (!startSessionWithFollowing) {
const feedFromPersisted = persisted.get('lastSelectedHomeFeed')
if (feedFromPersisted) {
// Fall back to the last chosen one across all tabs.
return feedFromPersisted
}
}
return 'home'
}

export function Provider({children}: React.PropsWithChildren<{}>) {
const [state, setState] = React.useState(getInitialFeed)
const startSessionWithFollowing = useGate('start_session_with_following')
const [state, setState] = React.useState(() =>
getInitialFeed(startSessionWithFollowing),
)

const saveState = React.useCallback((feed: string) => {
setState(feed)
Expand Down

0 comments on commit 6d3f939

Please sign in to comment.