| 1 | "use client"; |
| 2 | |
| 3 | import { createContext, useContext, useState, useCallback, type ReactNode } from "react"; |
| 4 | |
| 5 | const CollabNavActionsContext = createContext<{ |
| 6 | actions: ReactNode; |
| 7 | setActions: (node: ReactNode) => void; |
| 8 | }>({ actions: null, setActions: () => {} }); |
| 9 | |
| 10 | export function CollabNavActionsProvider({ children }: { children: ReactNode }) { |
| 11 | const [actions, setActions] = useState<ReactNode>(null); |
| 12 | return ( |
| 13 | <CollabNavActionsContext.Provider value={{ actions, setActions }}> |
| 14 | {children} |
| 15 | </CollabNavActionsContext.Provider> |
| 16 | ); |
| 17 | } |
| 18 | |
| 19 | export function useCollabNavActions() { |
| 20 | return useContext(CollabNavActionsContext); |
| 21 | } |
| 22 | |
| 23 | /** Slot that renders whatever was set via setActions */ |
| 24 | export function CollabNavActionsSlot() { |
| 25 | const { actions } = useContext(CollabNavActionsContext); |
| 26 | return <>{actions}</>; |
| 27 | } |
| 28 | |