DocSpace-buildtools/packages/common/components/Article/sub-components/article-header.js

93 lines
2.5 KiB
JavaScript
Raw Normal View History

import React, { useEffect } from "react";
import PropTypes from "prop-types";
import { useHistory, useLocation } from "react-router";
import Loaders from "@docspace/common/components/Loaders";
import { isTablet as isTabletUtils } from "@docspace/components/utils/device";
import { isTablet, isMobileOnly } from "react-device-detect";
import { inject, observer } from "mobx-react";
2022-07-20 11:58:50 +00:00
import { ReactSVG } from "react-svg";
2022-08-29 10:49:15 +00:00
import styled, { css } from "styled-components";
import {
StyledArticleHeader,
StyledHeading,
StyledIconBox,
StyledMenuIcon,
} from "../styled-article";
2022-04-10 15:23:21 +00:00
const ArticleHeader = ({
showText,
children,
onClick,
isLoadedPage,
isLoaded,
tReady,
setIsLoadedArticleHeader,
2022-05-12 12:05:28 +00:00
isBurgerLoading,
2022-04-10 15:23:21 +00:00
...rest
}) => {
2022-04-20 09:45:36 +00:00
const location = useLocation();
const history = useHistory();
2022-04-20 09:45:36 +00:00
const isLoadedSetting = isLoaded;
2022-04-20 09:45:36 +00:00
const commonSettings =
2022-04-20 15:29:29 +00:00
location.pathname.includes("common/customization") ||
location.pathname === "/settings";
useEffect(() => {
if (isLoadedSetting) setIsLoadedArticleHeader(isLoadedSetting);
}, [isLoadedSetting]);
2022-04-10 15:23:21 +00:00
const showLoader = commonSettings ? !isLoadedPage : false;
2022-04-20 09:45:36 +00:00
const isTabletView = (isTabletUtils() || isTablet) && !isMobileOnly;
2022-05-12 12:05:28 +00:00
const onLogoClick = () => {
2022-07-20 11:58:50 +00:00
if (showText && isTabletView) onClick();
else history.push("/");
2022-07-20 11:58:50 +00:00
};
if (isMobileOnly) return <></>;
2022-05-12 12:05:28 +00:00
return (
<StyledArticleHeader showText={showText} {...rest}>
2022-05-12 12:05:28 +00:00
{isTabletView && (isBurgerLoading || showLoader) ? (
2022-08-29 10:49:15 +00:00
<Loaders.ArticleHeader height="28px" width="28px" />
2022-05-12 12:05:28 +00:00
) : (
2022-07-20 11:58:50 +00:00
<StyledIconBox name="article-burger" showText={showText}>
<img src="/static/images/logo.icon.react.svg" onClick={onClick} />
2022-05-12 12:05:28 +00:00
</StyledIconBox>
)}
2022-08-29 10:49:15 +00:00
{!isTabletView && showLoader ? (
2022-08-29 13:15:33 +00:00
<Loaders.ArticleHeader height="24px" width="211px" />
2022-08-29 10:49:15 +00:00
) : (
<StyledHeading showText={showText} size="large">
<img
src="/static/images/logo.docspace.react.svg"
onClick={onLogoClick}
/>
</StyledHeading>
)}
</StyledArticleHeader>
);
};
ArticleHeader.propTypes = {
children: PropTypes.any,
showText: PropTypes.bool,
onClick: PropTypes.func,
};
ArticleHeader.displayName = "Header";
2022-05-12 12:05:28 +00:00
export default inject(({ common, auth }) => {
const { isLoaded, setIsLoadedArticleHeader } = common;
2022-05-12 12:05:28 +00:00
const { settingsStore } = auth;
const { isBurgerLoading } = settingsStore;
return {
isLoaded,
setIsLoadedArticleHeader,
2022-05-12 12:05:28 +00:00
isBurgerLoading,
};
})(observer(ArticleHeader));