2021-02-23 05:17:41 -05:00
|
|
|
import React, { createContext, useContext } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import useScopeValue from './util/scope-value-hook'
|
|
|
|
|
|
|
|
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,
|
2021-03-10 07:19:54 -05:00
|
|
|
setLeftMenuShown: PropTypes.func.isRequired,
|
2021-04-27 03:52:58 -04:00
|
|
|
pdfLayout: PropTypes.oneOf(['sideBySide', 'flat', 'split']).isRequired,
|
|
|
|
}).isRequired,
|
2021-02-23 05:17:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export function LayoutProvider({ children, $scope }) {
|
|
|
|
const [view, setView] = useScopeValue('ui.view', $scope)
|
|
|
|
const [chatIsOpen, setChatIsOpen] = useScopeValue('ui.chatOpen', $scope)
|
|
|
|
const [reviewPanelOpen, setReviewPanelOpen] = useScopeValue(
|
|
|
|
'ui.reviewPanelOpen',
|
|
|
|
$scope
|
|
|
|
)
|
|
|
|
const [leftMenuShown, setLeftMenuShown] = useScopeValue(
|
|
|
|
'ui.leftMenuShown',
|
|
|
|
$scope
|
|
|
|
)
|
|
|
|
|
2021-03-10 07:19:54 -05:00
|
|
|
const [pdfLayout] = useScopeValue('ui.pdfLayout', $scope)
|
|
|
|
|
2021-02-23 05:17:41 -05:00
|
|
|
const layoutContextValue = {
|
|
|
|
view,
|
|
|
|
setView,
|
|
|
|
chatIsOpen,
|
|
|
|
setChatIsOpen,
|
|
|
|
reviewPanelOpen,
|
|
|
|
setReviewPanelOpen,
|
|
|
|
leftMenuShown,
|
2021-03-10 07:19:54 -05:00
|
|
|
setLeftMenuShown,
|
2021-04-27 03:52:58 -04:00
|
|
|
pdfLayout,
|
2021-02-23 05:17:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<LayoutContext.Provider value={layoutContextValue}>
|
|
|
|
{children}
|
|
|
|
</LayoutContext.Provider>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
LayoutProvider.propTypes = {
|
|
|
|
children: PropTypes.any,
|
2021-04-27 03:52:58 -04:00
|
|
|
$scope: PropTypes.any.isRequired,
|
2021-02-23 05:17:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export function useLayoutContext(propTypes) {
|
|
|
|
const data = useContext(LayoutContext)
|
|
|
|
PropTypes.checkPropTypes(propTypes, data, 'data', 'LayoutContext.Provider')
|
|
|
|
return data
|
|
|
|
}
|