[Experiment] Ignore the persisted tab (#3442)
This commit is contained in:
parent
f03390e4b2
commit
6d3f9397f4
1 changed files with 14 additions and 7 deletions
|
@ -1,6 +1,8 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import * as persisted from '#/state/persisted'
|
|
||||||
|
import {useGate} from '#/lib/statsig/statsig'
|
||||||
import {isWeb} from '#/platform/detection'
|
import {isWeb} from '#/platform/detection'
|
||||||
|
import * as persisted from '#/state/persisted'
|
||||||
|
|
||||||
type StateContext = string
|
type StateContext = string
|
||||||
type SetContext = (v: string) => void
|
type SetContext = (v: string) => void
|
||||||
|
@ -8,7 +10,7 @@ type SetContext = (v: string) => void
|
||||||
const stateContext = React.createContext<StateContext>('home')
|
const stateContext = React.createContext<StateContext>('home')
|
||||||
const setContext = React.createContext<SetContext>((_: string) => {})
|
const setContext = React.createContext<SetContext>((_: string) => {})
|
||||||
|
|
||||||
function getInitialFeed() {
|
function getInitialFeed(startSessionWithFollowing: boolean) {
|
||||||
if (isWeb) {
|
if (isWeb) {
|
||||||
if (window.location.pathname === '/') {
|
if (window.location.pathname === '/') {
|
||||||
const params = new URLSearchParams(window.location.search)
|
const params = new URLSearchParams(window.location.search)
|
||||||
|
@ -24,16 +26,21 @@ function getInitialFeed() {
|
||||||
return feedFromSession
|
return feedFromSession
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!startSessionWithFollowing) {
|
||||||
const feedFromPersisted = persisted.get('lastSelectedHomeFeed')
|
const feedFromPersisted = persisted.get('lastSelectedHomeFeed')
|
||||||
if (feedFromPersisted) {
|
if (feedFromPersisted) {
|
||||||
// Fall back to the last chosen one across all tabs.
|
// Fall back to the last chosen one across all tabs.
|
||||||
return feedFromPersisted
|
return feedFromPersisted
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return 'home'
|
return 'home'
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Provider({children}: React.PropsWithChildren<{}>) {
|
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) => {
|
const saveState = React.useCallback((feed: string) => {
|
||||||
setState(feed)
|
setState(feed)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue