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