metacubexd/src/App.tsx

52 lines
1.2 KiB
TypeScript
Raw Normal View History

import { usePrefersDark } from '@solid-primitives/media'
2024-04-16 17:52:44 +08:00
import type { ParentComponent } from 'solid-js'
import { twMerge } from 'tailwind-merge'
import { Header } from '~/components'
import {
2023-09-08 18:42:15 +08:00
WsMsg,
autoSwitchTheme,
curTheme,
endpoint,
favDayTheme,
favNightTheme,
setCurTheme,
2023-09-08 18:42:15 +08:00
setLatestConnectionMsg,
useTwemoji,
2023-09-08 18:42:15 +08:00
useWsRequest,
} from '~/signals'
2023-08-24 04:20:53 +08:00
const ProtectedResources = () => {
const latestConnectionMsg = useWsRequest<WsMsg>('connections')
createEffect(() => setLatestConnectionMsg(latestConnectionMsg()))
return null
}
2024-03-20 16:12:33 +08:00
export const App: ParentComponent = ({ children }) => {
const prefersDark = usePrefersDark()
2023-09-02 19:06:02 +08:00
createEffect(() => {
if (autoSwitchTheme())
setCurTheme(prefersDark() ? favNightTheme() : favDayTheme())
2023-08-24 04:20:53 +08:00
})
return (
2024-03-20 16:12:33 +08:00
<div
class={twMerge(
'relative flex h-screen flex-col overscroll-y-none subpixel-antialiased',
useTwemoji() ? 'font-twemoji' : 'font-no-twemoji',
)}
data-theme={curTheme()}
>
<Header />
<div class="flex-1 overflow-y-auto p-2 sm:p-4">{children}</div>
2024-03-20 16:12:33 +08:00
<Show when={!!endpoint()}>
2024-03-20 16:12:33 +08:00
<ProtectedResources />
</Show>
</div>
2023-08-24 04:20:53 +08:00
)
}