pages235/src/react/utilsApp.ts
Vitaly 65af9a73c2
feat: rework hand! enable by default, fix bow anim (#261)
* refactor swing animation to controller

* idle animator!!!!

* implelment state switch transition

* a huge fix for UI server edit!

* adjust ui scaling so main menu elements clip less

* view bobbing, new config name, ws:

* EXTREMELY important fixes to entities rendering

* a lot of fixes, add dns resolve fallback

* improve f3 E, fix modal not found edge case

* set correctly target for old browsers, should fix ios 14 crash

* unecessary big refactor, to fix ts err

* fix isWysiwyg check

* fix entities rendering count
2025-02-15 05:14:36 +03:00

39 lines
1.1 KiB
TypeScript

import { proxy, useSnapshot } from 'valtio'
import { useEffect, useMemo } from 'react'
import { useMedia } from 'react-use'
import { activeModalStack, miscUiState } from '../globalState'
export const watchedModalsFromHooks = proxy({
value: new Set<string>()
})
// todo should not be there
export const hardcodedKnownModals = [
'player_win:',
'full-map' // todo
]
export const useUsingTouch = () => {
return useSnapshot(miscUiState).currentTouch
}
export const useIsModalActive = (modal: string, useIncludes = false) => {
useMemo(() => {
watchedModalsFromHooks.value.add(modal)
}, [])
useEffect(() => {
// watchedModalsFromHooks.add(modal)
return () => {
watchedModalsFromHooks.value.delete(modal)
}
}, [])
const allStack = useSnapshot(activeModalStack)
return useIncludes ? allStack.some(x => x.reactType === modal) : allStack.at(-1)?.reactType === modal
}
export const useIsWidgetActive = (name: string) => {
return useIsModalActive(`widget-${name}`)
}
export const useIsSmallWidth = () => {
return useMedia('(max-width: 550px)')
}