From 9b3344cad296b3905ef20bc5309d39538f3d33d9 Mon Sep 17 00:00:00 2001 From: checktheroads Date: Sun, 19 Jan 2020 22:06:16 -0700 Subject: [PATCH] add custom error & loading pages --- ui/pages/_app.js | 26 ++++++++++++ ui/pages/_error.js | 98 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 ui/pages/_app.js create mode 100644 ui/pages/_error.js diff --git a/ui/pages/_app.js b/ui/pages/_app.js new file mode 100644 index 0000000..7364ed3 --- /dev/null +++ b/ui/pages/_app.js @@ -0,0 +1,26 @@ +import React from "react"; +import useAxios from "axios-hooks"; +import { HyperglassProvider } from "~/components/HyperglassProvider"; +import PreConfig from "~/components/PreConfig"; + +const Hyperglass = ({ Component, pageProps }) => { + const [{ data, loading, error }, refetch] = useAxios({ + url: "/config", + method: "get" + }); + return ( + <> + {!data ? ( + + ) : ( + + + + )} + + ); +}; + +Hyperglass.displayName = "Hyperglass"; + +export default Hyperglass; diff --git a/ui/pages/_error.js b/ui/pages/_error.js new file mode 100644 index 0000000..0906075 --- /dev/null +++ b/ui/pages/_error.js @@ -0,0 +1,98 @@ +import React from "react"; +import dynamic from "next/dynamic"; +import { useRouter } from "next/router"; +import { + Button, + CSSReset, + Flex, + Heading, + Text, + ThemeProvider, + useColorMode +} from "@chakra-ui/core"; +import { inRange } from "lodash"; +import { defaultTheme } from "~/theme"; + +const ColorModeProvider = dynamic( + () => import("@chakra-ui/core").then(mod => mod.ColorModeProvider), + { ssr: false } +); + +const ErrorContent = ({ msg, statusCode }) => { + const { colorMode } = useColorMode(); + const bg = { light: "white", dark: "black" }; + const baseCode = inRange(statusCode, 400, 500) + ? 400 + : inRange(statusCode, 500, 600) + ? 500 + : 400; + const errorColor = { + 400: { light: "error.500", dark: "error.300" }, + 500: { light: "danger.500", dark: "danger.300" } + }; + const variantColor = { + 400: "error", + 500: "danger" + }; + const color = { light: "black", dark: "white" }; + const { push } = useRouter(); + const handleClick = () => push("/"); + return ( + + + + + {msg} + + {statusCode === 404 && isn't a thing...} + + + + + + ); +}; + +const ErrorPage = ({ msg, statusCode }) => { + return ( + + + + + + + ); +}; + +ErrorPage.getInitialProps = ({ res, err }) => { + const statusCode = res ? res.statusCode : err ? err.statusCode : 404; + const msg = err ? err.message : res.req.url; + return { msg, statusCode }; +}; + +export default ErrorPage;