mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
* feat(settings): add manager logs viewer with backend log capture * style(settings): polish logs viewer layout for mobile and full-height output
26 lines
754 B
TypeScript
26 lines
754 B
TypeScript
import { useEffect, useState } from 'react'
|
|
|
|
export const DESKTOP_MEDIA_QUERY = '(min-width: 640px)'
|
|
|
|
export function useMediaQuery(query: string): boolean {
|
|
const [matches, setMatches] = useState<boolean>(() => {
|
|
if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') {
|
|
return false
|
|
}
|
|
return window.matchMedia(query).matches
|
|
})
|
|
|
|
useEffect(() => {
|
|
if (typeof window.matchMedia !== 'function') {
|
|
return
|
|
}
|
|
const mediaQuery = window.matchMedia(query)
|
|
setMatches(mediaQuery.matches)
|
|
const update = () => setMatches(mediaQuery.matches)
|
|
mediaQuery.addEventListener('change', update)
|
|
return () => mediaQuery.removeEventListener('change', update)
|
|
}, [query])
|
|
|
|
return matches
|
|
}
|