mirror of
https://github.com/Sped0n/bridget.git
synced 2026-04-14 10:09:31 -07:00
* refactor: migrate part of the sass compilation to vite now `bundled` option is deprecated * fix: update build script * chore: add a “type” field to the package.json file to resolve Vite’s complaints about CommonJS modules.
84 lines
1.9 KiB
TypeScript
84 lines
1.9 KiB
TypeScript
import {
|
|
Match,
|
|
Show,
|
|
Switch,
|
|
createEffect,
|
|
createResource,
|
|
createSignal,
|
|
lazy,
|
|
type JSX
|
|
} from 'solid-js'
|
|
import { render } from 'solid-js/web'
|
|
|
|
import { getImageJSON } from './resources'
|
|
import { StateProvider } from './state'
|
|
|
|
import '../scss/style.scss'
|
|
|
|
/**
|
|
* interfaces
|
|
*/
|
|
|
|
export interface Container extends HTMLDivElement {
|
|
dataset: {
|
|
next: string
|
|
close: string
|
|
prev: string
|
|
loading: string
|
|
}
|
|
}
|
|
|
|
// container
|
|
const container = document.getElementsByClassName('container')[0] as Container
|
|
|
|
// lazy components
|
|
const Desktop = lazy(async () => await import('./desktop/layout'))
|
|
const Mobile = lazy(async () => await import('./mobile/layout'))
|
|
|
|
function Main(): JSX.Element {
|
|
// variables
|
|
const [ijs] = createResource(getImageJSON)
|
|
const isMobile = window.matchMedia('(hover: none)').matches
|
|
|
|
// states
|
|
const [scrollable, setScollable] = createSignal(true)
|
|
|
|
createEffect(() => {
|
|
if (scrollable()) {
|
|
container.classList.remove('disableScroll')
|
|
} else {
|
|
container.classList.add('disableScroll')
|
|
}
|
|
})
|
|
|
|
return (
|
|
<>
|
|
<Show when={ijs.state === 'ready'}>
|
|
<StateProvider length={ijs()?.length ?? 0}>
|
|
<Switch fallback={<div>Error</div>}>
|
|
<Match when={isMobile}>
|
|
<Mobile
|
|
ijs={ijs() ?? []}
|
|
closeText={container.dataset.close}
|
|
loadingText={container.dataset.loading}
|
|
setScrollable={setScollable}
|
|
/>
|
|
</Match>
|
|
<Match when={!isMobile}>
|
|
<Desktop
|
|
ijs={ijs() ?? []}
|
|
prevText={container.dataset.prev}
|
|
closeText={container.dataset.close}
|
|
nextText={container.dataset.next}
|
|
loadingText={container.dataset.loading}
|
|
/>
|
|
</Match>
|
|
</Switch>
|
|
</StateProvider>
|
|
</Show>
|
|
</>
|
|
)
|
|
}
|
|
|
|
render(() => <Main />, container)
|