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
3 changed files with 20 additions and 9 deletions

View File

@@ -23,6 +23,8 @@ export class Workbench {
this.views.value[this.activeViewIndex.value] this.views.value[this.activeViewIndex.value]
); );
basename = new LiveData('/');
location = LiveData.from( location = LiveData.from(
this.activeView.pipe(switchMap(view => view.location)), this.activeView.pipe(switchMap(view => view.location)),
this.views.value[this.activeViewIndex.value].history.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 { useAppSettingHelper } from '@affine/core/hooks/affine/use-app-setting-helper';
import { useService } from '@toeverything/infra/di'; import { useService } from '@toeverything/infra/di';
import { useLiveData } from '@toeverything/infra/livedata';
import type { To } from 'history'; import type { To } from 'history';
import { useCallback } from 'react'; import { useCallback } from 'react';
@@ -15,24 +16,28 @@ export const WorkbenchLink = ({
>) => { >) => {
const workbench = useService(Workbench); const workbench = useService(Workbench);
const { appSettings } = useAppSettingHelper(); const { appSettings } = useAppSettingHelper();
const basename = useLiveData(workbench.basename);
const handleClick = useCallback( const handleClick = useCallback(
(event: React.MouseEvent<HTMLAnchorElement>) => { (event: React.MouseEvent<HTMLAnchorElement>) => {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
// TODO: open this when multi view control is implemented
if ( if (event.ctrlKey || event.metaKey) {
appSettings.enableMultiView && if (appSettings.enableMultiView && environment.isDesktop) {
environment.isDesktop &&
(event.ctrlKey || event.metaKey)
) {
workbench.open(to, { at: 'beside' }); 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 { } else {
workbench.open(to); workbench.open(to);
} }
onClick?.(event); onClick?.(event);
}, },
[appSettings.enableMultiView, onClick, to, workbench] [appSettings.enableMultiView, basename, onClick, to, workbench]
); );
return ( return (
<a {...other} href="#" onClick={handleClick}> <a {...other} href="#" onClick={handleClick}>

View File

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