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

90 lines
2.5 KiB
JavaScript

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 Link from "@docspace/components/link";
import { isTablet, isMobileOnly } from "react-device-detect";
import { inject, observer } from "mobx-react";
import {
StyledArticleHeader,
StyledHeading,
StyledIconBox,
} from "../styled-article";
const ArticleHeader = ({
showText,
children,
onClick,
isLoadedPage,
isLoaded,
tReady,
setIsLoadedArticleHeader,
isBurgerLoading,
...rest
}) => {
const location = useLocation();
const history = useHistory();
const isLoadedSetting = isLoaded;
const commonSettings =
location.pathname.includes("common/customization") ||
location.pathname === "/settings";
useEffect(() => {
if (isLoadedSetting) setIsLoadedArticleHeader(isLoadedSetting);
}, [isLoadedSetting]);
const showLoader = commonSettings ? !isLoadedPage : false;
const isTabletView = (isTabletUtils() || isTablet) && !isMobileOnly;
const onLogoClick = () => {
if (showText && isTabletView) onClick();
else history.push("/");
};
if (isMobileOnly) return <></>;
return (
<StyledArticleHeader showText={showText} {...rest}>
{isTabletView && (isBurgerLoading || showLoader) ? (
<Loaders.ArticleHeader height="28px" width="28px" />
) : (
<StyledIconBox name="article-burger" showText={showText}>
<img src="/static/images/logo.icon.react.svg" onClick={onClick} />
</StyledIconBox>
)}
{!isTabletView && showLoader ? (
<Loaders.ArticleHeader height="24px" width="211px" />
) : (
<StyledHeading showText={showText} size="large">
<Link href={showText ? "/" : null} onClick={onLogoClick}>
<img src="/static/images/logo.docspace.react.svg" />
</Link>
</StyledHeading>
)}
</StyledArticleHeader>
);
};
ArticleHeader.propTypes = {
children: PropTypes.any,
showText: PropTypes.bool,
onClick: PropTypes.func,
};
ArticleHeader.displayName = "Header";
export default inject(({ common, auth }) => {
const { isLoaded, setIsLoadedArticleHeader } = common;
const { settingsStore } = auth;
const { isBurgerLoading } = settingsStore;
return {
isLoaded,
setIsLoadedArticleHeader,
isBurgerLoading,
};
})(observer(ArticleHeader));