chore: scaffold turbo monorepo with hono api and react admin web
This commit is contained in:
26
apps/web/src/hooks/use-health.ts
Normal file
26
apps/web/src/hooks/use-health.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { queryOptions, useQuery } from '@tanstack/react-query'
|
||||
|
||||
import { apiFetch } from '@/lib/api-client'
|
||||
|
||||
export type HealthStatus = {
|
||||
status: 'ok'
|
||||
uptimeSeconds: number
|
||||
timestamp: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Query options are exported so route loaders can prefetch the same data:
|
||||
*
|
||||
* ```ts
|
||||
* loader: ({ context }) => context.queryClient.ensureQueryData(healthQueryOptions())
|
||||
* ```
|
||||
*/
|
||||
export const healthQueryOptions = () =>
|
||||
queryOptions({
|
||||
queryKey: ['health'],
|
||||
queryFn: () => apiFetch<HealthStatus>('/health'),
|
||||
})
|
||||
|
||||
export function useHealth() {
|
||||
return useQuery(healthQueryOptions())
|
||||
}
|
||||
19
apps/web/src/hooks/use-mobile.ts
Normal file
19
apps/web/src/hooks/use-mobile.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import * as React from "react"
|
||||
|
||||
const MOBILE_BREAKPOINT = 768
|
||||
|
||||
export function useIsMobile() {
|
||||
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined)
|
||||
|
||||
React.useEffect(() => {
|
||||
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
|
||||
const onChange = () => {
|
||||
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
||||
}
|
||||
mql.addEventListener("change", onChange)
|
||||
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
||||
return () => mql.removeEventListener("change", onChange)
|
||||
}, [])
|
||||
|
||||
return !!isMobile
|
||||
}
|
||||
Reference in New Issue
Block a user