diff options
Diffstat (limited to 'src/state/shell/selected-feed.tsx')
-rw-r--r-- | src/state/shell/selected-feed.tsx | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/src/state/shell/selected-feed.tsx b/src/state/shell/selected-feed.tsx index df50b3952..08b7ba77c 100644 --- a/src/state/shell/selected-feed.tsx +++ b/src/state/shell/selected-feed.tsx @@ -1,47 +1,46 @@ import React from 'react' -import {Gate} from '#/lib/statsig/gates' -import {useGate} from '#/lib/statsig/statsig' import {isWeb} from '#/platform/detection' import * as persisted from '#/state/persisted' +import {FeedDescriptor} from '#/state/queries/post-feed' -type StateContext = string -type SetContext = (v: string) => void +type StateContext = FeedDescriptor | null +type SetContext = (v: FeedDescriptor) => void -const stateContext = React.createContext<StateContext>('home') +const stateContext = React.createContext<StateContext>(null) const setContext = React.createContext<SetContext>((_: string) => {}) -function getInitialFeed(gate: (gateName: Gate) => boolean) { +function getInitialFeed(): FeedDescriptor | null { if (isWeb) { if (window.location.pathname === '/') { const params = new URLSearchParams(window.location.search) const feedFromUrl = params.get('feed') if (feedFromUrl) { // If explicitly booted from a link like /?feed=..., prefer that. - return feedFromUrl + return feedFromUrl as FeedDescriptor } } + const feedFromSession = sessionStorage.getItem('lastSelectedHomeFeed') if (feedFromSession) { // Fall back to a previously chosen feed for this browser tab. - return feedFromSession + return feedFromSession as FeedDescriptor } } - if (!gate('start_session_with_following_v2')) { - const feedFromPersisted = persisted.get('lastSelectedHomeFeed') - if (feedFromPersisted) { - // Fall back to the last chosen one across all tabs. - return feedFromPersisted - } + + const feedFromPersisted = persisted.get('lastSelectedHomeFeed') + if (feedFromPersisted) { + // Fall back to the last chosen one across all tabs. + return feedFromPersisted as FeedDescriptor } - return 'home' + + return null } export function Provider({children}: React.PropsWithChildren<{}>) { - const gate = useGate() - const [state, setState] = React.useState(() => getInitialFeed(gate)) + const [state, setState] = React.useState(() => getInitialFeed()) - const saveState = React.useCallback((feed: string) => { + const saveState = React.useCallback((feed: FeedDescriptor) => { setState(feed) if (isWeb) { try { |