Skip to content

Commit

Permalink
fix(core): enable scroll anchoring in share page
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Sep 19, 2024
1 parent 7184d83 commit 5989210
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -377,15 +377,14 @@ export function patchQuickSearchService(framework: FrameworkProvider) {
(item.name === 'Linked Doc' || item.name === 'Link')
) {
item.action = async ({ rootComponent }) => {
// TODO(@Mirone): fix the type
// @ts-expect-error fixme
const { success, insertedLinkType } =
// @ts-expect-error fixme
rootComponent.std.command.exec('insertLinkByQuickSearch');

if (!success) return;

// TODO(@Mirone): fix the type
// @ts-expect-error fixme

Check failure on line 387 in packages/frontend/core/src/components/blocksuite/block-suite-editor/specs/custom/spec-patchers.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unused '@ts-expect-error' directive.
insertedLinkType
?.then(
(type: {
Expand All @@ -394,17 +393,17 @@ export function patchQuickSearchService(framework: FrameworkProvider) {
const flavour = type?.flavour;
if (!flavour) return;

if (flavour === 'affine:bookmark') {
track.doc.editor.slashMenu.bookmark();
return;
}

if (flavour === 'affine:embed-linked-doc') {
track.doc.editor.slashMenu.linkDoc({
control: 'linkDoc',
});
return;
}

if (flavour === 'affine:bookmark') {
track.doc.editor.slashMenu.bookmark();
return;
}
}
)
.catch(console.error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { AppContainer, MainContainer } from '@affine/core/components/workspace';
import { AuthService } from '@affine/core/modules/cloud';
import {
type Editor,
type EditorSelector,
EditorService,
EditorsService,
} from '@affine/core/modules/editor';
Expand Down Expand Up @@ -57,16 +58,29 @@ export const SharePage = ({

const location = useLocation();

const { mode, isTemplate, templateName, templateSnapshotUrl } =
const { mode, selector, isTemplate, templateName, templateSnapshotUrl } =
useMemo(() => {
const searchParams = new URLSearchParams(location.search);
const queryStringMode = searchParams.get('mode') as DocMode | null;
const blockIds = searchParams
.get('blockIds')
?.split(',')
.filter(v => v.length);
const elementIds = searchParams
.get('elementIds')
?.split(',')
.filter(v => v.length);

return {
mode:
queryStringMode && DocModes.includes(queryStringMode)
? queryStringMode
: null,
selector: {
blockIds,
elementIds,
refreshKey: searchParams.get('refreshKey') || undefined,
},
isTemplate: searchParams.has('isTemplate'),
templateName: searchParams.get('templateName') || '',
templateSnapshotUrl: searchParams.get('snapshotUrl') || '',
Expand Down Expand Up @@ -94,6 +108,7 @@ export const SharePage = ({
workspaceBinary={data.workspaceBinary}
docBinary={data.docBinary}
publishMode={mode || data.publishMode}
selector={selector}
isTemplate={isTemplate}
templateName={templateName}
templateSnapshotUrl={templateSnapshotUrl}
Expand All @@ -110,6 +125,7 @@ const SharePageInner = ({
workspaceBinary,
docBinary,
publishMode = 'page' as DocMode,
selector,
isTemplate,
templateName,
templateSnapshotUrl,
Expand All @@ -119,6 +135,7 @@ const SharePageInner = ({
workspaceBinary: Uint8Array;
docBinary: Uint8Array;
publishMode?: DocMode;
selector?: EditorSelector;
isTemplate?: boolean;
templateName?: string;
templateSnapshotUrl?: string;
Expand Down Expand Up @@ -180,6 +197,10 @@ const SharePageInner = ({
const editor = doc.scope.get(EditorsService).createEditor();
editor.setMode(publishMode);

if (selector) {
editor.setSelector(selector);
}

setEditor(editor);
})
.catch(err => {
Expand All @@ -190,6 +211,7 @@ const SharePageInner = ({
workspaceId,
workspacesService,
publishMode,
selector,
workspaceBinary,
docBinary,
]);
Expand Down
23 changes: 8 additions & 15 deletions packages/frontend/core/src/modules/workbench/entities/workbench.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { toURLSearchParams } from '@affine/core/utils';
import { Unreachable } from '@affine/env/constant';
import type { DocMode } from '@blocksuite/blocks';
import type { ReferenceParams } from '@blocksuite/blocks';
import { Entity, LiveData } from '@toeverything/infra';
import { type To } from 'history';
import { omit } from 'lodash-es';
import { nanoid } from 'nanoid';

import type { WorkbenchNewTabHandler } from '../services/workbench-new-tab-handler';
Expand Down Expand Up @@ -122,27 +124,18 @@ export class Workbench extends Entity {
}

openDoc(
id:
| string
| {
docId: string;
mode?: DocMode;
blockIds?: string[];
elementIds?: string[];
},
id: string | ({ docId: string } & ReferenceParams),
options?: WorkbenchOpenOptions
) {
const isString = typeof id === 'string';
const docId = isString ? id : id.docId;

let query = '';
if (!isString) {
const { mode, blockIds, elementIds } = id;
const search = new URLSearchParams();
if (mode) search.set('mode', mode);
if (blockIds?.length) search.set('blockIds', blockIds.join(','));
if (elementIds?.length) search.set('elementIds', elementIds.join(','));
if (search.size > 0) query = `?${search.toString()}`;
const search = toURLSearchParams(omit(id, ['docId']));
if (search?.size) {
query = search.toString();
}
}

this.open(`/${docId}${query}`, options);
Expand Down

0 comments on commit 5989210

Please sign in to comment.