2023-09-19 20:24:13 +08:00
|
|
|
import { usePrefersDark } from '@solid-primitives/media'
|
2024-04-16 17:52:44 +08:00
|
|
|
import type { ParentComponent } from 'solid-js'
|
2023-09-05 12:18:32 +08:00
|
|
|
import { twMerge } from 'tailwind-merge'
|
2023-09-03 03:26:29 +08:00
|
|
|
import { Header } from '~/components'
|
|
|
|
import {
|
2023-09-08 18:42:15 +08:00
|
|
|
WsMsg,
|
2023-09-19 20:24:13 +08:00
|
|
|
autoSwitchTheme,
|
2023-09-03 03:26:29 +08:00
|
|
|
curTheme,
|
|
|
|
endpoint,
|
2023-09-19 20:24:13 +08:00
|
|
|
favDayTheme,
|
|
|
|
favNightTheme,
|
|
|
|
setCurTheme,
|
2023-09-08 18:42:15 +08:00
|
|
|
setLatestConnectionMsg,
|
2023-09-05 11:40:00 +08:00
|
|
|
useTwemoji,
|
2023-09-08 18:42:15 +08:00
|
|
|
useWsRequest,
|
2023-09-03 03:26:29 +08:00
|
|
|
} from '~/signals'
|
2023-08-24 04:20:53 +08:00
|
|
|
|
2023-09-19 20:24:13 +08:00
|
|
|
const ProtectedResources = () => {
|
|
|
|
const latestConnectionMsg = useWsRequest<WsMsg>('connections')
|
|
|
|
|
2023-09-24 17:10:01 +08:00
|
|
|
createEffect(() => setLatestConnectionMsg(latestConnectionMsg()))
|
2023-09-19 20:24:13 +08:00
|
|
|
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2024-03-20 16:12:33 +08:00
|
|
|
export const App: ParentComponent = ({ children }) => {
|
2023-09-19 20:24:13 +08:00
|
|
|
const prefersDark = usePrefersDark()
|
2023-09-02 19:06:02 +08:00
|
|
|
|
2023-09-03 02:18:05 +08:00
|
|
|
createEffect(() => {
|
2023-10-09 20:12:41 +08:00
|
|
|
if (autoSwitchTheme())
|
2023-09-19 20:24:13 +08:00
|
|
|
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 />
|
|
|
|
|
2024-07-09 21:24:16 +08:00
|
|
|
<div class="flex-1 overflow-y-auto p-2 sm:p-4">{children}</div>
|
2024-03-20 16:12:33 +08:00
|
|
|
|
2024-10-10 20:16:51 +08:00
|
|
|
<Show when={!!endpoint()}>
|
2024-03-20 16:12:33 +08:00
|
|
|
<ProtectedResources />
|
|
|
|
</Show>
|
|
|
|
</div>
|
2023-08-24 04:20:53 +08:00
|
|
|
)
|
|
|
|
}
|