diff --git a/components/switch-theme.js b/components/switch-theme.js index d24c521..beab74f 100644 --- a/components/switch-theme.js +++ b/components/switch-theme.js @@ -1,25 +1,45 @@ import PropTypes from 'prop-types' import WbSunnyIcon from '@material-ui/icons/WbSunny' import Brightness3Icon from '@material-ui/icons/Brightness3' +import {Box, makeStyles} from '@material-ui/core' -export default function SwitchTheme({darkMode, setDarkMode}) { +const useStyles = makeStyles({ + switch: { + position: 'absolute', + right: '1em', + top: '95px', + zIndex: 1, + cursor: 'pointer' + }, + switchFixed: { + position: 'fixed', + right: '1em', + top: '95px', + zIndex: 9990, + cursor: 'pointer' + } +}) + +export default function SwitchTheme({switchFixed, darkMode, setDarkMode}) { + const classes = useStyles() const handleClick = () => { localStorage.setItem('oki-dark', !darkMode) setDarkMode(!darkMode) } return ( -
+ {darkMode ? ( ) : ( )} -
+ ) } SwitchTheme.propTypes = { + switchFixed: PropTypes.bool.isRequired, darkMode: PropTypes.bool.isRequired, setDarkMode: PropTypes.func.isRequired } diff --git a/pages/_app.js b/pages/_app.js index 0af2414..a702c3d 100644 --- a/pages/_app.js +++ b/pages/_app.js @@ -1,35 +1,16 @@ import {useEffect, useMemo, useState} from 'react' import {useRouter} from 'next/router' import PropTypes from 'prop-types' -import {createMuiTheme, ThemeProvider, makeStyles} from '@material-ui/core/styles' +import {createMuiTheme, ThemeProvider} from '@material-ui/core/styles' import CssBaseline from '@material-ui/core/CssBaseline' import {Provider, useSession} from 'next-auth/client' -import {Box} from '@material-ui/core' import SwitchTheme from '../components/switch-theme' -const useStyles = makeStyles({ - switch: { - position: 'absolute', - right: '1em', - top: '95px', - zIndex: 1, - cursor: 'pointer' - }, - switchFixed: { - position: 'fixed', - right: '1em', - top: '95px', - zIndex: 9990, - cursor: 'pointer' - } -}) - export default function MyApp(props) { const {Component, pageProps} = props const [darkMode, setDarkMode] = useState(false) const [switchFixed, setSwitchFixed] = useState(false) - const classes = useStyles() const darkTheme = useMemo(() => createMuiTheme({ palette: { @@ -71,9 +52,7 @@ export default function MyApp(props) { - - - + {Component.auth ? ( ) : (