sync-menu.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { useState } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import importOverleafModules from '../../../../macros/import-overleaf-module.macro'
  4. import getMeta from '../../../utils/meta'
  5. export default function SyncMenu() {
  6. const { t } = useTranslation()
  7. const anonymous = getMeta('ol-anonymous') as boolean | undefined
  8. const [editorLeftMenuSync] = useState<any[]>(
  9. () =>
  10. getMeta('editorLeftMenuSync') ||
  11. importOverleafModules('editorLeftMenuSync')
  12. )
  13. if (anonymous === true || anonymous === undefined) {
  14. return null
  15. }
  16. if (editorLeftMenuSync.length === 0) {
  17. return null
  18. }
  19. return (
  20. <>
  21. <h4>{t('sync')}</h4>
  22. <ul className="list-unstyled nav">
  23. {editorLeftMenuSync.map(({ import: importObject }, index) => (
  24. <li key={`editor-left-menu-sync-${index}`}>
  25. <ModuleComponent Component={Object.values(importObject)[0]} />
  26. </li>
  27. ))}
  28. </ul>
  29. </>
  30. )
  31. }
  32. type ModuleComponentProps = {
  33. Component: any
  34. }
  35. function ModuleComponent({ Component }: ModuleComponentProps) {
  36. return <Component />
  37. }