-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minor updates to css reset and layout
- Loading branch information
Showing
8 changed files
with
135 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,28 @@ | ||
import { useMediaQuery } from '@darkroom.engineering/hamo' | ||
import { useOrchestra } from '~/libs/orchestra/react' | ||
import { breakpoints } from '~/styles/config.mjs' | ||
|
||
interface NavigatorWithBattery extends Navigator { | ||
getBattery(): Promise<{ charging: boolean; level: number }> | ||
} | ||
|
||
export function useDeviceDetection() { | ||
const breakpoint = breakpoints.dt | ||
|
||
const { webgl } = useOrchestra() | ||
|
||
const isMobile = useMediaQuery(`(max-width: ${breakpoint - 1}px)`) | ||
const isDesktop = useMediaQuery(`(min-width: ${breakpoint}px)`) | ||
const isReducedMotion = useMediaQuery('(prefers-reduced-motion: reduce)') | ||
const isWebGL = isDesktop && !isReducedMotion && webgl | ||
// TODO: const isLowPowerMode | ||
const isWebGL = isDesktop && !isReducedMotion | ||
|
||
// test thoroughly | ||
const isLowPowerMode = | ||
useMediaQuery('(any-pointer: coarse) and (hover: none)') && | ||
'getBattery' in navigator && | ||
(navigator as NavigatorWithBattery) | ||
.getBattery() | ||
.then( | ||
(battery: { charging: boolean; level: number }) => | ||
battery.charging === false && battery.level <= 0.2 | ||
) | ||
|
||
return { isMobile, isDesktop, isReducedMotion, isWebGL } | ||
return { isMobile, isDesktop, isReducedMotion, isWebGL, isLowPowerMode } | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
import { useFrame } from '@darkroom.engineering/hamo' | ||
import { useRef } from 'react' | ||
|
||
export function useFramerate(fps, callback, priority = 0) { | ||
type FPSValue = number | (() => number) | ||
type FrameCallback = (time: number, deltaTime: number) => void | ||
|
||
export function useFramerate( | ||
fps: FPSValue, | ||
callback?: FrameCallback, | ||
priority = 0 | ||
): void { | ||
const timeRef = useRef(0) | ||
|
||
useFrame((time, delaTime) => { | ||
timeRef.current += delaTime | ||
useFrame((time, deltaTime) => { | ||
timeRef.current += deltaTime | ||
|
||
const executionTime = 1000 / (typeof fps === 'function' ? fps() : fps) | ||
|
||
if (timeRef.current >= executionTime) { | ||
timeRef.current = timeRef.current % executionTime | ||
callback?.(time, delaTime) | ||
callback?.(time, deltaTime) | ||
} | ||
}, priority) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { useCallback, useEffect, useRef } from 'react' | ||
|
||
type SetStateAction<T> = T | ((prevState: T) => T) | ||
type StateCallback<T> = (value: T, prevValue: T) => void | ||
|
||
export function useLazyState<T>( | ||
initialValue: T, | ||
callback: StateCallback<T>, | ||
deps: unknown[] = [] | ||
) { | ||
const stateRef = useRef<T>(initialValue) | ||
|
||
// biome-ignore lint/correctness/useExhaustiveDependencies: we need to trigger on initialValue change | ||
useEffect(() => { | ||
callback(initialValue, initialValue) | ||
}, [initialValue]) | ||
|
||
function set(value: SetStateAction<T>) { | ||
if (typeof value === 'function') { | ||
const nextValue = (value as (prevState: T) => T)(stateRef.current) | ||
callback(nextValue, stateRef.current) | ||
stateRef.current = nextValue | ||
return | ||
} | ||
|
||
if (value !== stateRef.current) { | ||
callback(value, stateRef.current) | ||
stateRef.current = value | ||
} | ||
} | ||
|
||
const get = useCallback(() => stateRef.current, []) | ||
|
||
// biome-ignore lint/correctness/useExhaustiveDependencies: we need to trigger on deps change | ||
useEffect(() => { | ||
callback(stateRef.current, stateRef.current) | ||
}, [...deps]) | ||
|
||
return [get, set] as const | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
7432ef1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚡️ Lighthouse report for the changes in this commit:
🟢 Performance: 99
🟢 Accessibility: 90
🟢 Best practices: 96
🟠 SEO: 63
Lighthouse ran on https://satus-legkgbkt3-darkroom-engineering.vercel.app/