mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
1760d93fc4
* Upgrade react and react-dom * Fix test * Ensure that the "history:toggle" event is broadcast when switching in or out of history view * Add ControlledDropdown * Remove DropdownButton stories GitOrigin-RevId: 3810f6986bb60e59af31f960f431c31be16554f5
73 lines
2 KiB
JavaScript
73 lines
2 KiB
JavaScript
import React, { createContext, useContext, useCallback } from 'react'
|
|
import PropTypes from 'prop-types'
|
|
import useScopeValue from './util/scope-value-hook'
|
|
import { useIdeContext } from './ide-context'
|
|
|
|
export const LayoutContext = createContext()
|
|
|
|
LayoutContext.Provider.propTypes = {
|
|
value: PropTypes.shape({
|
|
view: PropTypes.string,
|
|
setView: PropTypes.func.isRequired,
|
|
chatIsOpen: PropTypes.bool,
|
|
setChatIsOpen: PropTypes.func.isRequired,
|
|
reviewPanelOpen: PropTypes.bool,
|
|
setReviewPanelOpen: PropTypes.func.isRequired,
|
|
leftMenuShown: PropTypes.bool,
|
|
setLeftMenuShown: PropTypes.func.isRequired,
|
|
pdfLayout: PropTypes.oneOf(['sideBySide', 'flat', 'split']).isRequired,
|
|
}).isRequired,
|
|
}
|
|
|
|
export function LayoutProvider({ children }) {
|
|
const { $scope } = useIdeContext()
|
|
|
|
const [view, _setView] = useScopeValue('ui.view')
|
|
|
|
const setView = useCallback(
|
|
value => {
|
|
_setView(oldValue => {
|
|
// ensure that the "history:toggle" event is broadcast when switching in or out of history view
|
|
if (value === 'history' || oldValue === 'history') {
|
|
$scope.toggleHistory()
|
|
}
|
|
|
|
return value
|
|
})
|
|
},
|
|
[$scope, _setView]
|
|
)
|
|
|
|
const [chatIsOpen, setChatIsOpen] = useScopeValue('ui.chatOpen')
|
|
const [reviewPanelOpen, setReviewPanelOpen] = useScopeValue(
|
|
'ui.reviewPanelOpen'
|
|
)
|
|
const [leftMenuShown, setLeftMenuShown] = useScopeValue('ui.leftMenuShown')
|
|
const [pdfLayout] = useScopeValue('ui.pdfLayout')
|
|
|
|
const value = {
|
|
view,
|
|
setView,
|
|
chatIsOpen,
|
|
setChatIsOpen,
|
|
reviewPanelOpen,
|
|
setReviewPanelOpen,
|
|
leftMenuShown,
|
|
setLeftMenuShown,
|
|
pdfLayout,
|
|
}
|
|
|
|
return (
|
|
<LayoutContext.Provider value={value}>{children}</LayoutContext.Provider>
|
|
)
|
|
}
|
|
|
|
LayoutProvider.propTypes = {
|
|
children: PropTypes.any,
|
|
}
|
|
|
|
export function useLayoutContext(propTypes) {
|
|
const data = useContext(LayoutContext)
|
|
PropTypes.checkPropTypes(propTypes, data, 'data', 'LayoutContext.Provider')
|
|
return data
|
|
}
|