diff --git a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx index b25a9685579..51f0709b37d 100644 --- a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx +++ b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx @@ -29,7 +29,7 @@ import { SetWorksheetOrderMutation, } from '@univerjs/sheets'; import { IConfirmService, Menu } from '@univerjs/ui'; -import { useDependency, useInjector } from '@wendellhu/redi/react-bindings'; +import { useDependency } from '@wendellhu/redi/react-bindings'; import React, { useEffect, useRef, useState } from 'react'; import { SheetMenuPosition } from '../../../controllers/menu/menu'; @@ -60,7 +60,6 @@ export function SheetBarTabs() { const confirmService = useDependency(IConfirmService); const selectionRenderService = useDependency(ISelectionRenderService); const editorBridgeService = useDependency(IEditorBridgeService); - const injector = useInjector(); const workbook = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET)!; diff --git a/packages/sheets-ui/src/views/sheet-container/SheetContainer.tsx b/packages/sheets-ui/src/views/sheet-container/SheetContainer.tsx index 243fbf10296..a5985f0020d 100644 --- a/packages/sheets-ui/src/views/sheet-container/SheetContainer.tsx +++ b/packages/sheets-ui/src/views/sheet-container/SheetContainer.tsx @@ -48,9 +48,7 @@ export function RenderSheetHeader() { if (!workbook) return null; return ( - <> - - + ); } diff --git a/packages/ui/src/controllers/ui/ui-desktop.controller.tsx b/packages/ui/src/controllers/ui/ui-desktop.controller.tsx index 8e8ab4e70c0..f8572fd7f0b 100644 --- a/packages/ui/src/controllers/ui/ui-desktop.controller.tsx +++ b/packages/ui/src/controllers/ui/ui-desktop.controller.tsx @@ -25,7 +25,6 @@ import { delay, filter, take } from 'rxjs'; import { ILayoutService } from '../../services/layout/layout.service'; import { App } from '../../views/App'; -import { DesktopUIPart, IUIPartsService } from '../../services/parts/parts.service'; import type { IWorkbenchOptions } from './ui.controller'; const STEADY_TIMEOUT = 3000; @@ -95,39 +94,23 @@ function bootStrap( } const ConnectedApp = connectInjector(App, injector); - const uiPartsService = injector.get(IUIPartsService); const onRendered = (canvasElement: HTMLElement) => callback(canvasElement, mountContainer); function render() { - const headerComponents = uiPartsService.getComponents(DesktopUIPart.HEADER); - const contentComponents = uiPartsService.getComponents(DesktopUIPart.CONTENT); - const footerComponents = uiPartsService.getComponents(DesktopUIPart.FOOTER); - const headerMenuComponents = uiPartsService.getComponents(DesktopUIPart.HEADER_MENU); - const leftSidebarComponents = uiPartsService.getComponents(DesktopUIPart.LEFT_SIDEBAR); - const globalComponents = uiPartsService.getComponents(DesktopUIPart.GLOBAL); - createRoot( , mountContainer ); } - const updateSubscription = uiPartsService.componentRegistered$.subscribe(render); render(); return toDisposable(() => { unmount(mountContainer); - updateSubscription.unsubscribe(); }); } diff --git a/packages/ui/src/services/parts/parts.service.ts b/packages/ui/src/services/parts/parts.service.ts index 42cc0c813cb..aea0a88beff 100644 --- a/packages/ui/src/services/parts/parts.service.ts +++ b/packages/ui/src/services/parts/parts.service.ts @@ -57,6 +57,8 @@ export class DesktopUIPartsService implements IUIPartsService { if (components.size === 0) { this._componentsByPart.delete(part); } + + this._componentRegistered$.complete(); }); } diff --git a/packages/ui/src/views/App.tsx b/packages/ui/src/views/App.tsx index 2416ebad701..e61a1edb804 100644 --- a/packages/ui/src/views/App.tsx +++ b/packages/ui/src/views/App.tsx @@ -18,10 +18,10 @@ import { LocaleService, ThemeService } from '@univerjs/core'; import type { ILocale } from '@univerjs/design'; import { ConfigProvider, defaultTheme, themeInstance } from '@univerjs/design'; import { useDependency } from '@wendellhu/redi/react-bindings'; -import type { ComponentType } from 'react'; import React, { useEffect, useMemo, useRef, useState } from 'react'; import type { IWorkbenchOptions } from '../controllers/ui/ui.controller'; import { IMessageService } from '../services/message/message.service'; +import { DesktopUIPart, IUIPartsService } from '../services/parts/parts.service'; import styles from './app.module.less'; import { ComponentContainer } from './components/ComponentContainer'; import { Toolbar } from './components/doc-bars/Toolbar'; @@ -33,13 +33,6 @@ import { builtInGlobalComponents } from './parts'; export interface IUniverAppProps extends IWorkbenchOptions { mountContainer: HTMLElement; - globalComponents?: Set<() => ComponentType>; - headerComponents?: Set<() => ComponentType>; - contentComponents?: Set<() => ComponentType>; - footerComponents?: Set<() => ComponentType>; - headerMenuComponents?: Set<() => ComponentType>; - leftSidebarComponents?: Set<() => ComponentType>; - onRendered?: (container: HTMLElement) => void; } @@ -48,12 +41,6 @@ export function App(props: IUniverAppProps) { header, footer, mountContainer, - headerComponents, - headerMenuComponents, - contentComponents, - footerComponents, - leftSidebarComponents, - globalComponents, onRendered, } = props; @@ -62,10 +49,36 @@ export function App(props: IUniverAppProps) { const messageService = useDependency(IMessageService); const contentRef = useRef(null); + const uiPartsService = useDependency(IUIPartsService); + + const [updateTrigger, setUpdateTrigger] = useState(false); + + useEffect(() => { + const updateSubscription = uiPartsService.componentRegistered$.subscribe(() => { + setUpdateTrigger((prev) => !prev); + }); + + return () => { + updateSubscription.unsubscribe(); + }; + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + + const { headerComponents, contentComponents, footerComponents, headerMenuComponents, leftSidebarComponents, globalComponents } = useMemo(() => ({ + headerComponents: uiPartsService.getComponents(DesktopUIPart.HEADER), + contentComponents: uiPartsService.getComponents(DesktopUIPart.CONTENT), + footerComponents: uiPartsService.getComponents(DesktopUIPart.FOOTER), + headerMenuComponents: uiPartsService.getComponents(DesktopUIPart.HEADER_MENU), + leftSidebarComponents: uiPartsService.getComponents(DesktopUIPart.LEFT_SIDEBAR), + globalComponents: uiPartsService.getComponents(DesktopUIPart.GLOBAL), + // eslint-disable-next-line react-hooks/exhaustive-deps + }), [updateTrigger]); + useEffect(() => { if (!themeService.getCurrentTheme()) { themeService.setTheme(defaultTheme); } + // eslint-disable-next-line react-hooks/exhaustive-deps }, []); useEffect(() => {