feat(core): open new page on meta-clicking a page link (#6220)

This commit is contained in:
pengx17 2024-03-20 05:38:39 +00:00
parent 5623c0967c
commit 7adb89f134
No known key found for this signature in database
GPG Key ID: 23F23D9E8B3971ED
3 changed files with 20 additions and 9 deletions

View File

@ -23,6 +23,8 @@ export class Workbench {
this.views.value[this.activeViewIndex.value]
);
basename = new LiveData('/');
location = LiveData.from(
this.activeView.pipe(switchMap(view => view.location)),
this.views.value[this.activeViewIndex.value].history.location

View File

@ -1,5 +1,6 @@
import { useAppSettingHelper } from '@affine/core/hooks/affine/use-app-setting-helper';
import { useService } from '@toeverything/infra/di';
import { useLiveData } from '@toeverything/infra/livedata';
import type { To } from 'history';
import { useCallback } from 'react';
@ -15,24 +16,28 @@ export const WorkbenchLink = ({
>) => {
const workbench = useService(Workbench);
const { appSettings } = useAppSettingHelper();
const basename = useLiveData(workbench.basename);
const handleClick = useCallback(
(event: React.MouseEvent<HTMLAnchorElement>) => {
event.preventDefault();
event.stopPropagation();
// TODO: open this when multi view control is implemented
if (
appSettings.enableMultiView &&
environment.isDesktop &&
(event.ctrlKey || event.metaKey)
) {
workbench.open(to, { at: 'beside' });
if (event.ctrlKey || event.metaKey) {
if (appSettings.enableMultiView && environment.isDesktop) {
workbench.open(to, { at: 'beside' });
} else if (!environment.isDesktop) {
const href =
typeof to === 'string'
? to
: `${to.pathname}${to.search}${to.hash}`;
window.open(basename + href, '_blank');
}
} else {
workbench.open(to);
}
onClick?.(event);
},
[appSettings.enableMultiView, onClick, to, workbench]
[appSettings.enableMultiView, basename, onClick, to, workbench]
);
return (
<a {...other} href="#" onClick={handleClick}>

View File

@ -39,6 +39,10 @@ export const WorkbenchRoot = () => {
[workbench]
);
useEffect(() => {
workbench.basename.next(basename);
}, [basename, workbench.basename]);
return (
<SplitView
className={styles.workbenchRootContainer}