| 1 |
import { useSelect, dispatch } from '@wordpress/data' |
| 2 |
import { useRef, useLayoutEffect } from '@wordpress/element' |
| 3 |
import { Dialog } from '@headlessui/react' |
| 4 |
import { useModal } from '@library/hooks/useModal' |
| 5 |
import { useGlobalStore } from '@library/state/GlobalState' |
| 6 |
import { Layout } from './layout/Layout' |
| 7 |
|
| 8 |
export default function MainWindow() { |
| 9 |
const { open, setOpen, ready } = useGlobalStore() |
| 10 |
const containerRef = useRef(null) |
| 11 |
const modal = useModal(open) |
| 12 |
const welcomeScreenOpen = useSelect((select) => |
| 13 |
select('core/edit-post')?.isFeatureActive('welcomeGuide'), |
| 14 |
) |
| 15 |
|
| 16 |
useLayoutEffect(() => { |
| 17 |
if (!open) return |
| 18 |
// Disable the welcome guide if open |
| 19 |
if (welcomeScreenOpen) { |
| 20 |
dispatch('core/edit-post').toggleFeature('welcomeGuide') |
| 21 |
} |
| 22 |
}, [open, welcomeScreenOpen]) |
| 23 |
|
| 24 |
return ( |
| 25 |
<Dialog |
| 26 |
as="div" |
| 27 |
className="extendify" |
| 28 |
initialFocus={containerRef} |
| 29 |
open={open} |
| 30 |
onClose={() => undefined}> |
| 31 |
<div className="fixed inset-0 bg-black bg-opacity-40 transition-opacity" /> |
| 32 |
<div className="fixed inset-0 z-high m-auto h-screen w-screen overflow-y-auto sm:h-auto sm:w-auto"> |
| 33 |
<div className="flex min-h-screen items-end justify-center px-4 pt-4 pb-20 text-center sm:block sm:p-0"> |
| 34 |
<div |
| 35 |
ref={containerRef} |
| 36 |
tabIndex="0" |
| 37 |
onClick={(e) => |
| 38 |
e.target === e.currentTarget && setOpen(false) |
| 39 |
} |
| 40 |
className="fixed inset-0 transform p-2 transition-all lg:absolute lg:overflow-hidden lg:p-16"> |
| 41 |
<Layout /> |
| 42 |
{ready ? modal : null} |
| 43 |
</div> |
| 44 |
</div> |
| 45 |
</div> |
| 46 |
</Dialog> |
| 47 |
) |
| 48 |
} |
| 49 |
|