2020-04-21 20:32:53 -07:00
|
|
|
import React from "react";
|
2020-07-31 23:10:34 -07:00
|
|
|
import { ApolloProvider } from "@apollo/client";
|
2020-09-02 03:06:09 -07:00
|
|
|
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";
|
2021-01-16 10:59:54 -08:00
|
|
|
import * as Sentry from "@sentry/react";
|
|
|
|
import { Integrations } from "@sentry/tracing";
|
2020-09-04 05:59:35 -07:00
|
|
|
import { useAuth0 } from "@auth0/auth0-react";
|
2020-04-21 17:49:52 -07:00
|
|
|
|
2020-09-04 05:59:35 -07:00
|
|
|
import buildApolloClient from "./apolloClient";
|
2020-09-06 18:12:34 -07:00
|
|
|
import PageLayout from "./PageLayout";
|
2020-09-10 02:54:22 -07:00
|
|
|
import WardrobePageLayout from "./WardrobePage/WardrobePageLayout";
|
2020-05-18 00:20:48 -07:00
|
|
|
|
Fix ChunkLoadError crashes after deploys
Our host, Vercel, doesn't keep old build files on its CDN after a deploy for very long. This means that, after a deploy that changes a page's bundle, existing sessions that attempt to navigate to it for the first time will fail on the dynamic `import`, because the filename hash has changed.
The best fix I'm aware of for this is to just, reload the page when this happens!
To test this, I did the following:
1. Use `yarn build` to build a prod copy of the site.
2. Use `serve -s build` to start serving it on its own port. (API endpoints won't work, and that's okay!)
3. Don't touch the open copy of the site yet.
4. Make a change to `PrivacyPolicyPage.js`, and `yarn build` again. This simulates a deploy under similar circumstances.
5. Open the Console, tick the "Persist Logs" option, and try to navigate to Privacy Policy. Observe that it logs a ChunkLoadError in the console, and smoothly reloads the page to show you the updated Privacy Policy page.
6. Undo your change 😅
2021-01-18 05:17:14 -08:00
|
|
|
// Loading the page will often fail after a deploy, because Vercel doesn't keep
|
|
|
|
// old JS chunks on the CDN. Recover by reloading!
|
2021-01-18 15:56:24 -08:00
|
|
|
const tryLoadable = (load, options) =>
|
|
|
|
loadable(
|
|
|
|
() =>
|
|
|
|
load().catch((e) => {
|
|
|
|
console.error("Error loading page, reloading", e);
|
|
|
|
window.location.reload();
|
|
|
|
}),
|
|
|
|
options
|
Fix ChunkLoadError crashes after deploys
Our host, Vercel, doesn't keep old build files on its CDN after a deploy for very long. This means that, after a deploy that changes a page's bundle, existing sessions that attempt to navigate to it for the first time will fail on the dynamic `import`, because the filename hash has changed.
The best fix I'm aware of for this is to just, reload the page when this happens!
To test this, I did the following:
1. Use `yarn build` to build a prod copy of the site.
2. Use `serve -s build` to start serving it on its own port. (API endpoints won't work, and that's okay!)
3. Don't touch the open copy of the site yet.
4. Make a change to `PrivacyPolicyPage.js`, and `yarn build` again. This simulates a deploy under similar circumstances.
5. Open the Console, tick the "Persist Logs" option, and try to navigate to Privacy Policy. Observe that it logs a ChunkLoadError in the console, and smoothly reloads the page to show you the updated Privacy Policy page.
6. Undo your change 😅
2021-01-18 05:17:14 -08:00
|
|
|
);
|
|
|
|
|
|
|
|
const HomePage = tryLoadable(() => import("./HomePage"));
|
2021-01-18 15:56:24 -08:00
|
|
|
const ItemSearchPage = tryLoadable(() => import("./ItemSearchPage"));
|
Fix ChunkLoadError crashes after deploys
Our host, Vercel, doesn't keep old build files on its CDN after a deploy for very long. This means that, after a deploy that changes a page's bundle, existing sessions that attempt to navigate to it for the first time will fail on the dynamic `import`, because the filename hash has changed.
The best fix I'm aware of for this is to just, reload the page when this happens!
To test this, I did the following:
1. Use `yarn build` to build a prod copy of the site.
2. Use `serve -s build` to start serving it on its own port. (API endpoints won't work, and that's okay!)
3. Don't touch the open copy of the site yet.
4. Make a change to `PrivacyPolicyPage.js`, and `yarn build` again. This simulates a deploy under similar circumstances.
5. Open the Console, tick the "Persist Logs" option, and try to navigate to Privacy Policy. Observe that it logs a ChunkLoadError in the console, and smoothly reloads the page to show you the updated Privacy Policy page.
6. Undo your change 😅
2021-01-18 05:17:14 -08:00
|
|
|
const ItemPage = tryLoadable(() => import("./ItemPage"));
|
|
|
|
const ItemTradesOfferingPage = tryLoadable(() =>
|
2020-11-23 11:25:23 -08:00
|
|
|
import("./ItemTradesPage").then((m) => m.ItemTradesOfferingPage)
|
|
|
|
);
|
Fix ChunkLoadError crashes after deploys
Our host, Vercel, doesn't keep old build files on its CDN after a deploy for very long. This means that, after a deploy that changes a page's bundle, existing sessions that attempt to navigate to it for the first time will fail on the dynamic `import`, because the filename hash has changed.
The best fix I'm aware of for this is to just, reload the page when this happens!
To test this, I did the following:
1. Use `yarn build` to build a prod copy of the site.
2. Use `serve -s build` to start serving it on its own port. (API endpoints won't work, and that's okay!)
3. Don't touch the open copy of the site yet.
4. Make a change to `PrivacyPolicyPage.js`, and `yarn build` again. This simulates a deploy under similar circumstances.
5. Open the Console, tick the "Persist Logs" option, and try to navigate to Privacy Policy. Observe that it logs a ChunkLoadError in the console, and smoothly reloads the page to show you the updated Privacy Policy page.
6. Undo your change 😅
2021-01-18 05:17:14 -08:00
|
|
|
const ItemTradesSeekingPage = tryLoadable(() =>
|
2020-11-23 11:25:23 -08:00
|
|
|
import("./ItemTradesPage").then((m) => m.ItemTradesSeekingPage)
|
|
|
|
);
|
Fix ChunkLoadError crashes after deploys
Our host, Vercel, doesn't keep old build files on its CDN after a deploy for very long. This means that, after a deploy that changes a page's bundle, existing sessions that attempt to navigate to it for the first time will fail on the dynamic `import`, because the filename hash has changed.
The best fix I'm aware of for this is to just, reload the page when this happens!
To test this, I did the following:
1. Use `yarn build` to build a prod copy of the site.
2. Use `serve -s build` to start serving it on its own port. (API endpoints won't work, and that's okay!)
3. Don't touch the open copy of the site yet.
4. Make a change to `PrivacyPolicyPage.js`, and `yarn build` again. This simulates a deploy under similar circumstances.
5. Open the Console, tick the "Persist Logs" option, and try to navigate to Privacy Policy. Observe that it logs a ChunkLoadError in the console, and smoothly reloads the page to show you the updated Privacy Policy page.
6. Undo your change 😅
2021-01-18 05:17:14 -08:00
|
|
|
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"), {
|
2020-09-10 02:54:22 -07:00
|
|
|
fallback: <WardrobePageLayout />,
|
|
|
|
});
|
2020-04-22 14:02:23 -07:00
|
|
|
|
2020-12-25 09:20:18 -08:00
|
|
|
const theme = extendTheme({
|
2020-08-12 00:37:31 -07:00
|
|
|
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: {
|
2021-01-04 01:17:30 -08:00
|
|
|
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-08-12 00:37:31 -07:00
|
|
|
},
|
2020-12-25 09:20:18 -08:00
|
|
|
});
|
2020-08-12 00:37:31 -07:00
|
|
|
|
2021-01-16 10:59:54 -08:00
|
|
|
Sentry.init({
|
|
|
|
dsn:
|
|
|
|
"https://c55875c3b0904264a1a99e5b741a221e@o506079.ingest.sentry.io/5595379",
|
|
|
|
autoSessionTracking: true,
|
2021-01-17 08:48:22 -08:00
|
|
|
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.
|
2021-01-18 16:31:02 -08:00
|
|
|
// NOTE: I'm a bit uncertain about the timing on this for tracking
|
|
|
|
// client-side navs... but we now only track first-time
|
|
|
|
// pageloads, and it definitely works correctly for them!
|
2021-01-17 08:48:22 -08:00
|
|
|
name: window.location.pathname.replaceAll(/\/[0-9][^/]*/g, "/:id"),
|
|
|
|
}),
|
2021-01-18 16:31:02 -08:00
|
|
|
|
|
|
|
// We have a _lot_ of location changes that don't actually signify useful
|
|
|
|
// navigations, like in the wardrobe page. It could be useful to trace
|
|
|
|
// them with better filtering someday, but frankly we don't use the perf
|
|
|
|
// features besides Web Vitals right now, and those only get tracked on
|
|
|
|
// first-time pageloads, anyway. So, don't track client-side navs!
|
|
|
|
startTransactionOnLocationChange: false,
|
2021-01-17 08:48:22 -08:00
|
|
|
}),
|
|
|
|
],
|
2021-01-16 10:59:54 -08:00
|
|
|
|
2021-01-18 16:31:02 -08:00
|
|
|
// Since we're only tracking first-page loads and not navigations, 100%
|
|
|
|
// sampling isn't actually so much! Tune down if it becomes a problem, tho.
|
2021-01-16 10:59:54 -08:00
|
|
|
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 />
|
2020-09-02 03:06:09 -07:00
|
|
|
<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=""
|
2020-09-02 03:06:09 -07:00
|
|
|
>
|
2020-09-04 05:59:35 -07:00
|
|
|
<ApolloProviderWithAuth0>
|
2020-09-02 03:06:09 -07:00
|
|
|
<ChakraProvider theme={theme}>
|
|
|
|
<CSSReset />
|
|
|
|
<Switch>
|
2021-01-18 15:56:24 -08:00
|
|
|
<Route path="/items/search/:query?">
|
|
|
|
<PageLayout>
|
|
|
|
<ItemSearchPage />
|
|
|
|
</PageLayout>
|
|
|
|
</Route>
|
2020-11-23 11:25:23 -08:00
|
|
|
<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>
|
2020-09-02 03:06:09 -07:00
|
|
|
<Route path="/outfits/new">
|
|
|
|
<WardrobePage />
|
|
|
|
</Route>
|
2021-01-04 22:29:39 -08:00
|
|
|
<Route path="/outfits/:id">
|
|
|
|
<WardrobePage />
|
|
|
|
</Route>
|
2020-09-04 05:59:35 -07:00
|
|
|
<Route path="/user/:userId/items">
|
2020-09-06 18:12:34 -07:00
|
|
|
<PageLayout>
|
2020-09-11 23:20:06 -07:00
|
|
|
<UserItemsPage />
|
2020-09-06 18:12:34 -07:00
|
|
|
</PageLayout>
|
2020-09-04 05:59:35 -07:00
|
|
|
</Route>
|
2021-01-03 23:31:02 -08:00
|
|
|
<Route path="/your-outfits">
|
|
|
|
<PageLayout>
|
|
|
|
<UserOutfitsPage />
|
|
|
|
</PageLayout>
|
|
|
|
</Route>
|
2020-09-06 23:32:04 -07:00
|
|
|
<Route path="/modeling">
|
|
|
|
<PageLayout>
|
|
|
|
<ModelingPage />
|
2020-12-07 22:56:23 -08:00
|
|
|
</PageLayout>
|
|
|
|
</Route>
|
|
|
|
<Route path="/privacy">
|
|
|
|
<PageLayout>
|
|
|
|
<PrivacyPolicyPage />
|
2020-09-06 23:32:04 -07:00
|
|
|
</PageLayout>
|
|
|
|
</Route>
|
2020-09-02 03:06:09 -07:00
|
|
|
<Route path="/">
|
2020-09-06 18:42:39 -07:00
|
|
|
<PageLayout hideHomeLink>
|
2020-09-06 18:12:34 -07:00
|
|
|
<HomePage />
|
|
|
|
</PageLayout>
|
2020-09-02 03:06:09 -07:00
|
|
|
</Route>
|
|
|
|
</Switch>
|
|
|
|
</ChakraProvider>
|
2020-09-04 05:59:35 -07:00
|
|
|
</ApolloProviderWithAuth0>
|
2020-09-02 03:06:09 -07:00
|
|
|
</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;
|
|
|
|
}
|
|
|
|
|
2020-09-04 05:59:35 -07:00
|
|
|
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;
|