-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of github.com:humoyun/reddix-web into dev
- Loading branch information
Showing
11 changed files
with
127 additions
and
53 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,88 @@ | ||
import { ChakraProvider, CSSReset } from '@chakra-ui/core' | ||
|
||
import theme from '@/theme' | ||
import Theme from '@/theme' | ||
import AppLayout from '@/layouts/AppLayout' | ||
import AuthLayout from '@/layouts/AuthLayout' | ||
import { withUrqlClient } from 'next-urql' | ||
import { createUrqlClient } from '@/utils/createUrqlClient' | ||
import { useRouter } from 'next/router' | ||
|
||
const MyApp = ({ Component, pageProps }) => { | ||
|
||
const router = useRouter() | ||
import UserContext from '@/utils/userContext' | ||
import { useEffect, useState } from 'react' | ||
import { useMeQuery } from '@/generated/graphql' | ||
|
||
|
||
/** | ||
* | ||
* https://reacttricks.com/sharing-global-data-in-next-with-custom-app-and-usecontext-hook | ||
* | ||
* https://reacttricks.com/nested-dynamic-layouts-in-next-apps | ||
* | ||
* https://reacttricks.com/learn-react-by-building-websites-with-next | ||
* | ||
*/ | ||
const ReddixApp = ({ Component, pageProps }) => { | ||
const [{ data, fetching }] = useMeQuery({ | ||
pause: typeof window === 'undefined' || typeof window === undefined | ||
}) | ||
const router = useRouter() | ||
|
||
// emulate net delay for getting user data | ||
// useEffect(() => { | ||
// setTimeout(() => { | ||
// setState({ id: 'some-iuser-id', username: 'Some Username' }) | ||
// }, 200) | ||
// }, []) | ||
|
||
return ( | ||
<ChakraProvider theme={theme}> | ||
{/* <ColorModeProvider> */} | ||
<CSSReset /> | ||
|
||
{router.pathname.startsWith('/auth/') | ||
? | ||
<AuthLayout> | ||
<Component {...pageProps} /> | ||
</AuthLayout> | ||
: | ||
<AppLayout> | ||
<Component {...pageProps} /> | ||
</AppLayout> | ||
} | ||
|
||
|
||
{/* </ColorModeProvider> */} | ||
</ChakraProvider> | ||
<UserContext.Provider | ||
value={{ | ||
user: data, | ||
fetching: fetching | ||
}}> | ||
<ChakraProvider theme={Theme}> | ||
{/* <ColorModeProvider> */} | ||
<CSSReset /> | ||
|
||
{router.pathname.startsWith('/auth/') | ||
? | ||
<AuthLayout> | ||
<Component {...pageProps} /> | ||
</AuthLayout> | ||
: | ||
<AppLayout> | ||
<Component {...pageProps} /> | ||
</AppLayout> | ||
} | ||
{/* </ColorModeProvider> */} | ||
</ChakraProvider> | ||
</UserContext.Provider> | ||
) | ||
} | ||
|
||
export default withUrqlClient(createUrqlClient)(MyApp) | ||
// export default MyApp; | ||
/** | ||
* | ||
* Next.js uses the App component to initialize pages. You can override it and control the page initialization. | ||
* Which allows you to do amazing things like: | ||
- Persisting layout between page changes | ||
- Keeping state when navigating pages | ||
- Custom error handling using componentDidCatch | ||
- Inject additional data into pages | ||
- Add global CSS | ||
* | ||
*/ | ||
|
||
// Only uncomment this method if you have blocking data requirements for | ||
// every single page in your application. This disables the ability to | ||
// perform automatic static optimization, causing every page in your app to | ||
// be server-side rendered. | ||
// | ||
// ReddixApp.getInitialProps = async (appContext) => { | ||
// // calls page's `getInitialProps` and fills `appProps.pageProps` | ||
// const appProps = await App.getInitialProps(appContext); | ||
// | ||
// return { ...appProps } | ||
// } | ||
|
||
|
||
export default withUrqlClient(createUrqlClient)(ReddixApp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { createContext } from 'react' | ||
|
||
// const initUserData = { | ||
// id: null, | ||
// username: '' | ||
// } | ||
|
||
const UserContext = createContext() | ||
|
||
export default UserContext |