2022-02-02 11:24:35 +00:00
|
|
|
import React from "react";
|
|
|
|
import PropTypes from "prop-types";
|
2021-10-15 07:07:15 +00:00
|
|
|
|
2022-02-02 11:24:35 +00:00
|
|
|
import StyledContainer from "./StyledNavigation";
|
|
|
|
import ArrowButton from "./sub-components/arrow-btn";
|
|
|
|
import Text from "./sub-components/text";
|
|
|
|
import ControlButtons from "./sub-components/control-btn";
|
|
|
|
import DropBox from "./sub-components/drop-box";
|
2021-10-15 07:07:15 +00:00
|
|
|
|
2022-07-22 19:01:25 +00:00
|
|
|
import { Consumer } from "@docspace/components/utils/context";
|
2021-10-15 07:07:15 +00:00
|
|
|
|
2022-07-22 19:01:25 +00:00
|
|
|
import DomHelpers from "@docspace/components/utils/domHelpers";
|
|
|
|
import Backdrop from "@docspace/components/backdrop";
|
2021-10-15 07:07:15 +00:00
|
|
|
|
2022-05-11 07:58:24 +00:00
|
|
|
import { isMobile, isMobileOnly } from "react-device-detect";
|
|
|
|
import {
|
|
|
|
isMobile as isMobileUtils,
|
|
|
|
isTablet as isTabletUtils,
|
|
|
|
isDesktop as isDesktopUtils,
|
2022-07-22 19:01:25 +00:00
|
|
|
} from "@docspace/components/utils/device";
|
2022-05-11 07:58:24 +00:00
|
|
|
import ToggleInfoPanelButton from "./sub-components/toggle-infopanel-btn";
|
|
|
|
|
2021-10-15 07:07:15 +00:00
|
|
|
const Navigation = ({
|
|
|
|
tReady,
|
2022-02-02 15:04:41 +00:00
|
|
|
showText,
|
2021-10-15 07:07:15 +00:00
|
|
|
isRootFolder,
|
|
|
|
title,
|
|
|
|
canCreate,
|
|
|
|
isTabletView,
|
|
|
|
personal,
|
|
|
|
onClickFolder,
|
|
|
|
navigationItems,
|
|
|
|
getContextOptionsPlus,
|
|
|
|
getContextOptionsFolder,
|
|
|
|
onBackToParentFolder,
|
2022-02-03 08:06:36 +00:00
|
|
|
isRecycleBinFolder,
|
|
|
|
isEmptyFilesList,
|
|
|
|
clearTrash,
|
2022-03-17 14:16:21 +00:00
|
|
|
showFolderInfo,
|
|
|
|
isCurrentFolderInfo,
|
2022-03-24 14:57:36 +00:00
|
|
|
toggleInfoPanel,
|
2022-03-17 14:16:21 +00:00
|
|
|
isInfoPanelVisible,
|
2022-05-13 16:33:16 +00:00
|
|
|
titles,
|
2021-10-15 07:07:15 +00:00
|
|
|
...rest
|
|
|
|
}) => {
|
|
|
|
const [isOpen, setIsOpen] = React.useState(false);
|
|
|
|
const [firstClick, setFirstClick] = React.useState(true);
|
2022-03-03 07:04:27 +00:00
|
|
|
const [dropBoxWidth, setDropBoxWidth] = React.useState(0);
|
2022-04-20 13:03:55 +00:00
|
|
|
const [maxHeight, setMaxHeight] = React.useState(false);
|
2022-03-03 07:04:27 +00:00
|
|
|
|
2021-10-15 07:07:15 +00:00
|
|
|
const dropBoxRef = React.useRef(null);
|
2022-03-03 07:04:27 +00:00
|
|
|
const containerRef = React.useRef(null);
|
2021-10-15 07:07:15 +00:00
|
|
|
|
2022-05-11 07:58:24 +00:00
|
|
|
const isDesktop =
|
|
|
|
(!isMobile && !isTabletUtils() && !isMobileUtils()) ||
|
|
|
|
(isDesktopUtils() && !isMobile);
|
|
|
|
|
2022-06-04 18:25:39 +00:00
|
|
|
const onMissClick = React.useCallback(
|
|
|
|
(e) => {
|
|
|
|
e.preventDefault;
|
|
|
|
const path = e.path || (e.composedPath && e.composedPath());
|
2022-02-21 08:09:21 +00:00
|
|
|
|
2022-06-04 18:25:39 +00:00
|
|
|
if (!firstClick) {
|
|
|
|
!path.includes(dropBoxRef.current) ? toggleDropBox() : null;
|
|
|
|
} else {
|
|
|
|
setFirstClick((prev) => !prev);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[firstClick, toggleDropBox, setFirstClick]
|
|
|
|
);
|
2021-10-15 07:07:15 +00:00
|
|
|
|
|
|
|
const onClickAvailable = React.useCallback(
|
2022-07-11 13:08:40 +00:00
|
|
|
(id, isRootRoom) => {
|
|
|
|
onClickFolder && onClickFolder(id, isRootRoom);
|
2021-10-15 07:07:15 +00:00
|
|
|
toggleDropBox();
|
|
|
|
},
|
2022-02-02 11:24:35 +00:00
|
|
|
[onClickFolder, toggleDropBox]
|
2021-10-15 07:07:15 +00:00
|
|
|
);
|
|
|
|
|
2022-03-03 07:04:27 +00:00
|
|
|
const toggleDropBox = () => {
|
2022-02-21 08:09:21 +00:00
|
|
|
if (isRootFolder) return setIsOpen(false);
|
2021-10-15 07:07:15 +00:00
|
|
|
setIsOpen((prev) => !prev);
|
2022-04-20 13:03:55 +00:00
|
|
|
|
|
|
|
setDropBoxWidth(DomHelpers.getOuterWidth(containerRef.current));
|
|
|
|
|
|
|
|
const { top } = DomHelpers.getOffset(containerRef.current);
|
|
|
|
|
|
|
|
setMaxHeight(`calc(100vh - ${top}px)`);
|
|
|
|
|
2021-10-15 07:07:15 +00:00
|
|
|
setFirstClick(true);
|
2022-03-03 07:04:27 +00:00
|
|
|
};
|
2021-10-15 07:07:15 +00:00
|
|
|
|
2022-04-20 09:18:59 +00:00
|
|
|
const onResize = React.useCallback(() => {
|
|
|
|
setDropBoxWidth(DomHelpers.getOuterWidth(containerRef.current));
|
|
|
|
}, [containerRef.current]);
|
|
|
|
|
2021-10-15 07:07:15 +00:00
|
|
|
React.useEffect(() => {
|
|
|
|
if (isOpen) {
|
2022-02-02 11:24:35 +00:00
|
|
|
window.addEventListener("click", onMissClick);
|
2022-04-20 09:18:59 +00:00
|
|
|
window.addEventListener("resize", onResize);
|
2021-10-15 07:07:15 +00:00
|
|
|
} else {
|
2022-02-02 11:24:35 +00:00
|
|
|
window.removeEventListener("click", onMissClick);
|
2022-05-16 09:59:27 +00:00
|
|
|
window.removeEventListener("resize", onResize);
|
2021-10-15 07:07:15 +00:00
|
|
|
setFirstClick(true);
|
|
|
|
}
|
|
|
|
|
2022-04-20 09:18:59 +00:00
|
|
|
return () => {
|
|
|
|
window.removeEventListener("click", onMissClick);
|
2022-05-16 09:59:27 +00:00
|
|
|
window.removeEventListener("resize", onResize);
|
2022-04-20 09:18:59 +00:00
|
|
|
};
|
|
|
|
}, [isOpen, onResize, onMissClick]);
|
2022-02-18 09:56:42 +00:00
|
|
|
|
|
|
|
const onBackToParentFolderAction = React.useCallback(() => {
|
|
|
|
setIsOpen((val) => !val);
|
|
|
|
onBackToParentFolder && onBackToParentFolder();
|
|
|
|
}, [onBackToParentFolder]);
|
2022-03-03 07:04:27 +00:00
|
|
|
|
2021-10-15 07:07:15 +00:00
|
|
|
return (
|
|
|
|
<Consumer>
|
|
|
|
{(context) => (
|
|
|
|
<>
|
|
|
|
{isOpen && (
|
2022-04-20 13:03:55 +00:00
|
|
|
<>
|
2022-05-11 09:27:15 +00:00
|
|
|
<Backdrop
|
|
|
|
visible={isOpen}
|
|
|
|
withBackground={false}
|
|
|
|
withoutBlur={true}
|
|
|
|
zIndex={400}
|
|
|
|
/>
|
|
|
|
|
2022-04-20 13:03:55 +00:00
|
|
|
<DropBox
|
|
|
|
{...rest}
|
2022-05-11 07:58:24 +00:00
|
|
|
isDesktop={isDesktop}
|
2022-04-20 13:03:55 +00:00
|
|
|
ref={dropBoxRef}
|
|
|
|
maxHeight={maxHeight}
|
|
|
|
dropBoxWidth={dropBoxWidth}
|
|
|
|
sectionHeight={context.sectionHeight}
|
|
|
|
showText={showText}
|
|
|
|
isRootFolder={isRootFolder}
|
|
|
|
onBackToParentFolder={onBackToParentFolderAction}
|
|
|
|
title={title}
|
|
|
|
personal={personal}
|
|
|
|
canCreate={canCreate}
|
|
|
|
navigationItems={navigationItems}
|
|
|
|
getContextOptionsFolder={getContextOptionsFolder}
|
|
|
|
getContextOptionsPlus={getContextOptionsPlus}
|
|
|
|
toggleDropBox={toggleDropBox}
|
|
|
|
toggleInfoPanel={toggleInfoPanel}
|
|
|
|
isInfoPanelVisible={isInfoPanelVisible}
|
|
|
|
onClickAvailable={onClickAvailable}
|
|
|
|
/>
|
|
|
|
</>
|
2021-10-15 07:07:15 +00:00
|
|
|
)}
|
|
|
|
<StyledContainer
|
2022-03-03 07:04:27 +00:00
|
|
|
ref={containerRef}
|
2021-10-15 07:07:15 +00:00
|
|
|
width={context.sectionWidth}
|
|
|
|
isRootFolder={isRootFolder}
|
|
|
|
canCreate={canCreate}
|
2022-02-02 11:24:35 +00:00
|
|
|
isTabletView={isTabletView}
|
2022-03-03 07:04:27 +00:00
|
|
|
isRecycleBinFolder={isRecycleBinFolder}
|
2022-05-11 07:58:24 +00:00
|
|
|
isDesktop={isDesktop}
|
2022-05-17 10:12:34 +00:00
|
|
|
isInfoPanelVisible={isInfoPanelVisible}
|
2022-02-02 11:24:35 +00:00
|
|
|
>
|
2022-03-03 07:04:27 +00:00
|
|
|
<ArrowButton
|
|
|
|
isRootFolder={isRootFolder}
|
|
|
|
onBackToParentFolder={onBackToParentFolder}
|
|
|
|
/>
|
|
|
|
<Text
|
|
|
|
title={title}
|
|
|
|
isOpen={false}
|
|
|
|
isRootFolder={isRootFolder}
|
|
|
|
onClick={toggleDropBox}
|
|
|
|
/>
|
|
|
|
<ControlButtons
|
|
|
|
personal={personal}
|
|
|
|
isRootFolder={isRootFolder}
|
|
|
|
canCreate={canCreate}
|
|
|
|
getContextOptionsFolder={getContextOptionsFolder}
|
|
|
|
getContextOptionsPlus={getContextOptionsPlus}
|
|
|
|
isRecycleBinFolder={isRecycleBinFolder}
|
|
|
|
isEmptyFilesList={isEmptyFilesList}
|
|
|
|
clearTrash={clearTrash}
|
2022-03-24 14:57:36 +00:00
|
|
|
toggleInfoPanel={toggleInfoPanel}
|
2022-03-17 14:16:21 +00:00
|
|
|
isInfoPanelVisible={isInfoPanelVisible}
|
2022-05-11 07:58:24 +00:00
|
|
|
isDesktop={isDesktop}
|
2022-05-13 16:33:16 +00:00
|
|
|
titles={titles}
|
2022-03-03 07:04:27 +00:00
|
|
|
/>
|
2021-10-15 07:07:15 +00:00
|
|
|
</StyledContainer>
|
2022-05-11 07:58:24 +00:00
|
|
|
{isDesktop && (
|
|
|
|
<ToggleInfoPanelButton
|
|
|
|
isRootFolder={isRootFolder}
|
|
|
|
toggleInfoPanel={toggleInfoPanel}
|
|
|
|
isInfoPanelVisible={isInfoPanelVisible}
|
|
|
|
/>
|
|
|
|
)}
|
2021-10-15 07:07:15 +00:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Consumer>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
Navigation.propTypes = {
|
|
|
|
tReady: PropTypes.bool,
|
|
|
|
isRootFolder: PropTypes.bool,
|
|
|
|
title: PropTypes.string,
|
|
|
|
canCreate: PropTypes.bool,
|
|
|
|
isDesktop: PropTypes.bool,
|
|
|
|
isTabletView: PropTypes.bool,
|
|
|
|
personal: PropTypes.bool,
|
|
|
|
onClickFolder: PropTypes.func,
|
|
|
|
navigationItems: PropTypes.arrayOf(PropTypes.object),
|
|
|
|
getContextOptionsPlus: PropTypes.func,
|
|
|
|
getContextOptionsFolder: PropTypes.func,
|
|
|
|
onBackToParentFolder: PropTypes.func,
|
2022-05-13 16:33:16 +00:00
|
|
|
titles: PropTypes.object,
|
2021-10-15 07:07:15 +00:00
|
|
|
};
|
|
|
|
|
2022-02-18 12:46:49 +00:00
|
|
|
export default React.memo(Navigation);
|