pages235/src/react/utils.ts
Vitaly Turovsky 826fed54d9 fix: rewrite google drive integration by using native picker (safer for user)
fix: allow to switch accounts in google provider (fix sign out)
feat: add google drive ui integration (open with context menu)
2024-03-18 05:21:46 +03:00

37 lines
994 B
TypeScript

import { useSnapshot } from 'valtio'
import { useEffect, useRef } from 'react'
import { UAParser } from 'ua-parser-js'
import { activeModalStack, miscUiState } from '../globalState'
export const useIsModalActive = (modal: string, useIncludes = false) => {
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 function useDidUpdateEffect (fn, inputs) {
const isMountingRef = useRef(false)
useEffect(() => {
isMountingRef.current = true
}, [])
useEffect(() => {
if (isMountingRef.current) {
isMountingRef.current = false
} else {
return fn()
}
}, inputs)
}
export const useUsingTouch = () => {
return useSnapshot(miscUiState).currentTouch
}
export const ua = new UAParser(navigator.userAgent)
export const isIos = ua.getOS().name === 'iOS'