Something went wrong. Try again.
Mirror — see github.com/blacksky-algorithms/blacksky.community
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667import {createContext, useContext, useState} from 'react'
import {logger} from '#/logger'
type StarterPackLanding = { type: 'starterpack' uri: string isClip?: boolean}
type GroupChatJoinRequestLanding = { type: 'groupchat' uri: string code: string}
type LandingType = StarterPackLanding | GroupChatJoinRequestLanding | undefined
type SetContext = (v: LandingType) => void
const stateContext = createContext<LandingType>(undefined)stateContext.displayName = 'ActiveLandingStateContext'const setContext = createContext<SetContext>((_: LandingType) => {})setContext.displayName = 'ActiveLandingSetContext'
export function Provider({children}: {children: React.ReactNode}) { const [state, setState] = useState<LandingType>()
return ( <stateContext.Provider value={state}> <setContext.Provider value={setState}>{children}</setContext.Provider> </stateContext.Provider> )}
// Core hooksexport const useActiveLanding = () => useContext(stateContext)export const useSetActiveLanding = () => useContext(setContext)
// Filtered hooks for convenienceexport const useActiveStarterPack = () => { const landing = useActiveLanding() return landing?.type === 'starterpack' ? landing : undefined}
export const useSetActiveStarterPack = () => { const setLanding = useSetActiveLanding() const currentLanding = useActiveLanding() return (pack: {uri: string; isClip?: boolean} | undefined) => { if (!pack) { setLanding(undefined) } else { if (currentLanding && currentLanding.type !== 'starterpack') { logger.debug( `[landing] Replacing ${currentLanding.type} landing with starterpack`, ) } setLanding({type: 'starterpack', ...pack}) } }}
export const useActiveGroupChatJoinRequest = () => { const landing = useActiveLanding() return landing?.type === 'groupchat' ? landing : undefined}