1
0
mirror of https://github.com/kremalicious/portfolio.git synced 2024-06-30 05:31:44 +02:00

fix build

This commit is contained in:
Matthias Kretschmann 2018-06-24 20:53:15 +02:00
parent c9369dfa09
commit b881b297c4
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 24 additions and 15 deletions

View File

@ -17,12 +17,24 @@ class ThemeSwitch extends PureComponent {
constructor(props) { constructor(props) {
super(props) super(props)
if (localStorage.getItem('dark') === 'true') { this.state = { dark: null }
this.state = { dark: true } }
} else if (localStorage.getItem('dark') === 'false') {
this.state = { dark: null } isDark = () => this.state.dark === true
darkLocalStorageMode = darkLocalStorage => {
if (darkLocalStorage === 'true') {
this.setState({ dark: true })
} else { } else {
this.state = { dark: null } this.setState({ dark: false })
}
}
darkMode = now => {
if (!this.isDark() && (now >= 19 || now <= 7)) {
this.setState({ dark: true })
} else {
this.setState({ dark: null })
} }
} }
@ -30,18 +42,16 @@ class ThemeSwitch extends PureComponent {
const now = new Date().getHours() const now = new Date().getHours()
const darkLocalStorage = localStorage.getItem('dark') const darkLocalStorage = localStorage.getItem('dark')
if (darkLocalStorage) return if (darkLocalStorage) {
this.darkLocalStorageMode(darkLocalStorage)
if (now >= 19 || now <= 7) { } else {
this.setState({ dark: true }) this.darkMode(now)
} }
} }
isDark = () => this.state.dark === true handleChange = event => {
this.setState({ dark: event.target.checked })
handleChange = () => { localStorage.setItem('dark', event.target.checked)
this.setState({ dark: !this.isDark() })
localStorage.setItem('dark', !this.isDark())
} }
render() { render() {

View File

@ -10,7 +10,6 @@ html,
body { body {
margin: 0; margin: 0;
padding: 0; padding: 0;
height: 100%;
} }
html { html {