import React from "react"; import PropTypes from "prop-types"; import styled, { css } from "styled-components"; //import equal from "fast-deep-equal/react"; //import { LayoutContextConsumer } from "studio/Layout/context"; import { isMobile } from "react-device-detect"; import { inject, observer } from "mobx-react"; import Scrollbar from "@appserver/components/scrollbar"; import DragAndDrop from "@appserver/components/drag-and-drop"; import { tablet, desktop } from "@appserver/components/utils/device"; const paddingStyles = css` padding: 17px 7px 16px 24px; @media ${tablet} { padding: 16px 0 16px 24px; } `; const commonStyles = css` flex-grow: 1; ${(props) => (props.isDesktop ? "height: auto" : "height: 100%")}; border-left: none; -webkit-user-select: none; .section-wrapper { ${(props) => !props.withScroll && `display: flex; height: 100%; box-sizing:border-box`}; ${(props) => !props.withScroll && paddingStyles} } .section-wrapper-content { ${paddingStyles} flex: 1 0 auto; outline: none; ${(props) => props.viewAs == "tile" && css` padding-right: 0; padding-left: 20px; `} .section-wrapper { display: flex; flex-direction: column; min-height: 100%; } .section-wrapper { display: flex; flex-direction: column; min-height: 100%; } .people-row-container, .files-row-container { margin-top: -22px; @media ${desktop} { ${(props) => props.viewAs === "row" && `margin-top: -9px;`} } } } `; const StyledSectionBody = styled.div` ${commonStyles} ${(props) => props.withScroll && ` margin-left: -24px; `} .additional-scroll-height { ${(props) => !props.withScroll && !props.pinned && ` height: 64px; `} } `; const StyledDropZoneBody = styled(DragAndDrop)` ${commonStyles} .drag-and-drop { user-select: none; height: 100%; } ${(props) => props.withScroll && ` margin-left: -24px; `} `; const StyledSpacer = styled.div` display: none; min-height: 64px; @media ${tablet} { display: ${(props) => (props.pinned ? "none" : "block")}; } `; class SectionBody extends React.Component { constructor(props) { super(props); this.focusRef = React.createRef(); } // shouldComponentUpdate(nextProps) { // return !equal(this.props, nextProps); // } componentDidMount() { const { withScroll } = this.props; if (!this.props.autoFocus) return; if (withScroll) this.focusRef.current.focus(); } componentWillUnmount() { this.focusRef = null; } render() { //console.log("PageLayout SectionBody render" ); const { autoFocus, children, onDrop, pinned, uploadFiles, viewAs, withScroll, isLoaded, isDesktop, } = this.props; const focusProps = autoFocus ? { ref: this.focusRef, tabIndex: -1, } : {}; console.log("isDesktop", isDesktop); return uploadFiles ? ( {withScroll ? ( !isMobile ? (
{children}
) : (
{children}
) ) : (
{children}
)}
) : ( {withScroll ? ( !isMobile ? (
{children}
) : (
{children}
) ) : (
{children}
)}
); } } SectionBody.displayName = "SectionBody"; SectionBody.propTypes = { withScroll: PropTypes.bool, autoFocus: PropTypes.bool, pinned: PropTypes.bool, onDrop: PropTypes.func, uploadFiles: PropTypes.bool, children: PropTypes.oneOfType([ PropTypes.arrayOf(PropTypes.node), PropTypes.node, PropTypes.any, ]), viewAs: PropTypes.string, isLoaded: PropTypes.bool, }; SectionBody.defaultProps = { autoFocus: false, pinned: false, uploadFiles: false, withScroll: true, }; export default inject(({ auth }) => { const { settingsStore } = auth; const { isDesktopClient: isDesktop } = settingsStore; return { isLoaded: auth.isLoaded, isDesktop, }; })(observer(SectionBody));