1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00

102 lines
3.9 KiB
JavaScript
Raw Normal View History

2020-01-20 00:37:04 -07:00
import React, { useRef, useState } from "react";
import { Flex, useColorMode } from "@chakra-ui/core";
2020-01-17 02:50:57 -07:00
import { motion, AnimatePresence } from "framer-motion";
import HyperglassForm from "~/components/HyperglassForm";
import Results from "~/components/Results";
import Header from "~/components/Header";
import Footer from "~/components/Footer";
import Meta from "~/components/Meta";
2020-01-20 00:37:04 -07:00
import useConfig from "~/components/HyperglassProvider";
import Debugger from "~/components/Debugger";
2020-01-17 02:50:57 -07:00
const AnimatedForm = motion.custom(HyperglassForm);
2020-01-20 00:37:04 -07:00
const bg = { light: "white", dark: "black" };
const color = { light: "black", dark: "white" };
const headerHeightDefault = { true: [16, 16, 16, 16], false: [24, 64, 64, 64] };
const headerHeightAll = { true: [32, 32, 32, 32], false: [48, "20rem", "20rem", "20rem"] };
const Layout = () => {
const config = useConfig();
2020-01-17 02:50:57 -07:00
const { colorMode } = useColorMode();
const [isSubmitting, setSubmitting] = useState(false);
const [formData, setFormData] = useState({});
2020-01-20 00:37:04 -07:00
const containerRef = useRef(null);
2020-01-17 02:50:57 -07:00
const handleFormReset = () => {
2020-01-20 00:37:04 -07:00
containerRef.current.scrollIntoView({ behavior: "smooth", block: "start" });
2020-01-17 02:50:57 -07:00
setSubmitting(false);
};
2020-01-20 00:37:04 -07:00
const headerHeight =
config.branding.text.title_mode === "all"
? headerHeightAll[isSubmitting]
: headerHeightDefault[isSubmitting];
2020-01-17 02:50:57 -07:00
return (
<>
2020-01-20 00:37:04 -07:00
<Meta />
2020-01-17 02:50:57 -07:00
<Flex
w="100%"
2020-01-20 00:37:04 -07:00
ref={containerRef}
minHeight="100vh"
2020-01-17 02:50:57 -07:00
bg={bg[colorMode]}
2020-01-20 00:37:04 -07:00
flexDirection="column"
2020-01-17 02:50:57 -07:00
color={color[colorMode]}
>
2020-01-20 00:37:04 -07:00
<Flex px={2} flex="1 1 auto" flexGrow={0} flexDirection="column">
<Header
isSubmitting={isSubmitting}
handleFormReset={handleFormReset}
height={headerHeight}
/>
</Flex>
2020-01-17 02:50:57 -07:00
<Flex
2020-01-20 00:37:04 -07:00
px={2}
py={0}
2020-01-17 02:50:57 -07:00
w="100%"
2020-01-20 00:37:04 -07:00
as="main"
mt={headerHeight}
flex="1 1 auto"
textAlign="center"
2020-01-17 02:50:57 -07:00
alignItems="center"
justifyContent="start"
flexDirection="column"
>
{isSubmitting && formData && (
<Results
queryLocation={formData.query_location}
queryType={formData.query_type}
queryVrf={formData.query_vrf}
queryTarget={formData.query_target}
setSubmitting={setSubmitting}
/>
)}
<AnimatePresence>
{!isSubmitting && (
<AnimatedForm
initial={{ opacity: 0, y: 300 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.3 }}
exit={{ opacity: 0, x: -300 }}
isSubmitting={isSubmitting}
setSubmitting={setSubmitting}
setFormData={setFormData}
/>
)}
</AnimatePresence>
</Flex>
<Footer
general={config.general}
content={config.content}
terms={config.branding.terms}
help={config.branding.help_menu}
credit={config.branding.credit}
extLink={config.branding.external_link}
/>
2020-01-26 02:21:12 -07:00
{config.general.developer_mode && <Debugger />}
2020-01-17 02:50:57 -07:00
</Flex>
</>
);
};
2020-01-20 00:37:04 -07:00
Layout.displayName = "HyperglassLayout";
export default Layout;