mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-21 10:01:43 +03:00
feat(mobile): open doc info in explorer (#9040)
This commit is contained in:
parent
dd94fb3450
commit
c9e555d077
@ -1,5 +1,5 @@
|
|||||||
import { Button, Modal } from '@affine/component';
|
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 { useI18n } from '@affine/i18n';
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import {
|
import {
|
||||||
|
@ -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>;
|
||||||
|
};
|
@ -0,0 +1,2 @@
|
|||||||
|
export * from './doc-info';
|
||||||
|
export * from './doc-scope';
|
@ -2,6 +2,7 @@ import {
|
|||||||
IconButton,
|
IconButton,
|
||||||
MenuItem,
|
MenuItem,
|
||||||
MenuSeparator,
|
MenuSeparator,
|
||||||
|
MenuSub,
|
||||||
toast,
|
toast,
|
||||||
useConfirmModal,
|
useConfirmModal,
|
||||||
} from '@affine/component';
|
} from '@affine/component';
|
||||||
@ -12,6 +13,7 @@ import { IsFavoriteIcon } from '@affine/core/components/pure/icons';
|
|||||||
import type { NodeOperation } from '@affine/core/modules/explorer';
|
import type { NodeOperation } from '@affine/core/modules/explorer';
|
||||||
import { CompatibleFavoriteItemsAdapter } from '@affine/core/modules/favorite';
|
import { CompatibleFavoriteItemsAdapter } from '@affine/core/modules/favorite';
|
||||||
import { WorkbenchService } from '@affine/core/modules/workbench';
|
import { WorkbenchService } from '@affine/core/modules/workbench';
|
||||||
|
import { preventDefault } from '@affine/core/utils';
|
||||||
import { useI18n } from '@affine/i18n';
|
import { useI18n } from '@affine/i18n';
|
||||||
import { track } from '@affine/track';
|
import { track } from '@affine/track';
|
||||||
import {
|
import {
|
||||||
@ -33,12 +35,12 @@ import {
|
|||||||
} from '@toeverything/infra';
|
} from '@toeverything/infra';
|
||||||
import { useCallback, useMemo } from 'react';
|
import { useCallback, useMemo } from 'react';
|
||||||
|
|
||||||
|
import { DocFrameScope, DocInfoSheet } from '../../../doc-info';
|
||||||
import { DocRenameSubMenu } from './dialog';
|
import { DocRenameSubMenu } from './dialog';
|
||||||
|
|
||||||
export const useExplorerDocNodeOperations = (
|
export const useExplorerDocNodeOperations = (
|
||||||
docId: string,
|
docId: string,
|
||||||
options: {
|
options: {
|
||||||
openInfoModal: () => void;
|
|
||||||
openNodeCollapsed: () => void;
|
openNodeCollapsed: () => void;
|
||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
@ -74,10 +76,6 @@ export const useExplorerDocNodeOperations = (
|
|||||||
duplicate(docId, true);
|
duplicate(docId, true);
|
||||||
track.$.navigationPanel.docs.createDoc();
|
track.$.navigationPanel.docs.createDoc();
|
||||||
}, [docId, duplicate]);
|
}, [docId, duplicate]);
|
||||||
const handleOpenInfoModal = useCallback(() => {
|
|
||||||
track.$.docInfoPanel.$.open();
|
|
||||||
options.openInfoModal();
|
|
||||||
}, [options]);
|
|
||||||
|
|
||||||
const handleMoveToTrash = useCallback(() => {
|
const handleMoveToTrash = useCallback(() => {
|
||||||
if (!docRecord) {
|
if (!docRecord) {
|
||||||
@ -154,7 +152,6 @@ export const useExplorerDocNodeOperations = (
|
|||||||
handleOpenInSplitView,
|
handleOpenInSplitView,
|
||||||
handleOpenInNewTab,
|
handleOpenInNewTab,
|
||||||
handleMoveToTrash,
|
handleMoveToTrash,
|
||||||
handleOpenInfoModal,
|
|
||||||
handleRename,
|
handleRename,
|
||||||
}),
|
}),
|
||||||
[
|
[
|
||||||
@ -164,7 +161,6 @@ export const useExplorerDocNodeOperations = (
|
|||||||
handleMoveToTrash,
|
handleMoveToTrash,
|
||||||
handleOpenInNewTab,
|
handleOpenInNewTab,
|
||||||
handleOpenInSplitView,
|
handleOpenInSplitView,
|
||||||
handleOpenInfoModal,
|
|
||||||
handleRename,
|
handleRename,
|
||||||
handleToggleFavoriteDoc,
|
handleToggleFavoriteDoc,
|
||||||
]
|
]
|
||||||
@ -188,7 +184,6 @@ export const useExplorerDocNodeOperationsMenu = (
|
|||||||
handleOpenInSplitView,
|
handleOpenInSplitView,
|
||||||
handleOpenInNewTab,
|
handleOpenInNewTab,
|
||||||
handleMoveToTrash,
|
handleMoveToTrash,
|
||||||
handleOpenInfoModal,
|
|
||||||
handleRename,
|
handleRename,
|
||||||
} = useExplorerDocNodeOperations(docId, options);
|
} = useExplorerDocNodeOperations(docId, options);
|
||||||
|
|
||||||
@ -224,12 +219,20 @@ export const useExplorerDocNodeOperationsMenu = (
|
|||||||
{
|
{
|
||||||
index: 50,
|
index: 50,
|
||||||
view: (
|
view: (
|
||||||
<MenuItem
|
<MenuSub
|
||||||
prefixIcon={<InformationIcon />}
|
triggerOptions={{
|
||||||
onClick={handleOpenInfoModal}
|
prefixIcon: <InformationIcon />,
|
||||||
|
onClick: preventDefault,
|
||||||
|
}}
|
||||||
|
title={title ?? t['unnamed']()}
|
||||||
|
items={
|
||||||
|
<DocFrameScope docId={docId}>
|
||||||
|
<DocInfoSheet docId={docId} />
|
||||||
|
</DocFrameScope>
|
||||||
|
}
|
||||||
>
|
>
|
||||||
{t['com.affine.page-properties.page-info.view']()}
|
<span>{t['com.affine.page-properties.page-info.view']()}</span>
|
||||||
</MenuItem>
|
</MenuSub>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -305,6 +308,7 @@ export const useExplorerDocNodeOperationsMenu = (
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
docId,
|
||||||
enableMultiView,
|
enableMultiView,
|
||||||
favorite,
|
favorite,
|
||||||
handleAddLinkedPage,
|
handleAddLinkedPage,
|
||||||
@ -312,7 +316,6 @@ export const useExplorerDocNodeOperationsMenu = (
|
|||||||
handleMoveToTrash,
|
handleMoveToTrash,
|
||||||
handleOpenInNewTab,
|
handleOpenInNewTab,
|
||||||
handleOpenInSplitView,
|
handleOpenInSplitView,
|
||||||
handleOpenInfoModal,
|
|
||||||
handleRename,
|
handleRename,
|
||||||
handleToggleFavoriteDoc,
|
handleToggleFavoriteDoc,
|
||||||
t,
|
t,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
export * from './app-tabs';
|
export * from './app-tabs';
|
||||||
export * from './doc-card';
|
export * from './doc-card';
|
||||||
|
export * from './doc-info';
|
||||||
export * from './navigation-back';
|
export * from './navigation-back';
|
||||||
export * from './page-header';
|
export * from './page-header';
|
||||||
export * from './rename';
|
export * from './rename';
|
||||||
|
@ -8,6 +8,7 @@ import {
|
|||||||
import { useFavorite } from '@affine/core/components/blocksuite/block-suite-header/favorite';
|
import { useFavorite } from '@affine/core/components/blocksuite/block-suite-header/favorite';
|
||||||
import { IsFavoriteIcon } from '@affine/core/components/pure/icons';
|
import { IsFavoriteIcon } from '@affine/core/components/pure/icons';
|
||||||
import { EditorOutlinePanel } from '@affine/core/desktop/pages/workspace/detail-page/tabs/outline';
|
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 { EditorService } from '@affine/core/modules/editor';
|
||||||
import { ViewService } from '@affine/core/modules/workbench/services/view';
|
import { ViewService } from '@affine/core/modules/workbench/services/view';
|
||||||
import { preventDefault } from '@affine/core/utils';
|
import { preventDefault } from '@affine/core/utils';
|
||||||
@ -27,7 +28,6 @@ import { JournalConflictsMenuItem } from './menu/journal-conflicts';
|
|||||||
import { JournalTodayActivityMenuItem } from './menu/journal-today-activity';
|
import { JournalTodayActivityMenuItem } from './menu/journal-today-activity';
|
||||||
import { EditorModeSwitch } from './menu/mode-switch';
|
import { EditorModeSwitch } from './menu/mode-switch';
|
||||||
import * as styles from './page-header-more-button.css';
|
import * as styles from './page-header-more-button.css';
|
||||||
import { DocInfoSheet } from './sheets/doc-info';
|
|
||||||
|
|
||||||
export const PageHeaderMenuButton = () => {
|
export const PageHeaderMenuButton = () => {
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
|
Loading…
Reference in New Issue
Block a user