mirror of
https://gitlab.com/MrFry/qmining-page
synced 2026-04-28 11:17:37 +02:00
85 lines
2.0 KiB
JavaScript
85 lines
2.0 KiB
JavaScript
// import App from 'next/app'
|
|
|
|
import React, { useState, useEffect } from 'react'
|
|
|
|
import Layout from '../components/layout'
|
|
|
|
import '../defaultStyles.css'
|
|
import constants from '../constants.json'
|
|
|
|
function MyApp({ Component, pageProps, router }) {
|
|
const [userId, setUserId] = useState()
|
|
const [motd, setMotd] = useState()
|
|
const [userSpecificMotd, setUserSpecificMotd] = useState()
|
|
|
|
const getGlobalProps = () => {
|
|
fetch(`${constants.apiUrl}infos?motd=true`, {
|
|
credentials: 'include',
|
|
Accept: 'application/json',
|
|
'Content-Type': 'application/json',
|
|
})
|
|
.then((resp) => {
|
|
return resp.json()
|
|
})
|
|
.then((data) => {
|
|
setUserId(data.uid)
|
|
setMotd(data.motd)
|
|
setUserSpecificMotd(data.userSpecificMotd)
|
|
})
|
|
}
|
|
|
|
useEffect(() => {
|
|
getGlobalProps()
|
|
}, [])
|
|
|
|
const globalData = {
|
|
userId,
|
|
motd,
|
|
userSpecificMotd,
|
|
}
|
|
|
|
return (
|
|
<Layout
|
|
route={router.route}
|
|
globalData={globalData}
|
|
refetchGlobalData={getGlobalProps}
|
|
>
|
|
<Component
|
|
{...pageProps}
|
|
router={router}
|
|
globalData={globalData}
|
|
refetchGlobalData={getGlobalProps}
|
|
/>
|
|
</Layout>
|
|
)
|
|
}
|
|
|
|
// MyApp.getStaticProps = () => {
|
|
// console.log('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
|
|
// const res = await fetch('https://stuff.frylabs.net/asd.json', {
|
|
// credentials: 'include',
|
|
// })
|
|
// const resp = await res.json()
|
|
// console.log('aaaaaaaaaaaaa', resp)
|
|
// return {
|
|
// props: {
|
|
// msg: 'aaaaa',
|
|
// fetched: resp,
|
|
// },
|
|
// }
|
|
// }
|
|
|
|
// 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.
|
|
//
|
|
// MyApp.getInitialProps = async (appContext) => {
|
|
// // calls page's `getInitialProps` and fills `appProps.pageProps`
|
|
// const appProps = await App.getInitialProps(appContext);
|
|
//
|
|
// return { ...appProps }
|
|
// }
|
|
|
|
export default MyApp
|