mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00:00
feat(electron): close inactive views when switching workspace (#9601)
fix AF-1355
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
import { Menu, type MenuProps } from '@affine/component';
|
||||
import { useNavigateHelper } from '@affine/core/components/hooks/use-navigate-helper';
|
||||
import { GlobalContextService } from '@affine/core/modules/global-context';
|
||||
import { WorkbenchService } from '@affine/core/modules/workbench';
|
||||
import {
|
||||
type WorkspaceMetadata,
|
||||
WorkspacesService,
|
||||
} from '@affine/core/modules/workspace';
|
||||
import { track } from '@affine/track';
|
||||
import { useLiveData, useServices } from '@toeverything/infra';
|
||||
import {
|
||||
useLiveData,
|
||||
useServiceOptional,
|
||||
useServices,
|
||||
} from '@toeverything/infra';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
|
||||
import { UserWithWorkspaceList } from './user-with-workspace-list';
|
||||
@@ -124,22 +129,33 @@ export const WorkspaceNavigator = ({
|
||||
...props
|
||||
}: WorkspaceSelectorProps) => {
|
||||
const { jumpToPage } = useNavigateHelper();
|
||||
const workbench = useServiceOptional(WorkbenchService)?.workbench;
|
||||
|
||||
const handleClickWorkspace = useCallback(
|
||||
(workspaceMetadata: WorkspaceMetadata) => {
|
||||
onSelectWorkspace?.(workspaceMetadata);
|
||||
|
||||
const closeInactiveViews = () =>
|
||||
workbench?.views$.value.forEach(view => {
|
||||
if (workbench?.activeView$.value !== view) {
|
||||
workbench?.close(view);
|
||||
}
|
||||
});
|
||||
|
||||
if (document.startViewTransition) {
|
||||
document.startViewTransition(() => {
|
||||
closeInactiveViews();
|
||||
jumpToPage(workspaceMetadata.id, 'all');
|
||||
return new Promise(resolve =>
|
||||
setTimeout(resolve, 150)
|
||||
); /* start transition after 150ms */
|
||||
});
|
||||
} else {
|
||||
closeInactiveViews();
|
||||
jumpToPage(workspaceMetadata.id, 'all');
|
||||
}
|
||||
},
|
||||
[onSelectWorkspace, jumpToPage]
|
||||
[jumpToPage, onSelectWorkspace, workbench]
|
||||
);
|
||||
const handleCreatedWorkspace = useCallback(
|
||||
(payload: { metadata: WorkspaceMetadata; defaultDocId?: string }) => {
|
||||
|
||||
Reference in New Issue
Block a user