import { useEffect } from 'react' import { useTranslation } from 'react-i18next' import { create } from 'zustand' import LocalisedText from '@/components/LocalisedText' import { translateUIMessage } from '@/lib/i18n' import type { FC } from 'react' type OverlayStore = { active: boolean setActive: (v: boolean) => void } export const useOverlayStore = create (set => ({ active: false, setActive: v => set ({ active: v }) })) const RouteBlockerOverlay: FC = () => { const { i18n } = useTranslation ('common') const loading = translateUIMessage ('loading', 'common', i18n.language) const loadingLabel = translateUIMessage ('loadingLabel', 'common', i18n.language) const active = useOverlayStore (s => s.active) useEffect (() => { if (active) { document.body.style.overflow = 'hidden' document.body.setAttribute ('aria-busy', 'true') } else { document.body.style.overflow = '' document.body.removeAttribute ('aria-busy') } }, [active]) if (!(active)) return null return (
{loading.text}
) } export default RouteBlockerOverlay