Files
bridget/assets/ts/desktop/layout.tsx
Sped0n f25b71a858 refactor: split monolithic state into context-based modules
Extract image, desktop, mobile, and config state into separate context
providers to improve modularity and reduce unnecessary re-renders.

Signed-off-by: Sped0n <hi@sped0n.com>
2026-03-22 19:45:05 +08:00

62 lines
1.3 KiB
TypeScript

import { Show, createMemo, type JSX } from 'solid-js'
import { useImageState } from '../imageState'
import CustomCursor from './customCursor'
import Nav from './nav'
import Stage from './stage'
import StageNav from './stageNav'
import { useDesktopState } from './state'
/**
* interfaces and types
*/
export interface DesktopImage extends HTMLImageElement {
dataset: {
hiUrl: string
hiImgH: string
hiImgW: string
loUrl: string
loImgH: string
loImgW: string
}
}
/**
* components
*/
export default function Desktop(props: {
children?: JSX.Element
prevText: string
closeText: string
nextText: string
loadingText: string
}): JSX.Element {
const imageState = useImageState()
const [desktop] = useDesktopState()
const active = createMemo(() => desktop.isOpen() && !desktop.isAnimating())
const cursorText = createMemo(() =>
desktop.isLoading() ? props.loadingText : desktop.hoverText()
)
return (
<>
<Nav />
<Show when={imageState().length > 0}>
<Stage />
<Show when={desktop.isOpen()}>
<CustomCursor cursorText={cursorText} active={active} />
<StageNav
prevText={props.prevText}
closeText={props.closeText}
nextText={props.nextText}
/>
</Show>
</Show>
</>
)
}