2020-06-19 06:57:57 +03:00
|
|
|
import * as React from "react";
|
|
|
|
import * as Constants from "~/common/constants";
|
|
|
|
import * as SVG from "~/common/svg";
|
2020-11-28 07:39:01 +03:00
|
|
|
import * as Events from "~/common/custom-events";
|
2021-05-06 03:08:14 +03:00
|
|
|
import * as Styles from "~/common/styles";
|
2021-09-15 21:38:57 +03:00
|
|
|
import * as Upload from "~/components/core/Upload";
|
2020-04-09 00:29:13 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
import {
|
|
|
|
ApplicationUserControls,
|
|
|
|
ApplicationUserControlsPopup,
|
|
|
|
} from "~/components/core/ApplicationUserControls";
|
2020-09-29 07:39:05 +03:00
|
|
|
|
2021-08-24 19:34:45 +03:00
|
|
|
import { css } from "@emotion/react";
|
2021-07-07 23:50:57 +03:00
|
|
|
import { DarkSymbol } from "~/common/logo";
|
2021-05-06 03:08:14 +03:00
|
|
|
import { Link } from "~/components/core/Link";
|
|
|
|
import { ButtonPrimary, ButtonTertiary } from "~/components/system/components/Buttons";
|
2021-08-24 19:34:45 +03:00
|
|
|
import { Match, Switch } from "~/components/utility/Switch";
|
|
|
|
import { Show } from "~/components/utility/Show";
|
2021-08-24 22:50:32 +03:00
|
|
|
import { useField, useMediaQuery } from "~/common/hooks";
|
2021-08-24 19:34:45 +03:00
|
|
|
import { Input } from "~/components/system";
|
|
|
|
import { AnimatePresence, motion } from "framer-motion";
|
2020-11-14 02:43:59 +03:00
|
|
|
|
2021-08-24 19:34:45 +03:00
|
|
|
const STYLES_SEARCH_COMPONENT = (theme) => css`
|
|
|
|
background-color: transparent;
|
|
|
|
border-radius: 8px;
|
|
|
|
box-shadow: none;
|
|
|
|
height: 100%;
|
|
|
|
input {
|
|
|
|
height: 100%;
|
|
|
|
padding: 0px;
|
|
|
|
}
|
|
|
|
&::placeholder {
|
|
|
|
color: ${theme.semantic.textGray};
|
2021-05-06 03:08:14 +03:00
|
|
|
}
|
2020-12-19 08:25:50 +03:00
|
|
|
`;
|
|
|
|
|
2021-08-24 19:34:45 +03:00
|
|
|
const STYLES_DISMISS_BUTTON = (theme) => css`
|
2021-05-06 03:08:14 +03:00
|
|
|
display: block;
|
2021-08-24 19:34:45 +03:00
|
|
|
${Styles.BUTTON_RESET};
|
|
|
|
color: ${theme.semantic.textGray};
|
2020-04-09 00:29:13 +03:00
|
|
|
`;
|
|
|
|
|
2021-08-24 22:21:07 +03:00
|
|
|
const STYLES_APPLICATION_HEADER_BACKGROUND = (theme) => css`
|
|
|
|
position: absolute;
|
2020-11-14 02:43:59 +03:00
|
|
|
width: 100%;
|
2021-08-24 22:21:07 +03:00
|
|
|
height: 100%;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
z-index: -1;
|
2021-05-27 11:20:34 +03:00
|
|
|
background-color: ${theme.system.white};
|
|
|
|
box-shadow: 0 0 0 1px ${theme.semantic.bgGrayLight};
|
2020-09-25 06:16:10 +03:00
|
|
|
|
2021-09-01 18:41:35 +03:00
|
|
|
@supports ((-webkit-backdrop-filter: blur(75px)) or (backdrop-filter: blur(75px))) {
|
|
|
|
-webkit-backdrop-filter: blur(75px);
|
|
|
|
backdrop-filter: blur(75px);
|
2021-05-06 03:08:14 +03:00
|
|
|
background-color: rgba(255, 255, 255, 0.7);
|
2020-09-25 06:16:10 +03:00
|
|
|
}
|
2021-05-06 03:08:14 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_APPLICATION_HEADER = css`
|
2021-08-24 19:34:45 +03:00
|
|
|
${Styles.HORIZONTAL_CONTAINER_CENTERED};
|
2021-07-07 23:50:57 +03:00
|
|
|
height: ${Constants.sizes.header}px;
|
2021-08-24 19:34:45 +03:00
|
|
|
padding: 0px 24px;
|
2020-08-09 01:04:17 +03:00
|
|
|
|
|
|
|
@media (max-width: ${Constants.sizes.mobile}px) {
|
2021-08-24 19:34:45 +03:00
|
|
|
padding: 0px 16px;
|
2020-09-29 07:39:05 +03:00
|
|
|
width: 100%;
|
2020-08-09 01:04:17 +03:00
|
|
|
}
|
2020-04-09 00:29:13 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_LEFT = css`
|
|
|
|
flex-shrink: 0;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: flex-start;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_MIDDLE = css`
|
2021-08-24 19:34:45 +03:00
|
|
|
flex-grow: 1;
|
|
|
|
height: 100%;
|
|
|
|
padding: 0 12px;
|
2020-09-29 07:39:05 +03:00
|
|
|
`;
|
|
|
|
|
2020-04-09 00:29:13 +03:00
|
|
|
const STYLES_RIGHT = css`
|
2021-05-06 03:08:14 +03:00
|
|
|
flex-shrink: 0;
|
2020-04-09 00:29:13 +03:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: flex-end;
|
|
|
|
`;
|
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
const STYLES_BACKGROUND = css`
|
|
|
|
position: absolute;
|
|
|
|
width: 100vw;
|
|
|
|
height: 100vh;
|
2021-08-24 19:34:45 +03:00
|
|
|
background-color: ${Constants.semantic.bgBlurDark};
|
2021-05-06 03:08:14 +03:00
|
|
|
pointer-events: auto;
|
2020-09-06 04:57:39 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
@keyframes fade-in {
|
|
|
|
from {
|
|
|
|
opacity: 50%;
|
|
|
|
}
|
|
|
|
to {
|
|
|
|
opacity: 100%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
animation: fade-in 200ms ease-out;
|
2020-09-06 04:57:39 +03:00
|
|
|
`;
|
|
|
|
|
2021-07-07 23:50:57 +03:00
|
|
|
const STYLES_UPLOAD_BUTTON = css`
|
2021-08-24 19:34:45 +03:00
|
|
|
${Styles.CONTAINER_CENTERED};
|
2021-07-08 00:44:13 +03:00
|
|
|
background-color: ${Constants.semantic.bgGrayLight};
|
2021-07-07 23:50:57 +03:00
|
|
|
border-radius: 8px;
|
|
|
|
width: 24px;
|
|
|
|
height: 24px;
|
|
|
|
cursor: pointer;
|
|
|
|
pointer-events: auto;
|
|
|
|
`;
|
|
|
|
|
2021-09-15 21:38:57 +03:00
|
|
|
export default function ApplicationHeader({ viewer, page, data, onAction }) {
|
2021-08-24 19:34:45 +03:00
|
|
|
const [state, setState] = React.useState({
|
2021-05-06 03:08:14 +03:00
|
|
|
showDropdown: false,
|
2020-11-19 06:00:59 +03:00
|
|
|
popup: null,
|
2020-09-06 04:57:39 +03:00
|
|
|
isRefreshing: false,
|
2021-08-24 19:34:45 +03:00
|
|
|
});
|
2020-10-29 01:36:38 +03:00
|
|
|
|
2021-08-24 19:34:45 +03:00
|
|
|
const _handleTogglePopup = (value) => {
|
|
|
|
if (!value || state.popup === value) {
|
|
|
|
setState((prev) => ({ ...prev, popup: null }));
|
|
|
|
} else {
|
|
|
|
setState((prev) => ({ ...prev, popup: value, showDropdown: false }));
|
2020-10-29 01:36:38 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-08-24 22:50:32 +03:00
|
|
|
const handleCreateSearch = (searchQuery) => {
|
2021-08-24 19:34:45 +03:00
|
|
|
setState((prev) => ({ ...prev, showDropdown: false }));
|
2020-11-28 07:39:01 +03:00
|
|
|
Events.dispatchCustomEvent({
|
2020-11-10 00:20:38 +03:00
|
|
|
name: "show-search",
|
2021-08-24 22:50:32 +03:00
|
|
|
detail: {
|
|
|
|
initialValue: searchQuery,
|
|
|
|
},
|
2020-09-06 04:57:39 +03:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-08-24 19:34:45 +03:00
|
|
|
const {
|
|
|
|
getFieldProps,
|
2021-08-24 22:50:32 +03:00
|
|
|
value: searchQuery,
|
|
|
|
setFieldValue,
|
|
|
|
} = useField({
|
|
|
|
initialValue: "",
|
2021-08-24 19:34:45 +03:00
|
|
|
onSubmit: handleCreateSearch,
|
|
|
|
});
|
2020-11-19 06:00:59 +03:00
|
|
|
|
2021-08-24 22:50:32 +03:00
|
|
|
const handleDismissSearch = () => setFieldValue("");
|
|
|
|
|
2021-08-24 19:34:45 +03:00
|
|
|
const { mobile } = useMediaQuery();
|
|
|
|
const isSignedOut = !viewer;
|
|
|
|
const isSearching = searchQuery.length !== 0;
|
2020-04-09 00:29:13 +03:00
|
|
|
|
2021-08-24 19:34:45 +03:00
|
|
|
return (
|
2021-08-24 22:21:07 +03:00
|
|
|
<header style={{ position: "relative" }}>
|
2021-08-24 19:34:45 +03:00
|
|
|
<div css={STYLES_APPLICATION_HEADER}>
|
|
|
|
<div css={STYLES_LEFT}>
|
|
|
|
<Show
|
|
|
|
when={viewer}
|
|
|
|
fallback={
|
|
|
|
<Link onAction={onAction} href="/_/data" style={{ pointerEvents: "auto" }}>
|
2021-07-07 23:50:57 +03:00
|
|
|
<DarkSymbol style={{ height: 24, display: "block" }} />
|
|
|
|
</Link>
|
2021-08-24 19:34:45 +03:00
|
|
|
}
|
|
|
|
>
|
|
|
|
<ApplicationUserControls
|
|
|
|
popup={mobile ? false : state.popup}
|
|
|
|
onTogglePopup={_handleTogglePopup}
|
|
|
|
viewer={viewer}
|
|
|
|
onAction={onAction}
|
|
|
|
/>
|
|
|
|
</Show>
|
|
|
|
</div>
|
|
|
|
<div css={STYLES_MIDDLE}>
|
|
|
|
{/**TODO: update Search component */}
|
|
|
|
<Input
|
|
|
|
containerStyle={{ height: "100%" }}
|
|
|
|
full
|
|
|
|
placeholder={`Search ${!viewer ? "slate.host" : ""}`}
|
|
|
|
inputCss={STYLES_SEARCH_COMPONENT}
|
|
|
|
onSubmit={handleCreateSearch}
|
2021-08-24 22:50:32 +03:00
|
|
|
name="search"
|
|
|
|
{...getFieldProps()}
|
2021-08-24 19:34:45 +03:00
|
|
|
/>
|
|
|
|
</div>
|
2021-09-15 21:38:57 +03:00
|
|
|
<Upload.Provider page={page} data={data} viewer={viewer}>
|
|
|
|
<Upload.Root onAction={onAction} viewer={viewer}>
|
|
|
|
<div css={STYLES_RIGHT}>
|
|
|
|
<Actions
|
|
|
|
uploadAction={
|
|
|
|
<Upload.Trigger
|
|
|
|
enableMetrics
|
|
|
|
viewer={viewer}
|
|
|
|
aria-label="Upload"
|
|
|
|
css={STYLES_UPLOAD_BUTTON}
|
|
|
|
>
|
|
|
|
<SVG.Plus height="16px" />
|
|
|
|
</Upload.Trigger>
|
|
|
|
}
|
|
|
|
isSearching={isSearching}
|
|
|
|
isSignedOut={isSignedOut}
|
|
|
|
onAction={onAction}
|
|
|
|
onDismissSearch={handleDismissSearch}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</Upload.Root>
|
|
|
|
</Upload.Provider>
|
2021-08-24 19:34:45 +03:00
|
|
|
</div>
|
|
|
|
<Show when={mobile && state.popup === "profile"}>
|
2021-05-06 03:08:14 +03:00
|
|
|
<ApplicationUserControlsPopup
|
2021-08-24 19:34:45 +03:00
|
|
|
popup={state.popup}
|
|
|
|
onTogglePopup={_handleTogglePopup}
|
|
|
|
viewer={viewer}
|
|
|
|
onAction={onAction}
|
|
|
|
style={{ pointerEvents: "auto" }}
|
2021-05-06 03:08:14 +03:00
|
|
|
/>
|
|
|
|
<div css={STYLES_BACKGROUND} />
|
2021-08-24 19:34:45 +03:00
|
|
|
</Show>
|
2021-08-24 22:21:07 +03:00
|
|
|
{/** NOTE(amine): a fix for a backdrop-filter bug where the filter doesn't take any effects.
|
|
|
|
* It happens when we have two elements using backdrop-filter with a parent-child relationship */}
|
|
|
|
<div css={STYLES_APPLICATION_HEADER_BACKGROUND} />
|
2021-08-24 19:34:45 +03:00
|
|
|
</header>
|
|
|
|
);
|
|
|
|
}
|
2021-05-06 03:08:14 +03:00
|
|
|
|
2021-09-15 21:38:57 +03:00
|
|
|
const Actions = ({ uploadAction, isSignedOut, isSearching, onAction, onDismissSearch }) => {
|
2021-08-24 19:34:45 +03:00
|
|
|
const authActions = React.useMemo(
|
|
|
|
() => (
|
2021-05-06 03:08:14 +03:00
|
|
|
<>
|
2021-08-24 19:34:45 +03:00
|
|
|
<Link href="/_/auth?tab=signin" onAction={onAction} style={{ pointerEvents: "auto" }}>
|
2021-05-06 03:08:14 +03:00
|
|
|
<span css={Styles.MOBILE_HIDDEN}>
|
2021-08-24 19:34:45 +03:00
|
|
|
<ButtonTertiary
|
|
|
|
style={{
|
|
|
|
padding: "0px 12px",
|
|
|
|
minHeight: "30px",
|
|
|
|
fontFamily: Constants.font.text,
|
|
|
|
marginRight: 8,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
Sign in
|
|
|
|
</ButtonTertiary>
|
2020-09-16 23:39:35 +03:00
|
|
|
</span>
|
2021-08-24 19:34:45 +03:00
|
|
|
</Link>
|
|
|
|
<Link href="/_/auth?tab=signup" onAction={onAction} style={{ pointerEvents: "auto" }}>
|
|
|
|
<ButtonPrimary
|
|
|
|
style={{ padding: "0px 12px", minHeight: "30px", fontFamily: Constants.font.text }}
|
|
|
|
>
|
|
|
|
Sign up
|
|
|
|
</ButtonPrimary>
|
|
|
|
</Link>
|
2021-05-06 03:08:14 +03:00
|
|
|
</>
|
2021-08-24 19:34:45 +03:00
|
|
|
),
|
|
|
|
[onAction]
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<AnimatePresence>
|
2021-09-15 21:38:57 +03:00
|
|
|
<Switch fallback={uploadAction}>
|
|
|
|
<Match when={isSignedOut}>
|
|
|
|
<motion.div
|
|
|
|
initial={{ opacity: 0, y: 10 }}
|
|
|
|
animate={{ opacity: 1, y: 0 }}
|
|
|
|
exit={{ y: 10, opacity: 0 }}
|
|
|
|
>
|
|
|
|
{authActions}
|
|
|
|
</motion.div>
|
|
|
|
</Match>
|
2021-08-24 19:34:45 +03:00
|
|
|
<Match when={isSearching}>
|
|
|
|
<motion.div
|
|
|
|
initial={{ opacity: 0, y: -10 }}
|
|
|
|
animate={{ opacity: 1, y: 0 }}
|
|
|
|
exit={{ y: -10, opacity: 0 }}
|
|
|
|
>
|
|
|
|
<button
|
|
|
|
onClick={onDismissSearch}
|
|
|
|
style={{ marginRight: 4 }}
|
|
|
|
css={STYLES_DISMISS_BUTTON}
|
|
|
|
>
|
|
|
|
<SVG.Dismiss style={{ display: "block" }} height={16} width={16} />
|
|
|
|
</button>
|
|
|
|
</motion.div>
|
|
|
|
</Match>
|
|
|
|
</Switch>
|
|
|
|
</AnimatePresence>
|
|
|
|
);
|
|
|
|
};
|