mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-23 13:29:02 +08:00
feat(core): init organize (#7456)
This commit is contained in:
@@ -14,12 +14,22 @@ import {
|
||||
PageIcon,
|
||||
ViewLayersIcon,
|
||||
} from '@blocksuite/icons/rc';
|
||||
import { useLiveData, useService, WorkspaceService } from '@toeverything/infra';
|
||||
import {
|
||||
GlobalContextService,
|
||||
useLiveData,
|
||||
useService,
|
||||
useServices,
|
||||
WorkspaceService,
|
||||
} from '@toeverything/infra';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
|
||||
import { useNavigateHelper } from '../../../hooks/use-navigate-helper';
|
||||
import { ViewBody, ViewHeader } from '../../../modules/workbench';
|
||||
import {
|
||||
useIsActiveView,
|
||||
ViewBody,
|
||||
ViewHeader,
|
||||
} from '../../../modules/workbench';
|
||||
import { WorkspaceSubPath } from '../../../shared';
|
||||
import * as styles from './collection.css';
|
||||
import { CollectionDetailHeader } from './header';
|
||||
@@ -58,13 +68,18 @@ export const CollectionDetail = ({
|
||||
};
|
||||
|
||||
export const Component = function CollectionPage() {
|
||||
const collectionService = useService(CollectionService);
|
||||
const { collectionService, globalContextService } = useServices({
|
||||
CollectionService,
|
||||
GlobalContextService,
|
||||
});
|
||||
const globalContext = globalContextService.globalContext;
|
||||
|
||||
const collections = useLiveData(collectionService.collections$);
|
||||
const navigate = useNavigateHelper();
|
||||
const params = useParams();
|
||||
const workspace = useService(WorkspaceService).workspace;
|
||||
const collection = collections.find(v => v.id === params.collectionId);
|
||||
const isActiveView = useIsActiveView();
|
||||
|
||||
const notifyCollectionDeleted = useCallback(() => {
|
||||
navigate.jumpToSubPath(workspace.id, WorkspaceSubPath.ALL);
|
||||
@@ -82,6 +97,19 @@ export const Component = function CollectionPage() {
|
||||
return notify.error({ title: text });
|
||||
}, [collectionService, navigate, params.collectionId, workspace.id]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isActiveView && collection) {
|
||||
globalContext.collectionId.set(collection.id);
|
||||
globalContext.isCollection.set(true);
|
||||
|
||||
return () => {
|
||||
globalContext.collectionId.set(null);
|
||||
globalContext.isCollection.set(false);
|
||||
};
|
||||
}
|
||||
return;
|
||||
}, [collection, globalContext, isActiveView]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!collection) {
|
||||
notifyCollectionDeleted();
|
||||
|
||||
@@ -176,8 +176,7 @@ export function DetailPageHeader(props: PageHeaderProps) {
|
||||
<InfoModal
|
||||
open={openInfoModal}
|
||||
onOpenChange={setOpenInfoModal}
|
||||
page={page}
|
||||
workspace={workspace}
|
||||
docId={page.id}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -95,7 +95,6 @@ const DetailPageImpl = memo(function DetailPageImpl() {
|
||||
|
||||
useEffect(() => {
|
||||
const disposable = AIProvider.slots.requestOpenWithChat.on(params => {
|
||||
console.log(params);
|
||||
workbench.openSidebar();
|
||||
view.activeSidebarTab('chat');
|
||||
|
||||
@@ -110,9 +109,11 @@ const DetailPageImpl = memo(function DetailPageImpl() {
|
||||
useEffect(() => {
|
||||
if (isActiveView) {
|
||||
globalContext.docId.set(doc.id);
|
||||
globalContext.isDoc.set(true);
|
||||
|
||||
return () => {
|
||||
globalContext.docId.set(null);
|
||||
globalContext.isDoc.set(false);
|
||||
};
|
||||
}
|
||||
return;
|
||||
|
||||
@@ -4,9 +4,18 @@ import {
|
||||
} from '@affine/core/components/page-list';
|
||||
import { useBlockSuiteDocMeta } from '@affine/core/hooks/use-block-suite-page-meta';
|
||||
import { TagService } from '@affine/core/modules/tag';
|
||||
import { ViewBody, ViewHeader } from '@affine/core/modules/workbench';
|
||||
import { useLiveData, useService, WorkspaceService } from '@toeverything/infra';
|
||||
import { useMemo } from 'react';
|
||||
import {
|
||||
useIsActiveView,
|
||||
ViewBody,
|
||||
ViewHeader,
|
||||
} from '@affine/core/modules/workbench';
|
||||
import {
|
||||
GlobalContextService,
|
||||
useLiveData,
|
||||
useService,
|
||||
WorkspaceService,
|
||||
} from '@toeverything/infra';
|
||||
import { useEffect, useMemo } from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
|
||||
import { PageNotFound } from '../../404';
|
||||
@@ -15,6 +24,7 @@ import { TagDetailHeader } from './header';
|
||||
import * as styles from './index.css';
|
||||
|
||||
export const TagDetail = ({ tagId }: { tagId?: string }) => {
|
||||
const globalContext = useService(GlobalContextService).globalContext;
|
||||
const currentWorkspace = useService(WorkspaceService).workspace;
|
||||
const pageMetas = useBlockSuiteDocMeta(currentWorkspace.docCollection);
|
||||
|
||||
@@ -28,6 +38,21 @@ export const TagDetail = ({ tagId }: { tagId?: string }) => {
|
||||
return pageMetas.filter(page => pageIdsSet.has(page.id));
|
||||
}, [pageIds, pageMetas]);
|
||||
|
||||
const isActiveView = useIsActiveView();
|
||||
|
||||
useEffect(() => {
|
||||
if (isActiveView && currentTag) {
|
||||
globalContext.tagId.set(currentTag.id);
|
||||
globalContext.isTag.set(true);
|
||||
|
||||
return () => {
|
||||
globalContext.tagId.set(null);
|
||||
globalContext.isTag.set(false);
|
||||
};
|
||||
}
|
||||
return;
|
||||
}, [currentTag, globalContext, isActiveView]);
|
||||
|
||||
if (!currentTag) {
|
||||
return <PageNotFound />;
|
||||
}
|
||||
|
||||
@@ -7,9 +7,14 @@ import { useBlockSuiteDocMeta } from '@affine/core/hooks/use-block-suite-page-me
|
||||
import { useI18n } from '@affine/i18n';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import { DeleteIcon } from '@blocksuite/icons/rc';
|
||||
import { useService, WorkspaceService } from '@toeverything/infra';
|
||||
import {
|
||||
GlobalContextService,
|
||||
useService,
|
||||
WorkspaceService,
|
||||
} from '@toeverything/infra';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
import { ViewBody, ViewHeader } from '../../modules/workbench';
|
||||
import { useIsActiveView, ViewBody, ViewHeader } from '../../modules/workbench';
|
||||
import { EmptyPageList } from './page-list-empty';
|
||||
import * as styles from './trash-page.css';
|
||||
|
||||
@@ -28,6 +33,7 @@ const TrashHeader = () => {
|
||||
};
|
||||
|
||||
export const TrashPage = () => {
|
||||
const globalContextService = useService(GlobalContextService);
|
||||
const currentWorkspace = useService(WorkspaceService).workspace;
|
||||
const docCollection = currentWorkspace.docCollection;
|
||||
assertExists(docCollection);
|
||||
@@ -37,6 +43,19 @@ export const TrashPage = () => {
|
||||
trash: true,
|
||||
});
|
||||
|
||||
const isActiveView = useIsActiveView();
|
||||
|
||||
useEffect(() => {
|
||||
if (isActiveView) {
|
||||
globalContextService.globalContext.isTrash.set(true);
|
||||
|
||||
return () => {
|
||||
globalContextService.globalContext.isTrash.set(false);
|
||||
};
|
||||
}
|
||||
return;
|
||||
}, [globalContextService.globalContext.isTrash, isActiveView]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<ViewHeader>
|
||||
|
||||
Reference in New Issue
Block a user