feat(core): workbench open doc in mode (#7906)

This commit is contained in:
EYHN
2024-08-19 02:37:33 +00:00
parent e0a91f63d3
commit cfac3ebf1f
2 changed files with 8 additions and 25 deletions

View File

@@ -1,5 +1,4 @@
import { IconButton } from '@affine/component'; import { IconButton } from '@affine/component';
import { useNavigateHelper } from '@affine/core/hooks/use-navigate-helper';
import { useI18n } from '@affine/i18n'; import { useI18n } from '@affine/i18n';
import { import {
CloseIcon, CloseIcon,
@@ -20,7 +19,6 @@ import {
import { WorkbenchService } from '../../workbench'; import { WorkbenchService } from '../../workbench';
import { PeekViewService } from '../services/peek-view'; import { PeekViewService } from '../services/peek-view';
import * as styles from './peek-view-controls.css'; import * as styles from './peek-view-controls.css';
import { useEditor } from './utils';
type ControlButtonProps = { type ControlButtonProps = {
nameKey: string; nameKey: string;
@@ -98,9 +96,7 @@ export const DocPeekViewControls = ({
}: DocPeekViewControlsProps) => { }: DocPeekViewControlsProps) => {
const peekView = useService(PeekViewService).peekView; const peekView = useService(PeekViewService).peekView;
const workbench = useService(WorkbenchService).workbench; const workbench = useService(WorkbenchService).workbench;
const { jumpToPageBlock } = useNavigateHelper();
const t = useI18n(); const t = useI18n();
const { doc, workspace } = useEditor(docId);
const controls = useMemo(() => { const controls = useMemo(() => {
return [ return [
{ {
@@ -115,14 +111,7 @@ export const DocPeekViewControls = ({
nameKey: 'open', nameKey: 'open',
onClick: () => { onClick: () => {
// TODO(@Peng): for frame blocks, we should mimic "view in edgeless" button behavior // TODO(@Peng): for frame blocks, we should mimic "view in edgeless" button behavior
if (mode) { workbench.openDoc({ docId, blockId, mode });
// TODO(@eyhn): change this to use mode link
doc?.setPrimaryMode(mode);
}
blockId
? jumpToPageBlock(workspace.id, docId, blockId)
: workbench.openDoc(docId);
peekView.close('none'); peekView.close('none');
}, },
@@ -146,17 +135,7 @@ export const DocPeekViewControls = ({
}, },
}, },
].filter((opt): opt is ControlButtonProps => Boolean(opt)); ].filter((opt): opt is ControlButtonProps => Boolean(opt));
}, [ }, [blockId, docId, mode, peekView, t, workbench]);
blockId,
doc,
docId,
jumpToPageBlock,
mode,
peekView,
t,
workbench,
workspace.id,
]);
return ( return (
<div {...rest} className={clsx(styles.root, className)}> <div {...rest} className={clsx(styles.root, className)}>
{controls.map(option => ( {controls.map(option => (

View File

@@ -1,4 +1,5 @@
import { Unreachable } from '@affine/env/constant'; import { Unreachable } from '@affine/env/constant';
import type { DocMode } from '@blocksuite/blocks';
import { Entity, LiveData } from '@toeverything/infra'; import { Entity, LiveData } from '@toeverything/infra';
import { type To } from 'history'; import { type To } from 'history';
import { nanoid } from 'nanoid'; import { nanoid } from 'nanoid';
@@ -121,12 +122,15 @@ export class Workbench extends Entity {
} }
openDoc( openDoc(
id: string | { docId: string; blockId?: string }, id: string | { docId: string; blockId?: string; mode?: DocMode },
options?: WorkbenchOpenOptions options?: WorkbenchOpenOptions
) { ) {
const docId = typeof id === 'string' ? id : id.docId; const docId = typeof id === 'string' ? id : id.docId;
const blockId = typeof id === 'string' ? undefined : id.blockId; const blockId = typeof id === 'string' ? undefined : id.blockId;
this.open(blockId ? `/${docId}#${blockId}` : `/${docId}`, options); const mode = typeof id === 'string' ? undefined : id.mode;
const hash = blockId ? `#${blockId}` : '';
const query = mode ? `?mode=${mode}` : '';
this.open(`/${docId}${query}${hash}`, options);
} }
openCollections(options?: WorkbenchOpenOptions) { openCollections(options?: WorkbenchOpenOptions) {