Bluesky app fork with some witchin' additions 💫

scope last-selected-feed to per-account (#9500)

authored by samuel.fm and committed by

GitHub d9e37a22 3b98f2f8

+33 -21
+1
src/state/persisted/schema.ts
··· 116 116 }), 117 117 hiddenPosts: z.array(z.string()).optional(), // should move to server 118 118 useInAppBrowser: z.boolean().optional(), 119 + /** @deprecated */ 119 120 lastSelectedHomeFeed: z.string().optional(), 120 121 pdsAddressHistory: z.array(z.string()).optional(), 121 122 disableHaptics: z.boolean().optional(),
+30 -21
src/state/shell/selected-feed.tsx
··· 1 - import React from 'react' 1 + import {createContext, useCallback, useContext, useState} from 'react' 2 2 3 3 import {isWeb} from '#/platform/detection' 4 - import * as persisted from '#/state/persisted' 5 4 import {type FeedDescriptor} from '#/state/queries/post-feed' 5 + import {useSession} from '#/state/session' 6 + import {account} from '#/storage' 6 7 7 8 type StateContext = FeedDescriptor | null 8 9 type SetContext = (v: FeedDescriptor) => void 9 10 10 - const stateContext = React.createContext<StateContext>(null) 11 + const stateContext = createContext<StateContext>(null) 11 12 stateContext.displayName = 'SelectedFeedStateContext' 12 - const setContext = React.createContext<SetContext>((_: string) => {}) 13 + const setContext = createContext<SetContext>((_: string) => {}) 13 14 setContext.displayName = 'SelectedFeedSetContext' 14 15 15 - function getInitialFeed(): FeedDescriptor | null { 16 + function getInitialFeed(did?: string): FeedDescriptor | null { 16 17 if (isWeb) { 17 18 if (window.location.pathname === '/') { 18 19 const params = new URLSearchParams(window.location.search) ··· 30 31 } 31 32 } 32 33 33 - const feedFromPersisted = persisted.get('lastSelectedHomeFeed') 34 - if (feedFromPersisted) { 35 - // Fall back to the last chosen one across all tabs. 36 - return feedFromPersisted as FeedDescriptor 34 + if (did) { 35 + const feedFromStorage = account.get([did, 'lastSelectedHomeFeed']) 36 + if (feedFromStorage) { 37 + // Fall back to the last chosen one across all tabs. 38 + return feedFromStorage as FeedDescriptor 39 + } 37 40 } 38 41 39 42 return null 40 43 } 41 44 42 45 export function Provider({children}: React.PropsWithChildren<{}>) { 43 - const [state, setState] = React.useState(() => getInitialFeed()) 46 + const {currentAccount} = useSession() 47 + const [state, setState] = useState(() => getInitialFeed(currentAccount?.did)) 44 48 45 - const saveState = React.useCallback((feed: FeedDescriptor) => { 46 - setState(feed) 47 - if (isWeb) { 48 - try { 49 - sessionStorage.setItem('lastSelectedHomeFeed', feed) 50 - } catch {} 51 - } 52 - persisted.write('lastSelectedHomeFeed', feed) 53 - }, []) 49 + const saveState = useCallback( 50 + (feed: FeedDescriptor) => { 51 + setState(feed) 52 + if (isWeb) { 53 + try { 54 + sessionStorage.setItem('lastSelectedHomeFeed', feed) 55 + } catch {} 56 + } 57 + if (currentAccount?.did) { 58 + account.set([currentAccount?.did, 'lastSelectedHomeFeed'], feed) 59 + } 60 + }, 61 + [currentAccount?.did], 62 + ) 54 63 55 64 return ( 56 65 <stateContext.Provider value={state}> ··· 60 69 } 61 70 62 71 export function useSelectedFeed() { 63 - return React.useContext(stateContext) 72 + return useContext(stateContext) 64 73 } 65 74 66 75 export function useSetSelectedFeed() { 67 - return React.useContext(setContext) 76 + return useContext(setContext) 68 77 }
+2
src/storage/schema.ts
··· 66 66 * this device. 67 67 */ 68 68 birthdateLastUpdatedAt?: string 69 + 70 + lastSelectedHomeFeed?: string 69 71 }