Matchu
b39914976b
Woo, it's looking pretty good, I think!
I didn't bother with pagination yet, since I feel like that'll be a bit of a design and eng lift unto itself... but I figured people would appreciate the ability to look up individual items, even if the rest isn't ready yet 😅
197 lines
6.3 KiB
JavaScript
197 lines
6.3 KiB
JavaScript
import React from "react";
|
|
import { ApolloProvider } from "@apollo/client";
|
|
import { Auth0Provider } from "@auth0/auth0-react";
|
|
import { CSSReset, ChakraProvider, extendTheme } from "@chakra-ui/react";
|
|
import { mode } from "@chakra-ui/theme-tools";
|
|
import {
|
|
BrowserRouter as Router,
|
|
Switch,
|
|
Route,
|
|
useLocation,
|
|
} from "react-router-dom";
|
|
import loadable from "@loadable/component";
|
|
import * as Sentry from "@sentry/react";
|
|
import { Integrations } from "@sentry/tracing";
|
|
import { useAuth0 } from "@auth0/auth0-react";
|
|
|
|
import buildApolloClient from "./apolloClient";
|
|
import PageLayout from "./PageLayout";
|
|
import WardrobePageLayout from "./WardrobePage/WardrobePageLayout";
|
|
|
|
// Loading the page will often fail after a deploy, because Vercel doesn't keep
|
|
// old JS chunks on the CDN. Recover by reloading!
|
|
const tryLoadable = (load, options) =>
|
|
loadable(
|
|
() =>
|
|
load().catch((e) => {
|
|
console.error("Error loading page, reloading", e);
|
|
window.location.reload();
|
|
}),
|
|
options
|
|
);
|
|
|
|
const HomePage = tryLoadable(() => import("./HomePage"));
|
|
const ItemSearchPage = tryLoadable(() => import("./ItemSearchPage"));
|
|
const ItemPage = tryLoadable(() => import("./ItemPage"));
|
|
const ItemTradesOfferingPage = tryLoadable(() =>
|
|
import("./ItemTradesPage").then((m) => m.ItemTradesOfferingPage)
|
|
);
|
|
const ItemTradesSeekingPage = tryLoadable(() =>
|
|
import("./ItemTradesPage").then((m) => m.ItemTradesSeekingPage)
|
|
);
|
|
const ModelingPage = tryLoadable(() => import("./ModelingPage"));
|
|
const PrivacyPolicyPage = tryLoadable(() => import("./PrivacyPolicyPage"));
|
|
const UserItemsPage = tryLoadable(() => import("./UserItemsPage"));
|
|
const UserOutfitsPage = tryLoadable(() => import("./UserOutfitsPage"));
|
|
const WardrobePage = tryLoadable(() => import("./WardrobePage"), {
|
|
fallback: <WardrobePageLayout />,
|
|
});
|
|
|
|
const theme = extendTheme({
|
|
styles: {
|
|
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),
|
|
color: mode("green.800", "green.50")(props),
|
|
transition: "all 0.25s",
|
|
},
|
|
}),
|
|
},
|
|
});
|
|
|
|
Sentry.init({
|
|
dsn:
|
|
"https://c55875c3b0904264a1a99e5b741a221e@o506079.ingest.sentry.io/5595379",
|
|
autoSessionTracking: true,
|
|
integrations: [
|
|
new Integrations.BrowserTracing({
|
|
beforeNavigate: (context) => ({
|
|
...context,
|
|
// Assume any path segment starting with a digit is an ID, and replace
|
|
// it with `:id`. This will help group related routes in Sentry stats.
|
|
// NOTE: I'm a bit uncertain about the timing on this? This seems to
|
|
// work on initial pageload, but I feel like this won't help for
|
|
// describing the page we're navigating _to_... but maybe that's
|
|
// okay in practice? I'm just following the Sentry docs.
|
|
name: window.location.pathname.replaceAll(/\/[0-9][^/]*/g, "/:id"),
|
|
}),
|
|
}),
|
|
],
|
|
|
|
// 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,
|
|
});
|
|
|
|
/**
|
|
* 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!
|
|
*/
|
|
function App() {
|
|
return (
|
|
<Router>
|
|
<ScrollToTop />
|
|
<Auth0Provider
|
|
domain="openneo.us.auth0.com"
|
|
clientId="8LjFauVox7shDxVufQqnviUIywMuuC4r"
|
|
redirectUri={window.location.origin}
|
|
audience="https://impress-2020.openneo.net/api"
|
|
scope=""
|
|
>
|
|
<ApolloProviderWithAuth0>
|
|
<ChakraProvider theme={theme}>
|
|
<CSSReset />
|
|
<Switch>
|
|
<Route path="/items/search/:query?">
|
|
<PageLayout>
|
|
<ItemSearchPage />
|
|
</PageLayout>
|
|
</Route>
|
|
<Route path="/items/:itemId/trades/offering">
|
|
<PageLayout>
|
|
<ItemTradesOfferingPage />
|
|
</PageLayout>
|
|
</Route>
|
|
<Route path="/items/:itemId/trades/seeking">
|
|
<PageLayout>
|
|
<ItemTradesSeekingPage />
|
|
</PageLayout>
|
|
</Route>
|
|
<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">
|
|
<PageLayout>
|
|
<UserItemsPage />
|
|
</PageLayout>
|
|
</Route>
|
|
<Route path="/your-outfits">
|
|
<PageLayout>
|
|
<UserOutfitsPage />
|
|
</PageLayout>
|
|
</Route>
|
|
<Route path="/modeling">
|
|
<PageLayout>
|
|
<ModelingPage />
|
|
</PageLayout>
|
|
</Route>
|
|
<Route path="/privacy">
|
|
<PageLayout>
|
|
<PrivacyPolicyPage />
|
|
</PageLayout>
|
|
</Route>
|
|
<Route path="/">
|
|
<PageLayout hideHomeLink>
|
|
<HomePage />
|
|
</PageLayout>
|
|
</Route>
|
|
</Switch>
|
|
</ChakraProvider>
|
|
</ApolloProviderWithAuth0>
|
|
</Auth0Provider>
|
|
</Router>
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 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>;
|
|
}
|
|
|
|
export default App;
|