import React from "react"; import PropTypes, { element } from "prop-types"; import { inject, observer } from "mobx-react"; import { isMobile } from "react-device-detect"; import { isMobile as isMobileUtils, isTablet as isTabletUtils, } from "@docspace/components/utils/device"; import { Provider } from "@docspace/components/utils/context"; import SectionContainer from "./sub-components/section-container"; import SubSectionHeader from "./sub-components/section-header"; import SubSectionFilter from "./sub-components/section-filter"; import SubSectionBody from "./sub-components/section-body"; import SubSectionBodyContent from "./sub-components/section-body-content"; import SubSectionPaging from "./sub-components/section-paging"; import InfoPanel from "./sub-components/info-panel"; import SubInfoPanelBody from "./sub-components/info-panel-body"; import SubInfoPanelHeader from "./sub-components/info-panel-header"; import SubSectionFooter from "./sub-components/section-footer"; import FloatingButton from "@docspace/components/floating-button"; const Section = (props) => { const { onDrop, showPrimaryProgressBar, primaryProgressBarIcon, primaryProgressBarValue, showPrimaryButtonAlert, showSecondaryProgressBar, secondaryProgressBarValue, secondaryProgressBarIcon, showSecondaryButtonAlert, uploadFiles, viewAs, withBodyScroll, children, isHeaderVisible, onOpenUploadPanel, isTabletView, maintenanceExist, snackbarExist, showText, isInfoPanelAvailable, settingsStudio, clearUploadedFilesHistory, isInfoPanelVisible, isInfoPanelScrollLocked, isEmptyPage, } = props; const [sectionSize, setSectionSize] = React.useState({ width: null, height: null, }); const containerRef = React.useRef(null); const timerRef = React.useRef(null); let sectionHeaderContent = null; let sectionFilterContent = null; let sectionPagingContent = null; let sectionBodyContent = null; let sectionFooterContent = null; let infoPanelBodyContent = null; let infoPanelHeaderContent = null; React.Children.forEach(children, (child) => { const childType = child && child.type && (child.type.displayName || child.type.name); switch (childType) { case Section.SectionHeader.displayName: sectionHeaderContent = child; break; case Section.SectionFilter.displayName: sectionFilterContent = child; break; case Section.SectionPaging.displayName: sectionPagingContent = child; break; case Section.SectionBody.displayName: sectionBodyContent = child; break; case Section.SectionFooter.displayName: sectionFooterContent = child; break; case Section.InfoPanelBody.displayName: infoPanelBodyContent = child; break; case Section.InfoPanelHeader.displayName: infoPanelHeaderContent = child; break; default: break; } }); const isSectionHeaderAvailable = !!sectionHeaderContent, isSectionFilterAvailable = !!sectionFilterContent, isSectionPagingAvailable = !!sectionPagingContent, isSectionBodyAvailable = !!sectionBodyContent || isSectionFilterAvailable || isSectionPagingAvailable, isSectionAvailable = isSectionHeaderAvailable || isSectionFilterAvailable || isSectionBodyAvailable || isSectionPagingAvailable; React.useEffect(() => { window.addEventListener("resize", onResize); const ro = new ResizeObserver(onResize); !!containerRef.current && ro.observe(containerRef.current); return () => { !!containerRef.current && ro.unobserve(containerRef.current); window.removeEventListener("resize", onResize); }; }, []); const onResize = React.useCallback(() => { clearTimeout(timerRef.current); timerRef.current = setTimeout(() => { if (!containerRef.current) return; const computedStyles = window.getComputedStyle( containerRef.current, null ); const width = +computedStyles.getPropertyValue("width").replace("px", ""); const height = +computedStyles .getPropertyValue("height") .replace("px", ""); setSectionSize(() => ({ width, height })); }, 100); }, []); return ( <> {isSectionAvailable && ( {isSectionHeaderAvailable && !isMobile && ( {sectionHeaderContent ? sectionHeaderContent.props.children : null} )} {isSectionFilterAvailable && !isMobile && ( <> {sectionFilterContent ? sectionFilterContent.props.children : null} )} {isSectionBodyAvailable && ( <> {isSectionHeaderAvailable && isMobile && ( {sectionHeaderContent ? sectionHeaderContent.props.children : null} )} {isSectionFilterAvailable && isMobile && ( {sectionFilterContent ? sectionFilterContent.props.children : null} )} {sectionBodyContent ? sectionBodyContent.props.children : null} {sectionFooterContent ? sectionFooterContent.props.children : null} {isSectionPagingAvailable && ( {sectionPagingContent ? sectionPagingContent.props.children : null} )} )} {!(isMobile || isMobileUtils() || isTabletUtils()) ? ( showPrimaryProgressBar && showSecondaryProgressBar ? ( <> ) : showPrimaryProgressBar && !showSecondaryProgressBar ? ( ) : !showPrimaryProgressBar && showSecondaryProgressBar ? ( ) : ( <> ) ) : ( <> )} {isInfoPanelAvailable && ( {infoPanelHeaderContent} {infoPanelBodyContent} )} )} ); }; Section.SectionHeader = () => { return null; }; Section.SectionHeader.displayName = "SectionHeader"; Section.SectionFilter = () => { return null; }; Section.SectionFilter.displayName = "SectionFilter"; Section.SectionBody = () => { return null; }; Section.SectionBody.displayName = "SectionBody"; Section.SectionFooter = () => { return null; }; Section.SectionFooter.displayName = "SectionFooter"; Section.SectionPaging = () => { return null; }; Section.SectionPaging.displayName = "SectionPaging"; Section.InfoPanelBody = () => { return null; }; Section.InfoPanelBody.displayName = "InfoPanelBody"; Section.InfoPanelHeader = () => { return null; }; Section.InfoPanelHeader.displayName = "InfoPanelHeader"; Section.propTypes = { children: PropTypes.any, withBodyScroll: PropTypes.bool, showPrimaryProgressBar: PropTypes.bool, primaryProgressBarValue: PropTypes.number, showPrimaryButtonAlert: PropTypes.bool, progressBarDropDownContent: PropTypes.any, primaryProgressBarIcon: PropTypes.string, showSecondaryProgressBar: PropTypes.bool, secondaryProgressBarValue: PropTypes.number, secondaryProgressBarIcon: PropTypes.string, showSecondaryButtonAlert: PropTypes.bool, onDrop: PropTypes.func, uploadFiles: PropTypes.bool, viewAs: PropTypes.string, onOpenUploadPanel: PropTypes.func, isTabletView: PropTypes.bool, isHeaderVisible: PropTypes.bool, isInfoPanelAvailable: PropTypes.bool, settingsStudio: PropTypes.bool, isEmptyPage: PropTypes.bool, }; Section.defaultProps = { withBodyScroll: true, isInfoPanelAvailable: true, settingsStudio: false, }; export default inject(({ auth }) => { const { settingsStore } = auth; const { isHeaderVisible, isTabletView, maintenanceExist, snackbarExist, showText, } = settingsStore; const { isVisible: isInfoPanelVisible, isScrollLocked: isInfoPanelScrollLocked, } = auth.infoPanelStore; return { isTabletView, isHeaderVisible, maintenanceExist, snackbarExist, showText, isInfoPanelVisible, isInfoPanelScrollLocked, }; })(observer(Section));