1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-15 17:47:09 +00:00
conky/web/components/Layout.tsx
Brenden Matthews bd5b7c87fa
Update/fix some web stuff. (#1429)
* Update/fix some web stuff.

Also added lefthook with some linting config.

* Add note about lefthook.

* Enable sort imports eslint rule.

* This statement is untrue

* Remove cypress video, add to gitignore

* Add web CI action

* Set the right dir here

* Try this
2023-02-25 20:12:11 -05:00

69 lines
1.6 KiB
TypeScript

import { useEffect, useState } from 'react'
import { SearchIndex } from '../utils/search'
import Footer from './Footer'
import Header from './Header'
function darkModeDefault() {
if (typeof window === 'undefined') {
return false
} else {
const theme = localStorage.getItem('theme')
return (
theme === 'dark' ||
(!theme && window.matchMedia('(prefers-color-scheme: dark)').matches)
)
}
}
interface LayoutProps {
children: React.ReactNode
searchIndex: SearchIndex
}
export default function Layout({ children, searchIndex }: LayoutProps) {
const [darkMode, setDarkMode] = useState(darkModeDefault())
useEffect(() => {
if (darkMode) {
document.documentElement.classList.add('dark')
localStorage.setItem('theme', 'dark')
} else {
document.documentElement.classList.remove('dark')
localStorage.setItem('theme', 'light')
}
}, [darkMode])
useEffect(() => {
const darkQuery = window.matchMedia('(prefers-color-scheme: dark)')
darkQuery.onchange = (e) => {
if (e.matches) {
setDarkMode(true)
} else {
setDarkMode(false)
}
}
}, [])
return (
<div>
<div className="sticky top-0 z-10 h-16">
<Header
searchIndex={searchIndex}
name="Conky"
darkMode={darkMode}
setDarkMode={setDarkMode}
/>
</div>
<div className="relative pb-4">
<div className="flex flex-col items-center max-w-3xl w-full mx-auto">
{children}
</div>
</div>
<div className="relative">
<Footer />
</div>
</div>
)
}