impress-2020/src/app/App.js

167 lines
5.1 KiB
JavaScript
Raw Normal View History

2020-04-21 20:32:53 -07:00
import React from "react";
import { ApolloProvider } from "@apollo/client";
import { Auth0Provider } from "@auth0/auth0-react";
2020-12-25 09:20:18 -08:00
import { CSSReset, ChakraProvider, extendTheme } from "@chakra-ui/react";
import { mode } from "@chakra-ui/theme-tools";
2020-09-15 05:35:01 -07:00
import {
BrowserRouter as Router,
Switch,
Route,
useLocation,
} from "react-router-dom";
2020-05-18 00:20:48 -07:00
import loadable from "@loadable/component";
import * as Sentry from "@sentry/react";
import { Integrations } from "@sentry/tracing";
import { useAuth0 } from "@auth0/auth0-react";
2020-04-21 17:49:52 -07:00
import buildApolloClient from "./apolloClient";
2020-09-06 18:12:34 -07:00
import PageLayout from "./PageLayout";
import WardrobePageLayout from "./WardrobePage/WardrobePageLayout";
2020-05-18 00:20:48 -07:00
const HomePage = loadable(() => import("./HomePage"));
2020-09-11 23:56:47 -07:00
const ItemPage = loadable(() => import("./ItemPage"));
const ItemTradesOfferingPage = loadable(() =>
import("./ItemTradesPage").then((m) => m.ItemTradesOfferingPage)
);
const ItemTradesSeekingPage = loadable(() =>
import("./ItemTradesPage").then((m) => m.ItemTradesSeekingPage)
);
const ModelingPage = loadable(() => import("./ModelingPage"));
2020-12-07 22:56:23 -08:00
const PrivacyPolicyPage = loadable(() => import("./PrivacyPolicyPage"));
const UserItemsPage = loadable(() => import("./UserItemsPage"));
const UserOutfitsPage = loadable(() => import("./UserOutfitsPage"));
const WardrobePage = loadable(() => import("./WardrobePage"), {
fallback: <WardrobePageLayout />,
});
2020-12-25 09:20:18 -08:00
const theme = extendTheme({
styles: {
2020-12-25 09:20:18 -08:00
global: (props) => ({
html: {
// HACK: Chakra sets body as the relative position element, which is
// fine, except its `min-height: 100%` doesn't actually work
// unless paired with height on the root element too!
height: "100%",
},
body: {
background: mode("gray.50", "gray.800")(props),
2020-12-25 09:20:18 -08:00
color: mode("green.800", "green.50")(props),
transition: "all 0.25s",
},
}),
},
2020-12-25 09:20:18 -08:00
});
Sentry.init({
dsn:
"https://c55875c3b0904264a1a99e5b741a221e@o506079.ingest.sentry.io/5595379",
autoSessionTracking: true,
integrations: [new Integrations.BrowserTracing()],
// I'm figuring our traffic is low enough that 100% sample rate is fine.
// Let's see if we hit any usage limits!
tracesSampleRate: 1.0,
});
2020-04-25 23:55:39 -07:00
/**
* App is the entry point of our application. There's not a ton of exciting
* stuff happening here, mostly just setting up some globals and theming!
*
* To really dive into the code, try going down into a page component!
*/
2020-04-21 17:49:52 -07:00
function App() {
return (
2020-05-10 00:21:04 -07:00
<Router>
2020-09-15 05:35:01 -07:00
<ScrollToTop />
<Auth0Provider
domain="openneo.us.auth0.com"
clientId="8LjFauVox7shDxVufQqnviUIywMuuC4r"
redirectUri={window.location.origin}
2020-09-02 23:00:16 -07:00
audience="https://impress-2020.openneo.net/api"
scope=""
>
<ApolloProviderWithAuth0>
<ChakraProvider theme={theme}>
<CSSReset />
<Switch>
<Route path="/items/:itemId/trades/offering">
<PageLayout>
<ItemTradesOfferingPage />
</PageLayout>
</Route>
<Route path="/items/:itemId/trades/seeking">
<PageLayout>
<ItemTradesSeekingPage />
</PageLayout>
</Route>
2020-09-11 23:56:47 -07:00
<Route path="/items/:itemId">
<PageLayout>
<ItemPage />
</PageLayout>
</Route>
<Route path="/outfits/new">
<WardrobePage />
</Route>
<Route path="/outfits/:id">
<WardrobePage />
</Route>
<Route path="/user/:userId/items">
2020-09-06 18:12:34 -07:00
<PageLayout>
<UserItemsPage />
2020-09-06 18:12:34 -07:00
</PageLayout>
</Route>
<Route path="/your-outfits">
<PageLayout>
<UserOutfitsPage />
</PageLayout>
</Route>
<Route path="/modeling">
<PageLayout>
<ModelingPage />
2020-12-07 22:56:23 -08:00
</PageLayout>
</Route>
<Route path="/privacy">
<PageLayout>
<PrivacyPolicyPage />
</PageLayout>
</Route>
<Route path="/">
2020-09-06 18:42:39 -07:00
<PageLayout hideHomeLink>
2020-09-06 18:12:34 -07:00
<HomePage />
</PageLayout>
</Route>
</Switch>
</ChakraProvider>
</ApolloProviderWithAuth0>
</Auth0Provider>
2020-05-10 00:21:04 -07:00
</Router>
2020-04-21 17:49:52 -07:00
);
}
2020-09-15 05:35:01 -07:00
/**
* ScrollToTop scrolls to the top of the page when you navigate.
* Copied from https://reactrouter.com/web/guides/scroll-restoration/scroll-to-top.
*/
function ScrollToTop() {
const { pathname } = useLocation();
React.useEffect(() => window.scrollTo(0, 0), [pathname]);
return null;
}
function ApolloProviderWithAuth0({ children }) {
const auth0 = useAuth0();
const auth0Ref = React.useRef(auth0);
React.useEffect(() => {
auth0Ref.current = auth0;
}, [auth0]);
const client = React.useMemo(
() => buildApolloClient(() => auth0Ref.current),
[]
);
return <ApolloProvider client={client}>{children}</ApolloProvider>;
}
2020-04-21 17:49:52 -07:00
export default App;