Skip to content

Commit

Permalink
feat(mobile): open doc info in explorer (#9040)
Browse files Browse the repository at this point in the history
  • Loading branch information
CatsJuice committed Dec 6, 2024
1 parent dd94fb3 commit c9e555d
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, Modal } from '@affine/component';
import { PageHeader } from '@affine/core/mobile/components';
import { PageHeader } from '@affine/core/mobile/components/page-header';
import { useI18n } from '@affine/i18n';
import clsx from 'clsx';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { Doc } from '@toeverything/infra';
import { DocsService, FrameworkScope, useService } from '@toeverything/infra';
import { type PropsWithChildren, useEffect, useState } from 'react';

export const DocFrameScope = ({
children,
docId,
}: PropsWithChildren<{ docId: string }>) => {
const docsService = useService(DocsService);

const [doc, setDoc] = useState<Doc | null>(null);
useEffect(() => {
if (!docId) return;
const docRef = docsService.open(docId);
setDoc(docRef.doc);
return () => {
docRef.release();
setDoc(null);
};
}, [docId, docsService]);

if (!doc || !docId) return null;

return <FrameworkScope scope={doc.scope}>{children}</FrameworkScope>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './doc-info';
export * from './doc-scope';
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
IconButton,
MenuItem,
MenuSeparator,
MenuSub,
toast,
useConfirmModal,
} from '@affine/component';
Expand All @@ -12,6 +13,7 @@ import { IsFavoriteIcon } from '@affine/core/components/pure/icons';
import type { NodeOperation } from '@affine/core/modules/explorer';
import { CompatibleFavoriteItemsAdapter } from '@affine/core/modules/favorite';
import { WorkbenchService } from '@affine/core/modules/workbench';
import { preventDefault } from '@affine/core/utils';
import { useI18n } from '@affine/i18n';
import { track } from '@affine/track';
import {
Expand All @@ -33,12 +35,12 @@ import {
} from '@toeverything/infra';
import { useCallback, useMemo } from 'react';

import { DocFrameScope, DocInfoSheet } from '../../../doc-info';
import { DocRenameSubMenu } from './dialog';

export const useExplorerDocNodeOperations = (
docId: string,
options: {
openInfoModal: () => void;
openNodeCollapsed: () => void;
}
) => {
Expand Down Expand Up @@ -74,10 +76,6 @@ export const useExplorerDocNodeOperations = (
duplicate(docId, true);
track.$.navigationPanel.docs.createDoc();
}, [docId, duplicate]);
const handleOpenInfoModal = useCallback(() => {
track.$.docInfoPanel.$.open();
options.openInfoModal();
}, [options]);

const handleMoveToTrash = useCallback(() => {
if (!docRecord) {
Expand Down Expand Up @@ -154,7 +152,6 @@ export const useExplorerDocNodeOperations = (
handleOpenInSplitView,
handleOpenInNewTab,
handleMoveToTrash,
handleOpenInfoModal,
handleRename,
}),
[
Expand All @@ -164,7 +161,6 @@ export const useExplorerDocNodeOperations = (
handleMoveToTrash,
handleOpenInNewTab,
handleOpenInSplitView,
handleOpenInfoModal,
handleRename,
handleToggleFavoriteDoc,
]
Expand All @@ -188,7 +184,6 @@ export const useExplorerDocNodeOperationsMenu = (
handleOpenInSplitView,
handleOpenInNewTab,
handleMoveToTrash,
handleOpenInfoModal,
handleRename,
} = useExplorerDocNodeOperations(docId, options);

Expand Down Expand Up @@ -224,12 +219,20 @@ export const useExplorerDocNodeOperationsMenu = (
{
index: 50,
view: (
<MenuItem
prefixIcon={<InformationIcon />}
onClick={handleOpenInfoModal}
<MenuSub
triggerOptions={{
prefixIcon: <InformationIcon />,
onClick: preventDefault,
}}
title={title ?? t['unnamed']()}
items={
<DocFrameScope docId={docId}>
<DocInfoSheet docId={docId} />
</DocFrameScope>
}
>
{t['com.affine.page-properties.page-info.view']()}
</MenuItem>
<span>{t['com.affine.page-properties.page-info.view']()}</span>
</MenuSub>
),
},
{
Expand Down Expand Up @@ -305,14 +308,14 @@ export const useExplorerDocNodeOperationsMenu = (
},
],
[
docId,
enableMultiView,
favorite,
handleAddLinkedPage,
handleDuplicate,
handleMoveToTrash,
handleOpenInNewTab,
handleOpenInSplitView,
handleOpenInfoModal,
handleRename,
handleToggleFavoriteDoc,
t,
Expand Down
1 change: 1 addition & 0 deletions packages/frontend/core/src/mobile/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './app-tabs';
export * from './doc-card';
export * from './doc-info';
export * from './navigation-back';
export * from './page-header';
export * from './rename';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { useFavorite } from '@affine/core/components/blocksuite/block-suite-header/favorite';
import { IsFavoriteIcon } from '@affine/core/components/pure/icons';
import { EditorOutlinePanel } from '@affine/core/desktop/pages/workspace/detail-page/tabs/outline';
import { DocInfoSheet } from '@affine/core/mobile/components';
import { EditorService } from '@affine/core/modules/editor';
import { ViewService } from '@affine/core/modules/workbench/services/view';
import { preventDefault } from '@affine/core/utils';
Expand All @@ -27,7 +28,6 @@ import { JournalConflictsMenuItem } from './menu/journal-conflicts';
import { JournalTodayActivityMenuItem } from './menu/journal-today-activity';
import { EditorModeSwitch } from './menu/mode-switch';
import * as styles from './page-header-more-button.css';
import { DocInfoSheet } from './sheets/doc-info';

export const PageHeaderMenuButton = () => {
const t = useI18n();
Expand Down

0 comments on commit c9e555d

Please sign in to comment.