pdf-preview-detached-root.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { createRoot } from 'react-dom/client'
  2. import PdfPreview from './pdf-preview'
  3. import useWaitForI18n from '../../../shared/hooks/use-wait-for-i18n'
  4. import { ReactContextRoot } from '@/features/ide-react/context/react-context-root'
  5. import { useIsNewEditorEnabled } from '@/features/ide-redesign/utils/new-editor-utils'
  6. import useThemedPage from '@/shared/hooks/use-themed-page'
  7. function PdfPreviewDetachedRoot() {
  8. const { isReady } = useWaitForI18n()
  9. if (!isReady) {
  10. return null
  11. }
  12. return (
  13. <ReactContextRoot>
  14. <PdfPreviewDetachedRootContent />
  15. </ReactContextRoot>
  16. )
  17. }
  18. function PdfPreviewDetachedRootContent() {
  19. useThemedPage() // set the page theme based on user settings
  20. return (
  21. <EditorRedesignWrapper>
  22. <PdfPreview />
  23. </EditorRedesignWrapper>
  24. )
  25. }
  26. function EditorRedesignWrapper({ children }: { children: React.ReactNode }) {
  27. const newEditorEnabled = useIsNewEditorEnabled()
  28. if (!newEditorEnabled) {
  29. return <>{children}</>
  30. }
  31. // TODO ide-redesign-cleanup: this wrapper should not be required
  32. return <div className="ide-redesign-main">{children}</div>
  33. }
  34. export default PdfPreviewDetachedRoot // for testing
  35. const element = document.getElementById('pdf-preview-detached-root')
  36. if (element) {
  37. const root = createRoot(element)
  38. root.render(<PdfPreviewDetachedRoot />)
  39. }