diff options
Diffstat (limited to 'frontend/pages')
| -rw-r--r-- | frontend/pages/_app.js | 14 | ||||
| -rw-r--r-- | frontend/pages/index.js | 4 | ||||
| -rw-r--r-- | frontend/pages/item.js | 3 |
3 files changed, 10 insertions, 11 deletions
diff --git a/frontend/pages/_app.js b/frontend/pages/_app.js index 27202d5..b23df9b 100644 --- a/frontend/pages/_app.js +++ b/frontend/pages/_app.js @@ -1,13 +1,19 @@ -import App, { Container } from 'next/app'; -import React from 'react'; import { ApolloApp } from 'next-with-apollo'; import withData from '../lib/withData'; +import { CURRENT_USER_QUERY } from '../queries/queries'; // Next.js wraps each Page in an <App></App> component. This is handy for when you want to persist anything from page to page, or just access a component that is 1 level higher than each page. -// This code is taken right from the Next.js docs, and then we add the Router to the page props, which is why we need a custom _app.js +// normall here you import App from next/app, but we use next-with-apollo's ApolloApp here so we can get SSR class MyApp extends ApolloApp { + componentDidMount() { + if (typeof window !== 'undefined' && !window.__CLIENTLOADED__) { + console.log('Refetching current user'); + this.props.apollo.query({ query: CURRENT_USER_QUERY, fetchPolicy: 'network-only' }); + window.__CLIENTLOADED__ = true; + } + } static async getInitialProps({ Component, ctx }) { let pageProps = {}; @@ -15,7 +21,7 @@ class MyApp extends ApolloApp { pageProps = await Component.getInitialProps(ctx); } - pageProps.query = ctx.query + pageProps.query = ctx.query; return { pageProps }; } diff --git a/frontend/pages/index.js b/frontend/pages/index.js index 920ec9b..1dca5e1 100644 --- a/frontend/pages/index.js +++ b/frontend/pages/index.js @@ -4,10 +4,6 @@ import Items from '../components/Items'; import Page from '../components/Page'; class Home extends React.Component { - static async getInitialProps({ query }) { - return { query }; - } - render() { const page = parseInt(this.props.query.page) || 1; console.log(this.props); diff --git a/frontend/pages/item.js b/frontend/pages/item.js index 962634e..88ffc1d 100644 --- a/frontend/pages/item.js +++ b/frontend/pages/item.js @@ -3,9 +3,6 @@ import Page from '../components/Page'; import SingleItem from '../components/SingleItem'; class ItemPage extends React.Component { - static async getInitialProps({ query }) { - return { query }; - } render() { return ( <Page> |
