21e613891e
Includes changes due to NextJS version bump and attempts at storing theme via cookie
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import '/styles/globals.css'
|
|
import type { ReactElement, ReactNode } from 'react'
|
|
import Layout from '../components/layout'
|
|
import type { NextPage } from 'next'
|
|
import { AppProps } from 'next/app';
|
|
import { DefaultTheme, ThemeProvider } from 'styled-components';
|
|
import { createContext, useContext, useEffect, useState } from 'react'
|
|
import { getCookie, getCookies, setCookie } from 'cookies-next'
|
|
import { darkTheme } from '../components/themes';
|
|
|
|
export type NextPageWithLayout<P = {}, IP = P> = NextPage<P, IP> & {
|
|
getLayout?: (page: ReactElement) => ReactNode
|
|
}
|
|
|
|
export type AppPropsWithLayout = AppProps & {
|
|
Component: NextPageWithLayout
|
|
}
|
|
|
|
|
|
const ThemeUpdateContext = createContext(
|
|
(theme: DefaultTheme) => console.error("attempted to set theme outside of a ThemeUpdateContext.Provider")
|
|
)
|
|
|
|
export const useUpdateTheme = () => useContext(ThemeUpdateContext);
|
|
|
|
|
|
export default function Website({ Component, pageProps }: AppPropsWithLayout) {
|
|
const [selectedTheme, setselectedTheme] = useState(darkTheme);
|
|
//console.log("Selected Theme: ", selectedTheme); // DEBUG
|
|
|
|
useEffect(() => {
|
|
setCookie('theme', selectedTheme.themeId);
|
|
}, [selectedTheme])
|
|
|
|
|
|
// Use the layout defined at the page level, if available
|
|
const getLayout = Component.getLayout ?? ((page) => (
|
|
<Layout>{page}</Layout>))
|
|
|
|
return (
|
|
<ThemeProvider theme={selectedTheme}>
|
|
<ThemeUpdateContext.Provider value={setselectedTheme}>
|
|
{getLayout(<Component {...pageProps} />)}
|
|
</ThemeUpdateContext.Provider>
|
|
</ThemeProvider>
|
|
)
|
|
}
|
|
|
|
export async function getServerSideProps() {
|
|
|
|
return {
|
|
props: {
|
|
token: {},
|
|
}
|
|
}
|
|
}
|