2022-03-06 19:46:59 -05:00
|
|
|
import '../styles/globals.css'
|
2022-03-09 20:47:54 -05:00
|
|
|
import { GeistProvider, CssBaseline, useTheme } from '@geist-ui/core'
|
|
|
|
import { useEffect, useMemo, useState } from 'react'
|
2022-03-06 19:46:59 -05:00
|
|
|
import type { AppProps as NextAppProps } from "next/app";
|
2022-03-09 17:57:44 -05:00
|
|
|
import useSharedState from '../lib/hooks/use-shared-state';
|
2022-03-06 19:46:59 -05:00
|
|
|
|
2022-03-09 20:11:37 -05:00
|
|
|
import 'react-loading-skeleton/dist/skeleton.css'
|
2022-03-09 20:47:54 -05:00
|
|
|
import { SkeletonTheme } from 'react-loading-skeleton';
|
|
|
|
import Head from 'next/head';
|
2022-03-09 20:11:37 -05:00
|
|
|
|
2022-03-06 19:46:59 -05:00
|
|
|
export type ThemeProps = {
|
|
|
|
theme: "light" | "dark" | string,
|
|
|
|
changeTheme: () => void
|
|
|
|
}
|
|
|
|
|
|
|
|
type AppProps<P = any> = {
|
|
|
|
pageProps: P;
|
|
|
|
} & Omit<NextAppProps<P>, "pageProps">;
|
|
|
|
|
|
|
|
export type DriftProps = ThemeProps
|
|
|
|
|
|
|
|
function MyApp({ Component, pageProps }: AppProps<ThemeProps>) {
|
2022-03-09 17:57:44 -05:00
|
|
|
const [themeType, setThemeType] = useSharedState<string>('theme', 'light')
|
2022-03-09 20:47:54 -05:00
|
|
|
const theme = useTheme();
|
2022-03-09 05:06:03 -05:00
|
|
|
useEffect(() => {
|
|
|
|
if (typeof window === 'undefined' || !window.localStorage) return
|
|
|
|
const storedTheme = window.localStorage.getItem('drift-theme')
|
|
|
|
if (storedTheme) setThemeType(storedTheme)
|
2022-03-09 17:57:44 -05:00
|
|
|
// TODO: useReducer?
|
|
|
|
}, [setThemeType, themeType])
|
2022-03-07 19:42:47 -05:00
|
|
|
|
2022-03-06 19:46:59 -05:00
|
|
|
const changeTheme = () => {
|
|
|
|
const newTheme = themeType === 'dark' ? 'light' : 'dark'
|
|
|
|
localStorage.setItem('drift-theme', newTheme)
|
2022-03-07 19:42:47 -05:00
|
|
|
setThemeType(last => (last === 'dark' ? 'light' : 'dark'))
|
2022-03-06 19:46:59 -05:00
|
|
|
}
|
|
|
|
|
2022-03-09 20:47:54 -05:00
|
|
|
const skeletonBaseColor = useMemo(() => {
|
|
|
|
if (themeType === 'dark') return '#333'
|
|
|
|
return '#eee'
|
|
|
|
}, [themeType])
|
|
|
|
const skeletonHighlightColor = useMemo(() => {
|
|
|
|
if (themeType === 'dark') return '#555'
|
|
|
|
return '#ddd'
|
|
|
|
}, [themeType])
|
|
|
|
|
2022-03-06 19:46:59 -05:00
|
|
|
return (
|
2022-03-09 20:47:54 -05:00
|
|
|
<>
|
|
|
|
<Head>
|
|
|
|
<meta charSet="utf-8" />
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
|
2022-03-12 18:51:31 -05:00
|
|
|
<link rel="apple-touch-icon" sizes="180x180" href="/assets/apple-touch-icon.png" />
|
|
|
|
<link rel="icon" type="image/png" sizes="32x32" href="/assets/favicon-32x32.png" />
|
|
|
|
<link rel="icon" type="image/png" sizes="16x16" href="/assets/favicon-16x16.png" />
|
2022-03-09 20:47:54 -05:00
|
|
|
<link rel="manifest" href="/site.webmanifest" />
|
2022-03-12 18:51:31 -05:00
|
|
|
<link rel="mask-icon" href="/assets/safari-pinned-tab.svg" color="#5bbad5" />
|
2022-03-09 20:47:54 -05:00
|
|
|
<meta name="apple-mobile-web-app-title" content="Drift" />
|
|
|
|
<meta name="application-name" content="Drift" />
|
|
|
|
<meta name="msapplication-TileColor" content="#da532c" />
|
|
|
|
<meta name="theme-color" content="#ffffff" />
|
|
|
|
</Head>
|
|
|
|
<GeistProvider themeType={themeType} >
|
|
|
|
<SkeletonTheme baseColor={skeletonBaseColor} highlightColor={skeletonHighlightColor}>
|
|
|
|
<CssBaseline />
|
|
|
|
<Component {...pageProps} theme={themeType || 'light'} changeTheme={changeTheme} />
|
|
|
|
</SkeletonTheme>
|
|
|
|
</GeistProvider>
|
|
|
|
</>
|
2022-03-06 19:46:59 -05:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default MyApp
|