54 changed files with 173 additions and 99 deletions
@ -0,0 +1,22 @@ |
|||||||
|
import { createContext, useContext } from 'react' |
||||||
|
|
||||||
|
export type NoteDrawerContextValue = { |
||||||
|
openDrawer: (noteId: string) => void |
||||||
|
closeDrawer: () => void |
||||||
|
isDrawerOpen: boolean |
||||||
|
drawerNoteId: string | null |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Same rationale as {@link PrimaryNoteViewContext}: keep context identity out of PageManager.tsx |
||||||
|
* so lazy chunks never instantiate a duplicate context. |
||||||
|
*/ |
||||||
|
export const NoteDrawerContext = createContext<NoteDrawerContextValue | undefined>(undefined) |
||||||
|
|
||||||
|
export function useNoteDrawer(): NoteDrawerContextValue { |
||||||
|
const context = useContext(NoteDrawerContext) |
||||||
|
if (!context) { |
||||||
|
throw new Error('useNoteDrawer must be used within a NoteDrawerContext.Provider') |
||||||
|
} |
||||||
|
return context |
||||||
|
} |
||||||
@ -0,0 +1,38 @@ |
|||||||
|
import { createContext, useContext, type ReactNode } from 'react' |
||||||
|
|
||||||
|
export type TPrimaryOverlayViewType = |
||||||
|
| 'note' |
||||||
|
| 'settings' |
||||||
|
| 'settings-sub' |
||||||
|
| 'profile' |
||||||
|
| 'hashtag' |
||||||
|
| 'relay' |
||||||
|
| 'following' |
||||||
|
| 'mute' |
||||||
|
| 'others-relay-settings' |
||||||
|
|
||||||
|
export type PrimaryNoteViewContextValue = { |
||||||
|
setPrimaryNoteView: (view: ReactNode | null, type?: TPrimaryOverlayViewType) => void |
||||||
|
primaryViewType: TPrimaryOverlayViewType | null |
||||||
|
getNavigationCounter: () => number |
||||||
|
/** Top URL in the secondary stack (right panel), or undefined if empty. */ |
||||||
|
getTopSecondaryUrl: () => string | undefined |
||||||
|
/** Primary overlay (mobile / narrow): child calls this to expose refresh for the chrome bar. */ |
||||||
|
registerPrimaryPanelRefresh: (fn: (() => void) | null) => void |
||||||
|
triggerPrimaryPanelRefresh: () => void |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Dedicated module so lazy chunks (e.g. BottomNavigationBar) share the same context as PageManager. |
||||||
|
* Importing these hooks from PageManager into those chunks can duplicate the module and break |
||||||
|
* Provider matching ("must be used within PrimaryNoteViewContext.Provider"). |
||||||
|
*/ |
||||||
|
export const PrimaryNoteViewContext = createContext<PrimaryNoteViewContextValue | undefined>(undefined) |
||||||
|
|
||||||
|
export function usePrimaryNoteView(): PrimaryNoteViewContextValue { |
||||||
|
const context = useContext(PrimaryNoteViewContext) |
||||||
|
if (!context) { |
||||||
|
throw new Error('usePrimaryNoteView must be used within a PrimaryNoteViewContext.Provider') |
||||||
|
} |
||||||
|
return context |
||||||
|
} |
||||||
Loading…
Reference in new issue