mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-04 23:05:56 -05:00
438192fc11
* Remove need for custom set-review-panel-open event * Open current file view when clicking add comment tooltip --------- Co-authored-by: Domagoj Kriskovic <dom.kriskovic@overleaf.com> GitOrigin-RevId: 2b21061193f4270030d73174014aabbd017fd38e
54 lines
1.1 KiB
TypeScript
54 lines
1.1 KiB
TypeScript
import {
|
|
createContext,
|
|
Dispatch,
|
|
FC,
|
|
SetStateAction,
|
|
useContext,
|
|
useMemo,
|
|
useState,
|
|
} from 'react'
|
|
|
|
export type View = 'cur_file' | 'overview'
|
|
|
|
export const ReviewPanelViewContext = createContext<View>('cur_file')
|
|
|
|
type ViewActions = {
|
|
setView: Dispatch<SetStateAction<View>>
|
|
}
|
|
|
|
const ReviewPanelViewActionsContext = createContext<ViewActions | undefined>(
|
|
undefined
|
|
)
|
|
|
|
export const ReviewPanelViewProvider: FC = ({ children }) => {
|
|
const [view, setView] = useState<View>('cur_file')
|
|
|
|
const actions = useMemo(
|
|
() => ({
|
|
setView,
|
|
}),
|
|
[setView]
|
|
)
|
|
|
|
return (
|
|
<ReviewPanelViewActionsContext.Provider value={actions}>
|
|
<ReviewPanelViewContext.Provider value={view}>
|
|
{children}
|
|
</ReviewPanelViewContext.Provider>
|
|
</ReviewPanelViewActionsContext.Provider>
|
|
)
|
|
}
|
|
|
|
export const useReviewPanelViewContext = () => {
|
|
return useContext(ReviewPanelViewContext)
|
|
}
|
|
|
|
export const useReviewPanelViewActionsContext = () => {
|
|
const context = useContext(ReviewPanelViewActionsContext)
|
|
if (!context) {
|
|
throw new Error(
|
|
'useViewActionsContext is only available inside ViewProvider'
|
|
)
|
|
}
|
|
return context
|
|
}
|