Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

refactor: remove null type in hooks (#1955)

Himself653d70a36dd357
diff --git a/apps/web/src/components/__tests__/WorkSpaceSliderBar.spec.tsx b/apps/web/src/components/__tests__/WorkSpaceSliderBar.spec.tsx
index 7d6e69af35..628381729b 100644
--- a/apps/web/src/components/__tests__/WorkSpaceSliderBar.spec.tsx
+++ b/apps/web/src/components/__tests__/WorkSpaceSliderBar.spec.tsx
@@ -10,6 +10,7 @@ import {
import { WorkspaceFlavour } from '@affine/workspace/type';
import { assertExists } from '@blocksuite/store';
import { render, renderHook } from '@testing-library/react';
+import { useBlockSuiteWorkspaceHelper } from '@toeverything/hooks/use-block-suite-workspace-helper';
import { createStore, getDefaultStore, Provider, useAtomValue } from 'jotai';
import { useRouter } from 'next/router';
import type React from 'react';
@@ -22,7 +23,6 @@ import {
currentWorkspaceAtom,
useCurrentWorkspace,
} from '../../hooks/current/use-current-workspace';
-import { useBlockSuiteWorkspaceHelper } from '../../hooks/use-blocksuite-workspace-helper';
import { useAppHelper } from '../../hooks/use-workspaces';
import { ThemeProvider } from '../../providers/ThemeProvider';
import { pathGenerator } from '../../shared';
diff --git a/apps/web/src/components/affine/pinboard/pinboard-menu/index.tsx b/apps/web/src/components/affine/pinboard/pinboard-menu/index.tsx
index c77d5c910e..d42e80751d 100644
--- a/apps/web/src/components/affine/pinboard/pinboard-menu/index.tsx
+++ b/apps/web/src/components/affine/pinboard/pinboard-menu/index.tsx
@@ -3,9 +3,9 @@ import { Input, PureMenu, TreeView } from '@affine/component';
import { useTranslation } from '@affine/i18n';
import { RemoveIcon, SearchIcon } from '@blocksuite/icons';
import type { PageMeta } from '@blocksuite/store';
+import { usePageMetaHelper } from '@toeverything/hooks/use-block-suite-page-meta';
import React, { useCallback, useMemo, useState } from 'react';
-import { usePageMetaHelper } from '../../../../hooks/use-page-meta';
import { usePinboardData } from '../../../../hooks/use-pinboard-data';
import { usePinboardHandler } from '../../../../hooks/use-pinboard-handler';
import type { BlockSuiteWorkspace } from '../../../../shared';
diff --git a/apps/web/src/components/affine/pinboard/pinboard-render/OperationButton.tsx b/apps/web/src/components/affine/pinboard/pinboard-render/OperationButton.tsx
index b15b5880dd..38e5f7fc66 100644
--- a/apps/web/src/components/affine/pinboard/pinboard-render/OperationButton.tsx
+++ b/apps/web/src/components/affine/pinboard/pinboard-render/OperationButton.tsx
@@ -10,7 +10,7 @@ import type { PageMeta } from '@blocksuite/store';
import { useTheme } from '@mui/material';
import { useMemo, useRef, useState } from 'react';
-import { useMetaHelper } from '../../../../hooks/affine/use-meta-helper';
+import { useBlockSuiteMetaHelper } from '../../../../hooks/affine/use-block-suite-meta-helper';
import type { BlockSuiteWorkspace } from '../../../../shared';
import { toast } from '../../../../utils';
import { CopyLink, MoveToTrash } from '../../operation-menu-items';
@@ -50,7 +50,7 @@ export const OperationButton = ({
const [pinboardMenuOpen, setPinboardMenuOpen] = useState(false);
const [confirmModalOpen, setConfirmModalOpen] = useState(false);
const menuIndex = useMemo(() => modalIndex + 1, [modalIndex]);
- const { removeToTrash } = useMetaHelper(blockSuiteWorkspace);
+ const { removeToTrash } = useBlockSuiteMetaHelper(blockSuiteWorkspace);
return (
<MuiClickAwayListener
diff --git a/apps/web/src/components/affine/pinboard/pinboard-render/index.tsx b/apps/web/src/components/affine/pinboard/pinboard-render/index.tsx
index c2d0d8edb8..2e6497634e 100644
--- a/apps/web/src/components/affine/pinboard/pinboard-render/index.tsx
+++ b/apps/web/src/components/affine/pinboard/pinboard-render/index.tsx
@@ -6,12 +6,12 @@ import {
PageIcon,
PivotsIcon,
} from '@blocksuite/icons';
+import { usePageMetaHelper } from '@toeverything/hooks/use-block-suite-page-meta';
import { useAtomValue } from 'jotai';
import { useRouter } from 'next/router';
import { useMemo, useState } from 'react';
import { workspacePreferredModeAtom } from '../../../../atoms';
-import { usePageMetaHelper } from '../../../../hooks/use-page-meta';
import type { PinboardNode } from '../../../../hooks/use-pinboard-data';
import { StyledCollapsedButton, StyledPinboard } from '../styles';
import EmptyItem from './EmptyItem';
diff --git a/apps/web/src/components/affine/workspace-setting-detail/panel/general/delete/index.tsx b/apps/web/src/components/affine/workspace-setting-detail/panel/general/delete/index.tsx
index f0d1bce038..a0f3dd12a2 100644
--- a/apps/web/src/components/affine/workspace-setting-detail/panel/general/delete/index.tsx
+++ b/apps/web/src/components/affine/workspace-setting-detail/panel/general/delete/index.tsx
@@ -1,7 +1,7 @@
import { Button, Input, Modal, ModalCloseButton } from '@affine/component';
import { Trans, useTranslation } from '@affine/i18n';
import { WorkspaceFlavour } from '@affine/workspace/type';
-import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-blocksuite-workspace-name';
+import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-block-suite-workspace-name';
import { useCallback, useState } from 'react';
import type { AffineOfficialWorkspace } from '../../../../../../shared';
diff --git a/apps/web/src/components/affine/workspace-setting-detail/panel/general/index.tsx b/apps/web/src/components/affine/workspace-setting-detail/panel/general/index.tsx
index 07574429c8..f571b0ca39 100644
--- a/apps/web/src/components/affine/workspace-setting-detail/panel/general/index.tsx
+++ b/apps/web/src/components/affine/workspace-setting-detail/panel/general/index.tsx
@@ -2,8 +2,8 @@ import { Button, FlexWrapper, MuiFade } from '@affine/component';
import { WorkspaceAvatar } from '@affine/component/workspace-avatar';
import { useTranslation } from '@affine/i18n';
import { WorkspaceFlavour } from '@affine/workspace/type';
-import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-blocksuite-workspace-avatar-url';
-import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-blocksuite-workspace-name';
+import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-block-suite-workspace-avatar-url';
+import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-block-suite-workspace-name';
import type React from 'react';
import { useState } from 'react';
diff --git a/apps/web/src/components/affine/workspace-setting-detail/panel/sync/index.tsx b/apps/web/src/components/affine/workspace-setting-detail/panel/sync/index.tsx
index d313c1ae93..4e1a30be7a 100644
--- a/apps/web/src/components/affine/workspace-setting-detail/panel/sync/index.tsx
+++ b/apps/web/src/components/affine/workspace-setting-detail/panel/sync/index.tsx
@@ -1,8 +1,8 @@
import { Content, FlexWrapper, styled } from '@affine/component';
import { Trans, useTranslation } from '@affine/i18n';
import { WorkspaceFlavour } from '@affine/workspace/type';
-import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-blocksuite-workspace-avatar-url';
-import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-blocksuite-workspace-name';
+import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-block-suite-workspace-avatar-url';
+import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-block-suite-workspace-name';
import type React from 'react';
import { useCurrentUser } from '../../../../../hooks/current/use-current-user';
diff --git a/apps/web/src/components/blocksuite/block-suite-page-list/page-list/index.tsx b/apps/web/src/components/blocksuite/block-suite-page-list/page-list/index.tsx
index ec059cf0e3..735ddd3b8a 100644
--- a/apps/web/src/components/blocksuite/block-suite-page-list/page-list/index.tsx
+++ b/apps/web/src/components/blocksuite/block-suite-page-list/page-list/index.tsx
@@ -17,16 +17,16 @@ import {
} from '@blocksuite/icons';
import type { PageMeta } from '@blocksuite/store';
import { useMediaQuery, useTheme } from '@mui/material';
+import {
+ useBlockSuitePageMeta,
+ usePageMetaHelper,
+} from '@toeverything/hooks/use-block-suite-page-meta';
import { useAtomValue } from 'jotai';
import type React from 'react';
import { useMemo } from 'react';
import { workspacePreferredModeAtom } from '../../../../atoms';
-import { useMetaHelper } from '../../../../hooks/affine/use-meta-helper';
-import {
- usePageMeta,
- usePageMetaHelper,
-} from '../../../../hooks/use-page-meta';
+import { useBlockSuiteMetaHelper } from '../../../../hooks/affine/use-block-suite-meta-helper';
import type { BlockSuiteWorkspace } from '../../../../shared';
import { toast } from '../../../../utils';
import DateCell from './DateCell';
@@ -101,10 +101,10 @@ export const PageList: React.FC<PageListProps> = ({
listType,
onClickPage,
}) => {
- const pageList = usePageMeta(blockSuiteWorkspace);
+ const pageList = useBlockSuitePageMeta(blockSuiteWorkspace);
const helper = usePageMetaHelper(blockSuiteWorkspace);
const { removeToTrash, restoreFromTrash } =
- useMetaHelper(blockSuiteWorkspace);
+ useBlockSuiteMetaHelper(blockSuiteWorkspace);
const { t } = useTranslation();
const theme = useTheme();
const matches = useMediaQuery(theme.breakpoints.up('sm'));
diff --git a/apps/web/src/components/blocksuite/workspace-header/editor-mode-switch/index.tsx b/apps/web/src/components/blocksuite/workspace-header/editor-mode-switch/index.tsx
index 42770045ca..4002aa39b2 100644
--- a/apps/web/src/components/blocksuite/workspace-header/editor-mode-switch/index.tsx
+++ b/apps/web/src/components/blocksuite/workspace-header/editor-mode-switch/index.tsx
@@ -1,9 +1,9 @@
import { assertExists } from '@blocksuite/store';
+import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page-meta';
import { useAtomValue, useSetAtom } from 'jotai';
import type { CSSProperties } from 'react';
import { workspacePreferredModeAtom } from '../../../../atoms';
-import { usePageMeta } from '../../../../hooks/use-page-meta';
import type { BlockSuiteWorkspace } from '../../../../shared';
import { toast } from '../../../../utils';
import { StyledEditorModeSwitch } from './style';
@@ -24,7 +24,7 @@ export const EditorModeSwitch = ({
const currentMode =
useAtomValue(workspacePreferredModeAtom)[pageId] ?? 'page';
const setMode = useSetAtom(workspacePreferredModeAtom);
- const pageMeta = usePageMeta(blockSuiteWorkspace).find(
+ const pageMeta = useBlockSuitePageMeta(blockSuiteWorkspace).find(
meta => meta.id === pageId
);
assertExists(pageMeta);
diff --git a/apps/web/src/components/blocksuite/workspace-header/header-right-items/EditorOptionMenu.tsx b/apps/web/src/components/blocksuite/workspace-header/header-right-items/EditorOptionMenu.tsx
index c336945b7e..3d14c8ca55 100644
--- a/apps/web/src/components/blocksuite/workspace-header/header-right-items/EditorOptionMenu.tsx
+++ b/apps/web/src/components/blocksuite/workspace-header/header-right-items/EditorOptionMenu.tsx
@@ -10,17 +10,17 @@ import {
} from '@blocksuite/icons';
import { assertExists } from '@blocksuite/store';
import { useTheme } from '@mui/material';
+import {
+ useBlockSuitePageMeta,
+ usePageMetaHelper,
+} from '@toeverything/hooks/use-block-suite-page-meta';
import { useAtom } from 'jotai';
import { useState } from 'react';
import { workspacePreferredModeAtom } from '../../../../atoms';
-import { useMetaHelper } from '../../../../hooks/affine/use-meta-helper';
+import { useBlockSuiteMetaHelper } from '../../../../hooks/affine/use-block-suite-meta-helper';
import { useCurrentPageId } from '../../../../hooks/current/use-current-page-id';
import { useCurrentWorkspace } from '../../../../hooks/current/use-current-workspace';
-import {
- usePageMeta,
- usePageMetaHelper,
-} from '../../../../hooks/use-page-meta';
import { toast } from '../../../../utils';
import {
Export,
@@ -38,17 +38,17 @@ export const EditorOptionMenu = () => {
assertExists(workspace);
assertExists(pageId);
const blockSuiteWorkspace = workspace.blockSuiteWorkspace;
- const pageMeta = usePageMeta(blockSuiteWorkspace).find(
+ const pageMeta = useBlockSuitePageMeta(blockSuiteWorkspace).find(
meta => meta.id === pageId
);
- const allMetas = usePageMeta(blockSuiteWorkspace);
+ const allMetas = useBlockSuitePageMeta(blockSuiteWorkspace);
const [record, set] = useAtom(workspacePreferredModeAtom);
const mode = record[pageId] ?? 'page';
assertExists(pageMeta);
const { favorite } = pageMeta;
const { setPageMeta } = usePageMetaHelper(blockSuiteWorkspace);
const [openConfirm, setOpenConfirm] = useState(false);
- const { removeToTrash } = useMetaHelper(blockSuiteWorkspace);
+ const { removeToTrash } = useBlockSuiteMetaHelper(blockSuiteWorkspace);
const EditMenu = (
<>
<MenuItem
diff --git a/apps/web/src/components/blocksuite/workspace-header/header-right-items/TrashButtonGroup.tsx b/apps/web/src/components/blocksuite/workspace-header/header-right-items/TrashButtonGroup.tsx
index 93bcab6dd6..98fba9e850 100644
--- a/apps/web/src/components/blocksuite/workspace-header/header-right-items/TrashButtonGroup.tsx
+++ b/apps/web/src/components/blocksuite/workspace-header/header-right-items/TrashButtonGroup.tsx
@@ -1,13 +1,13 @@
import { Button, Confirm } from '@affine/component';
import { useTranslation } from '@affine/i18n';
import { assertExists } from '@blocksuite/store';
+import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page-meta';
import { useRouter } from 'next/router';
import { useState } from 'react';
-import { useMetaHelper } from '../../../../hooks/affine/use-meta-helper';
+import { useBlockSuiteMetaHelper } from '../../../../hooks/affine/use-block-suite-meta-helper';
import { useCurrentPageId } from '../../../../hooks/current/use-current-page-id';
import { useCurrentWorkspace } from '../../../../hooks/current/use-current-workspace';
-import { usePageMeta } from '../../../../hooks/use-page-meta';
export const TrashButtonGroup = () => {
// fixme(himself65): remove these hooks ASAP
@@ -16,13 +16,13 @@ export const TrashButtonGroup = () => {
assertExists(workspace);
assertExists(pageId);
const blockSuiteWorkspace = workspace.blockSuiteWorkspace;
- const pageMeta = usePageMeta(blockSuiteWorkspace).find(
+ const pageMeta = useBlockSuitePageMeta(blockSuiteWorkspace).find(
meta => meta.id === pageId
);
assertExists(pageMeta);
const { t } = useTranslation();
const router = useRouter();
- const { restoreFromTrash } = useMetaHelper(blockSuiteWorkspace);
+ const { restoreFromTrash } = useBlockSuiteMetaHelper(blockSuiteWorkspace);
const [open, setOpen] = useState(false);
diff --git a/apps/web/src/components/blocksuite/workspace-header/index.tsx b/apps/web/src/components/blocksuite/workspace-header/index.tsx
index 1a25af5881..467accf319 100644
--- a/apps/web/src/components/blocksuite/workspace-header/index.tsx
+++ b/apps/web/src/components/blocksuite/workspace-header/index.tsx
@@ -3,13 +3,13 @@ import { QuickSearchTips } from '@affine/component';
import { getEnvironment } from '@affine/env';
import { ArrowDownSmallIcon } from '@blocksuite/icons';
import { assertExists } from '@blocksuite/store';
+import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page-meta';
import { useAtomValue, useSetAtom } from 'jotai';
import type { HTMLAttributes, PropsWithChildren } from 'react';
import { forwardRef, useCallback, useRef } from 'react';
import { currentEditorAtom, openQuickSearchModalAtom } from '../../../atoms';
import { useGuideHidden } from '../../../hooks/use-is-first-load';
-import { usePageMeta } from '../../../hooks/use-page-meta';
import { useElementResizeEffect } from '../../../hooks/use-workspaces';
import { QuickSearchButton } from '../../pure/quick-search-button';
import { EditorModeSwitch } from './editor-mode-switch';
@@ -34,7 +34,7 @@ export const WorkspaceHeader = forwardRef<
const { workspace, currentPage, children, isPublic } = props;
// fixme(himself65): remove this atom and move it to props
const setOpenQuickSearch = useSetAtom(openQuickSearchModalAtom);
- const pageMeta = usePageMeta(workspace.blockSuiteWorkspace).find(
+ const pageMeta = useBlockSuitePageMeta(workspace.blockSuiteWorkspace).find(
meta => meta.id === currentPage?.id
);
assertExists(pageMeta);
diff --git a/apps/web/src/components/page-detail-editor.tsx b/apps/web/src/components/page-detail-editor.tsx
index de4a30cac7..610d858e4d 100644
--- a/apps/web/src/components/page-detail-editor.tsx
+++ b/apps/web/src/components/page-detail-editor.tsx
@@ -1,14 +1,14 @@
import type { EditorContainer } from '@blocksuite/editor';
import type { Page } from '@blocksuite/store';
import { assertExists } from '@blocksuite/store';
-import { useBlockSuiteWorkspacePageTitle } from '@toeverything/hooks/use-blocksuite-workspace-page-title';
+import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page-meta';
+import { useBlockSuiteWorkspacePageTitle } from '@toeverything/hooks/use-block-suite-workspace-page-title';
import { useAtomValue, useSetAtom } from 'jotai';
import Head from 'next/head';
import type React from 'react';
import { startTransition, useCallback } from 'react';
import { currentEditorAtom, workspacePreferredModeAtom } from '../atoms';
-import { usePageMeta } from '../hooks/use-page-meta';
import type { AffineOfficialWorkspace } from '../shared';
import { PageNotFoundError } from './affine/affine-error-eoundary';
import { BlockSuiteEditor as Editor } from './blocksuite/block-suite-editor';
@@ -39,7 +39,7 @@ export const PageDetailEditor: React.FC<PageDetailEditorProps> = ({
throw new PageNotFoundError(blockSuiteWorkspace, pageId);
}
const title = useBlockSuiteWorkspacePageTitle(blockSuiteWorkspace, pageId);
- const meta = usePageMeta(blockSuiteWorkspace).find(
+ const meta = useBlockSuitePageMeta(blockSuiteWorkspace).find(
meta => meta.id === pageId
);
const currentMode =
diff --git a/apps/web/src/components/pure/quick-search-modal/Footer.tsx b/apps/web/src/components/pure/quick-search-modal/Footer.tsx
index 9b8bac8677..6602956eba 100644
--- a/apps/web/src/components/pure/quick-search-modal/Footer.tsx
+++ b/apps/web/src/components/pure/quick-search-modal/Footer.tsx
@@ -3,12 +3,12 @@ import { useTranslation } from '@affine/i18n';
import type { PageBlockModel } from '@blocksuite/blocks';
import { PlusIcon } from '@blocksuite/icons';
import { assertEquals, nanoid } from '@blocksuite/store';
+import { useBlockSuiteWorkspaceHelper } from '@toeverything/hooks/use-block-suite-workspace-helper';
import { Command } from 'cmdk';
import type { NextRouter } from 'next/router';
import type React from 'react';
import { useCallback } from 'react';
-import { useBlockSuiteWorkspaceHelper } from '../../../hooks/use-blocksuite-workspace-helper';
import { useRouterHelper } from '../../../hooks/use-router-helper';
import type { BlockSuiteWorkspace } from '../../../shared';
import { StyledModalFooterContent } from './style';
diff --git a/apps/web/src/components/pure/quick-search-modal/PublishedResults.tsx b/apps/web/src/components/pure/quick-search-modal/PublishedResults.tsx
index c8bbc799d6..68079a1742 100644
--- a/apps/web/src/components/pure/quick-search-modal/PublishedResults.tsx
+++ b/apps/web/src/components/pure/quick-search-modal/PublishedResults.tsx
@@ -1,12 +1,12 @@
import { useTranslation } from '@affine/i18n';
import { EdgelessIcon, PageIcon } from '@blocksuite/icons';
+import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page-meta';
import { Command } from 'cmdk';
import Image from 'next/legacy/image';
import { useRouter } from 'next/router';
import type { FC } from 'react';
import { useEffect, useMemo, useState } from 'react';
-import { usePageMeta } from '../../../hooks/use-page-meta';
import type { BlockSuiteWorkspace } from '../../../shared';
import { StyledListItem, StyledNotFound } from './style';
@@ -26,7 +26,7 @@ export const PublishedResults: FC<PublishedResultsProps> = ({
}) => {
const [results, setResults] = useState(new Map<string, string | undefined>());
const router = useRouter();
- const pageList = usePageMeta(blockSuiteWorkspace);
+ const pageList = useBlockSuitePageMeta(blockSuiteWorkspace);
// useEffect(() => {
// dataCenter
// .loadPublicWorkspace(router.query.workspaceId as string)
diff --git a/apps/web/src/components/pure/quick-search-modal/Results.tsx b/apps/web/src/components/pure/quick-search-modal/Results.tsx
index 3f656d316f..c0d36f0eab 100644
--- a/apps/web/src/components/pure/quick-search-modal/Results.tsx
+++ b/apps/web/src/components/pure/quick-search-modal/Results.tsx
@@ -2,14 +2,14 @@ import { UNTITLED_WORKSPACE_NAME } from '@affine/env';
import { useTranslation } from '@affine/i18n';
import { EdgelessIcon, PageIcon } from '@blocksuite/icons';
import { assertExists } from '@blocksuite/store';
+import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page-meta';
+import { useBlockSuiteWorkspaceHelper } from '@toeverything/hooks/use-block-suite-workspace-helper';
import { Command } from 'cmdk';
import Image from 'next/legacy/image';
import type { NextRouter } from 'next/router';
import type { Dispatch, FC, SetStateAction } from 'react';
import { useEffect } from 'react';
-import { useBlockSuiteWorkspaceHelper } from '../../../hooks/use-blocksuite-workspace-helper';
-import { usePageMeta } from '../../../hooks/use-page-meta';
import { useRecentlyViewed } from '../../../hooks/use-recent-views';
import { useRouterHelper } from '../../../hooks/use-router-helper';
import type { BlockSuiteWorkspace } from '../../../shared';
@@ -31,7 +31,7 @@ export const Results: FC<ResultsProps> = ({
onClose,
}) => {
useBlockSuiteWorkspaceHelper(blockSuiteWorkspace);
- const pageList = usePageMeta(blockSuiteWorkspace);
+ const pageList = useBlockSuitePageMeta(blockSuiteWorkspace);
assertExists(blockSuiteWorkspace.id);
const List = useSwitchToConfig(blockSuiteWorkspace.id);
diff --git a/apps/web/src/components/pure/quick-search-modal/navigation-path/index.tsx b/apps/web/src/components/pure/quick-search-modal/navigation-path/index.tsx
index d28e916785..79fe2b11e7 100644
--- a/apps/web/src/components/pure/quick-search-modal/navigation-path/index.tsx
+++ b/apps/web/src/components/pure/quick-search-modal/navigation-path/index.tsx
@@ -7,11 +7,11 @@ import {
MoreHorizontalIcon,
} from '@blocksuite/icons';
import type { PageMeta } from '@blocksuite/store';
+import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page-meta';
import { useRouter } from 'next/router';
import type { MouseEvent } from 'react';
import { Fragment, useCallback, useMemo, useState } from 'react';
-import { usePageMeta } from '../../../../hooks/use-page-meta';
import type { PinboardNode } from '../../../../hooks/use-pinboard-data';
import { usePinboardData } from '../../../../hooks/use-pinboard-data';
import { useRouterHelper } from '../../../../hooks/use-router-helper';
@@ -33,7 +33,7 @@ export const NavigationPath = ({
pageId?: string;
onJumpToPage?: (pageId: string) => void;
}) => {
- const metas = usePageMeta(blockSuiteWorkspace);
+ const metas = useBlockSuitePageMeta(blockSuiteWorkspace);
const router = useRouter();
const { t } = useTranslation();
diff --git a/apps/web/src/components/pure/workspace-slider-bar/Pinboard.tsx b/apps/web/src/components/pure/workspace-slider-bar/Pinboard.tsx
index 170322306c..4c370804bf 100644
--- a/apps/web/src/components/pure/workspace-slider-bar/Pinboard.tsx
+++ b/apps/web/src/components/pure/workspace-slider-bar/Pinboard.tsx
@@ -1,5 +1,5 @@
import { TreeView } from '@affine/component';
-import type { PageMeta } from '@blocksuite/store';
+import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page-meta';
import type { MouseEvent } from 'react';
import { useCallback } from 'react';
@@ -12,14 +12,10 @@ import { PinboardRender } from '../../affine/pinboard';
export type PinboardProps = {
blockSuiteWorkspace: BlockSuiteWorkspace;
openPage: (pageId: string) => void;
- allMetas: PageMeta[];
};
-export const Pinboard = ({
- blockSuiteWorkspace,
- openPage,
- allMetas,
-}: PinboardProps) => {
+export const Pinboard = ({ blockSuiteWorkspace, openPage }: PinboardProps) => {
+ const allMetas = useBlockSuitePageMeta(blockSuiteWorkspace);
const handlePinboardClick = useCallback(
(e: MouseEvent<HTMLDivElement>, node: PinboardNode) => {
openPage(node.id);
diff --git a/apps/web/src/components/pure/workspace-slider-bar/WorkspaceSelector/WorkspaceSelector.tsx b/apps/web/src/components/pure/workspace-slider-bar/WorkspaceSelector/WorkspaceSelector.tsx
index 27de8f0d54..cd7a494419 100644
--- a/apps/web/src/components/pure/workspace-slider-bar/WorkspaceSelector/WorkspaceSelector.tsx
+++ b/apps/web/src/components/pure/workspace-slider-bar/WorkspaceSelector/WorkspaceSelector.tsx
@@ -1,6 +1,6 @@
import { WorkspaceAvatar } from '@affine/component/workspace-avatar';
import { CloudWorkspaceIcon, LocalWorkspaceIcon } from '@blocksuite/icons';
-import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-blocksuite-workspace-name';
+import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-block-suite-workspace-name';
import type React from 'react';
import { useCurrentWorkspace } from '../../../../hooks/current/use-current-workspace';
diff --git a/apps/web/src/components/pure/workspace-slider-bar/favorite/index.tsx b/apps/web/src/components/pure/workspace-slider-bar/favorite/index.tsx
index 068471f551..d2167e2374 100644
--- a/apps/web/src/components/pure/workspace-slider-bar/favorite/index.tsx
+++ b/apps/web/src/components/pure/workspace-slider-bar/favorite/index.tsx
@@ -1,12 +1,14 @@
import { useTranslation } from '@affine/i18n';
import { ArrowDownSmallIcon, FavoriteIcon } from '@blocksuite/icons';
+import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page-meta';
import { useCallback, useState } from 'react';
-import { usePageMeta } from '../../../../hooks/use-page-meta';
+import type { AllWorkspace } from '../../../../shared';
import type { WorkSpaceSliderBarProps } from '../index';
import { StyledCollapseButton, StyledListItem } from '../shared-styles';
import { StyledLink } from '../style';
import FavoriteList from './favorite-list';
+
export const Favorite = ({
currentPath,
paths,
@@ -15,10 +17,12 @@ export const Favorite = ({
currentWorkspace,
}: Pick<
WorkSpaceSliderBarProps,
- 'currentPath' | 'paths' | 'currentPageId' | 'openPage' | 'currentWorkspace'
->) => {
- const currentWorkspaceId = currentWorkspace?.id || null;
- const pageMeta = usePageMeta(currentWorkspace?.blockSuiteWorkspace ?? null);
+ 'currentPath' | 'paths' | 'currentPageId' | 'openPage'
+> & {
+ currentWorkspace: AllWorkspace;
+}) => {
+ const currentWorkspaceId = currentWorkspace.id;
+ const pageMeta = useBlockSuitePageMeta(currentWorkspace.blockSuiteWorkspace);
const [showSubFavorite, setOpenSubFavorite] = useState(true);
diff --git a/apps/web/src/components/pure/workspace-slider-bar/index.tsx b/apps/web/src/components/pure/workspace-slider-bar/index.tsx
index 9ce37b6f8d..24cc6293d2 100644
--- a/apps/web/src/components/pure/workspace-slider-bar/index.tsx
+++ b/apps/web/src/components/pure/workspace-slider-bar/index.tsx
@@ -14,7 +14,6 @@ import type React from 'react';
import type { UIEvent } from 'react';
import { lazy, Suspense, useCallback, useEffect, useState } from 'react';
-import { usePageMeta } from '../../../hooks/use-page-meta';
import {
useSidebarFloating,
useSidebarResizing,
@@ -85,7 +84,6 @@ export const WorkSpaceSliderBar: React.FC<WorkSpaceSliderBarProps> = ({
const blockSuiteWorkspace = currentWorkspace?.blockSuiteWorkspace;
const { t } = useTranslation();
const [sidebarOpen, setSidebarOpen] = useSidebarStatus();
- const pageMeta = usePageMeta(blockSuiteWorkspace ?? null);
const onClickNewPage = useCallback(async () => {
const page = await createPage();
openPage(page.id);
@@ -190,18 +188,19 @@ export const WorkSpaceSliderBar: React.FC<WorkSpaceSliderBarProps> = ({
: setIsScrollAtTop(false);
}}
>
- <Favorite
- currentPath={currentPath}
- paths={paths}
- currentPageId={currentPageId}
- openPage={openPage}
- currentWorkspace={currentWorkspace}
- />
- {!!blockSuiteWorkspace && (
+ {blockSuiteWorkspace && (
+ <Favorite
+ currentPath={currentPath}
+ paths={paths}
+ currentPageId={currentPageId}
+ openPage={openPage}
+ currentWorkspace={currentWorkspace}
+ />
+ )}
+ {blockSuiteWorkspace && (
<Pinboard
blockSuiteWorkspace={blockSuiteWorkspace}
openPage={openPage}
- allMetas={pageMeta}
/>
)}
</StyledScrollWrapper>
diff --git a/apps/web/src/hooks/__tests__/index.spec.tsx b/apps/web/src/hooks/__tests__/index.spec.tsx
index 4a138feeb5..8dbf9b238f 100644
--- a/apps/web/src/hooks/__tests__/index.spec.tsx
+++ b/apps/web/src/hooks/__tests__/index.spec.tsx
@@ -16,6 +16,10 @@ import { __unstableSchemas, AffineSchemas } from '@blocksuite/blocks/models';
import type { Page } from '@blocksuite/store';
import { assertExists } from '@blocksuite/store';
import { render, renderHook } from '@testing-library/react';
+import {
+ useBlockSuitePageMeta,
+ usePageMetaHelper,
+} from '@toeverything/hooks/use-block-suite-page-meta';
import { createStore, Provider } from 'jotai';
import { useRouter } from 'next/router';
import routerMock from 'next-router-mock';
@@ -36,7 +40,6 @@ import {
useLastVersion,
useTipsDisplayStatus,
} from '../use-is-first-load';
-import { usePageMeta, usePageMetaHelper } from '../use-page-meta';
import {
useRecentlyViewed,
useSyncRecentViewsWithRouter,
@@ -103,7 +106,7 @@ beforeEach(async () => {
describe('usePageMetas', async () => {
test('basic', async () => {
const Component = () => {
- const pageMetas = usePageMeta(blockSuiteWorkspace);
+ const pageMetas = useBlockSuitePageMeta(blockSuiteWorkspace);
return (
<div>
{pageMetas.map(meta => (
@@ -121,7 +124,7 @@ describe('usePageMetas', async () => {
test('mutation', () => {
const { result, rerender } = renderHook(() =>
- usePageMeta(blockSuiteWorkspace)
+ useBlockSuitePageMeta(blockSuiteWorkspace)
);
expect(result.current.length).toBe(3);
expect(result.current[0].mode).not.exist;
@@ -143,7 +146,7 @@ describe('usePageMetas', async () => {
test('update title', () => {
const { result, rerender } = renderHook(() =>
- usePageMeta(blockSuiteWorkspace)
+ useBlockSuitePageMeta(blockSuiteWorkspace)
);
expect(result.current.length).toBe(3);
expect(result.current[0].mode).not.exist;
@@ -260,7 +263,7 @@ describe('useRecentlyViewed', () => {
});
routerHook.rerender();
const syncHook = renderHook(
- router => useSyncRecentViewsWithRouter(router),
+ router => useSyncRecentViewsWithRouter(router, blockSuiteWorkspace),
{
wrapper: ProviderWrapper,
initialProps: routerHook.result.current,
diff --git a/apps/web/src/hooks/affine/use-meta-helper.ts b/apps/web/src/hooks/affine/use-block-suite-meta-helper.ts
similarity index 87%
rename from apps/web/src/hooks/affine/use-meta-helper.ts
rename to apps/web/src/hooks/affine/use-block-suite-meta-helper.ts
index a06957ab31..a838495307 100644
--- a/apps/web/src/hooks/affine/use-meta-helper.ts
+++ b/apps/web/src/hooks/affine/use-block-suite-meta-helper.ts
@@ -1,11 +1,16 @@
+import {
+ useBlockSuitePageMeta,
+ usePageMetaHelper,
+} from '@toeverything/hooks/use-block-suite-page-meta';
import { useCallback } from 'react';
import type { BlockSuiteWorkspace } from '../../shared';
-import { usePageMeta, usePageMetaHelper } from '../use-page-meta';
-export function useMetaHelper(blockSuiteWorkspace: BlockSuiteWorkspace | null) {
+export function useBlockSuiteMetaHelper(
+ blockSuiteWorkspace: BlockSuiteWorkspace
+) {
const { setPageMeta, getPageMeta } = usePageMetaHelper(blockSuiteWorkspace);
- const metas = usePageMeta(blockSuiteWorkspace);
+ const metas = useBlockSuitePageMeta(blockSuiteWorkspace);
const removeToTrash = useCallback(
(pageId: string, isRoot = true) => {
diff --git a/apps/web/src/hooks/current/use-current-workspace.ts b/apps/web/src/hooks/current/use-current-workspace.ts
index 632a47ff0c..5345ac8209 100644
--- a/apps/web/src/hooks/current/use-current-workspace.ts
+++ b/apps/web/src/hooks/current/use-current-workspace.ts
@@ -17,7 +17,7 @@ export const lastWorkspaceIdAtom = atomWithSyncStorage<string | null>(
);
export function useCurrentWorkspace(): [
- AllWorkspace | null,
+ AllWorkspace,
(id: string | null) => void
] {
const currentWorkspace = useAtomValue(rootCurrentWorkspaceAtom);
diff --git a/apps/web/src/hooks/use-pinboard-handler.ts b/apps/web/src/hooks/use-pinboard-handler.ts
index 1e5874f798..88b0fe619f 100644
--- a/apps/web/src/hooks/use-pinboard-handler.ts
+++ b/apps/web/src/hooks/use-pinboard-handler.ts
@@ -2,12 +2,12 @@ import type { TreeViewProps } from '@affine/component';
import { DebugLogger } from '@affine/debug';
import type { PageMeta } from '@blocksuite/store';
import { nanoid } from '@blocksuite/store';
+import { usePageMetaHelper } from '@toeverything/hooks/use-block-suite-page-meta';
+import { useBlockSuiteWorkspaceHelper } from '@toeverything/hooks/use-block-suite-workspace-helper';
import { useCallback } from 'react';
import type { BlockSuiteWorkspace } from '../shared';
-import { useMetaHelper } from './affine/use-meta-helper';
-import { useBlockSuiteWorkspaceHelper } from './use-blocksuite-workspace-helper';
-import { usePageMetaHelper } from './use-page-meta';
+import { useBlockSuiteMetaHelper } from './affine/use-block-suite-meta-helper';
import type { NodeRenderProps } from './use-pinboard-data';
const logger = new DebugLogger('pinboard');
@@ -26,7 +26,7 @@ export function usePinboardHandler({
onDelete,
onDrop,
}: {
- blockSuiteWorkspace: BlockSuiteWorkspace | null;
+ blockSuiteWorkspace: BlockSuiteWorkspace;
metas: PageMeta[];
onAdd?: (addedId: string, parentId: string) => void;
onDelete?: TreeViewProps<NodeRenderProps>['onDelete'];
@@ -35,7 +35,7 @@ export function usePinboardHandler({
const { createPage } = useBlockSuiteWorkspaceHelper(blockSuiteWorkspace);
const { setPageMeta } = usePageMetaHelper(blockSuiteWorkspace);
const { removeToTrash: removeToTrashHelper } =
- useMetaHelper(blockSuiteWorkspace);
+ useBlockSuiteMetaHelper(blockSuiteWorkspace);
// Just need handle add operation, delete check is handled in blockSuite's reference link
const addReferenceLink = useCallback(
(pageId: string, referenceId: string) => {
diff --git a/apps/web/src/hooks/use-recent-views.ts b/apps/web/src/hooks/use-recent-views.ts
index 778903478c..5a9d1c312a 100644
--- a/apps/web/src/hooks/use-recent-views.ts
+++ b/apps/web/src/hooks/use-recent-views.ts
@@ -1,3 +1,5 @@
+import type { Workspace } from '@blocksuite/store';
+import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page-meta';
import { useAtomValue, useSetAtom } from 'jotai';
import type { NextRouter } from 'next/router';
import { useEffect } from 'react';
@@ -8,7 +10,6 @@ import {
workspaceRecentViresWriteAtom,
} from '../atoms';
import { useCurrentWorkspace } from './current/use-current-workspace';
-import { usePageMeta } from './use-page-meta';
export function useRecentlyViewed() {
const [workspace] = useCurrentWorkspace();
@@ -19,13 +20,14 @@ export function useRecentlyViewed() {
return recentlyViewed[workspaceId] ?? [];
}
-export function useSyncRecentViewsWithRouter(router: NextRouter) {
- const [workspace] = useCurrentWorkspace();
- const workspaceId = workspace?.id || null;
- const blockSuiteWorkspace = workspace?.blockSuiteWorkspace || null;
+export function useSyncRecentViewsWithRouter(
+ router: NextRouter,
+ blockSuiteWorkspace: Workspace
+) {
+ const workspaceId = blockSuiteWorkspace.id;
const pageId = router.query.pageId;
const set = useSetAtom(workspaceRecentViresWriteAtom);
- const meta = usePageMeta(blockSuiteWorkspace).find(
+ const meta = useBlockSuitePageMeta(blockSuiteWorkspace).find(
meta => meta.id === pageId
);
const currentMode = useAtomValue(workspacePreferredModeAtom)[
diff --git a/apps/web/src/hooks/use-router-helper.ts b/apps/web/src/hooks/use-router-helper.ts
index 29ff3a7ff7..9232e09878 100644
--- a/apps/web/src/hooks/use-router-helper.ts
+++ b/apps/web/src/hooks/use-router-helper.ts
@@ -25,26 +25,6 @@ export function useRouterHelper(router: NextRouter) {
},
[router]
);
- const jumpToWorkspace = useCallback(
- (workspaceId: string, logic: RouteLogic = RouteLogic.PUSH) => {
- if (router.pathname === '/workspace/[workspaceId]/[pageId]') {
- return router[logic]({
- pathname: `/workspace/[workspaceId]`,
- query: {
- workspaceId: workspaceId,
- },
- });
- } else {
- return router[logic]({
- pathname: router.pathname,
- query: {
- workspaceId: workspaceId,
- },
- });
- }
- },
- [router]
- );
const jumpToPublicWorkspacePage = useCallback(
(
workspaceId: string,
@@ -91,7 +71,6 @@ export function useRouterHelper(router: NextRouter) {
return {
jumpToPage,
- jumpToWorkspace,
jumpToPublicWorkspacePage,
jumpToSubPath,
openPage,
diff --git a/apps/web/src/layouts/workspace-layout.tsx b/apps/web/src/layouts/workspace-layout.tsx
index 2c5790e4ac..327158c07f 100644
--- a/apps/web/src/layouts/workspace-layout.tsx
+++ b/apps/web/src/layouts/workspace-layout.tsx
@@ -12,6 +12,7 @@ import {
import type { LocalIndexedDBProvider } from '@affine/workspace/type';
import { WorkspaceFlavour } from '@affine/workspace/type';
import { assertEquals, assertExists, nanoid } from '@blocksuite/store';
+import { useBlockSuiteWorkspaceHelper } from '@toeverything/hooks/use-block-suite-workspace-helper';
import { useAtom, useAtomValue, useSetAtom } from 'jotai';
import Head from 'next/head';
import { useRouter } from 'next/router';
@@ -27,7 +28,6 @@ import { HelpIsland } from '../components/pure/help-island';
import { PageLoading } from '../components/pure/loading';
import WorkSpaceSliderBar from '../components/pure/workspace-slider-bar';
import { useCurrentWorkspace } from '../hooks/current/use-current-workspace';
-import { useBlockSuiteWorkspaceHelper } from '../hooks/use-blocksuite-workspace-helper';
import { useRouterHelper } from '../hooks/use-router-helper';
import { useRouterTitle } from '../hooks/use-router-title';
import { useRouterWithWorkspaceIdDefense } from '../hooks/use-router-with-workspace-id-defense';
@@ -341,7 +341,7 @@ export const WorkspaceLayoutInner: FC<PropsWithChildren> = ({ children }) => {
const { openPage } = useRouterHelper(router);
const [, setOpenWorkspacesModal] = useAtom(openWorkspacesModalAtom);
const helper = useBlockSuiteWorkspaceHelper(
- currentWorkspace?.blockSuiteWorkspace ?? null
+ currentWorkspace.blockSuiteWorkspace
);
const isPublicWorkspace =
router.pathname.split('/')[1] === 'public-workspace';
@@ -393,16 +393,11 @@ export const WorkspaceLayoutInner: FC<PropsWithChildren> = ({ children }) => {
);
}, [setIsResizing, setSidebarOpen, setSliderWidth]);
- const Provider = currentWorkspace
- ? WorkspacePlugins[currentWorkspace.flavour].UI.Provider
- : DefaultProvider;
+ const Provider =
+ WorkspacePlugins[currentWorkspace.flavour].UI.Provider ?? DefaultProvider;
return (
- <Provider
- key={`${
- currentWorkspace ? currentWorkspace.flavour : 'default'
- }-provider`}
- >
+ <Provider>
<Head>
<title>{title}</title>
</Head>
diff --git a/apps/web/src/pages/public-workspace/[workspaceId].tsx b/apps/web/src/pages/public-workspace/[workspaceId].tsx
index 1ea6f17a9e..0757d94873 100644
--- a/apps/web/src/pages/public-workspace/[workspaceId].tsx
+++ b/apps/web/src/pages/public-workspace/[workspaceId].tsx
@@ -1,7 +1,7 @@
import { Breadcrumbs, IconButton, ListSkeleton } from '@affine/component';
import { SearchIcon } from '@blocksuite/icons';
-import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-blocksuite-workspace-avatar-url';
-import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-blocksuite-workspace-name';
+import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-block-suite-workspace-avatar-url';
+import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-block-suite-workspace-name';
import { useAtomValue, useSetAtom } from 'jotai';
import { useRouter } from 'next/router';
import type React from 'react';
diff --git a/apps/web/src/pages/public-workspace/[workspaceId]/[pageId].tsx b/apps/web/src/pages/public-workspace/[workspaceId]/[pageId].tsx
index 7f44dfbc78..b2cd698039 100644
--- a/apps/web/src/pages/public-workspace/[workspaceId]/[pageId].tsx
+++ b/apps/web/src/pages/public-workspace/[workspaceId]/[pageId].tsx
@@ -3,8 +3,8 @@ import { initPage } from '@affine/env/blocksuite';
import { useTranslation } from '@affine/i18n';
import { PageIcon } from '@blocksuite/icons';
import { assertExists } from '@blocksuite/store';
-import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-blocksuite-workspace-avatar-url';
-import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-blocksuite-workspace-name';
+import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-block-suite-workspace-avatar-url';
+import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-block-suite-workspace-name';
import { useAtom, useAtomValue } from 'jotai';
import Link from 'next/link';
import { useRouter } from 'next/router';
diff --git a/apps/web/src/pages/workspace/[workspaceId]/[pageId].tsx b/apps/web/src/pages/workspace/[workspaceId]/[pageId].tsx
index 4149a2983f..fb74348073 100644
--- a/apps/web/src/pages/workspace/[workspaceId]/[pageId].tsx
+++ b/apps/web/src/pages/workspace/[workspaceId]/[pageId].tsx
@@ -1,7 +1,11 @@
import { rootCurrentPageIdAtom } from '@affine/workspace/atom';
import { WorkspaceFlavour } from '@affine/workspace/type';
import { assertExists } from '@blocksuite/store';
-import { useBlockSuiteWorkspacePage } from '@toeverything/hooks/use-blocksuite-workspace-page';
+import {
+ useBlockSuitePageMeta,
+ usePageMetaHelper,
+} from '@toeverything/hooks/use-block-suite-page-meta';
+import { useBlockSuiteWorkspacePage } from '@toeverything/hooks/use-block-suite-workspace-page';
import { useAtomValue } from 'jotai';
import { useRouter } from 'next/router';
import type React from 'react';
@@ -12,7 +16,6 @@ import { Unreachable } from '../../../components/affine/affine-error-eoundary';
import { PageLoading } from '../../../components/pure/loading';
import { useReferenceLinkEffect } from '../../../hooks/affine/use-reference-link-effect';
import { useCurrentWorkspace } from '../../../hooks/current/use-current-workspace';
-import { usePageMeta, usePageMetaHelper } from '../../../hooks/use-page-meta';
import { usePinboardHandler } from '../../../hooks/use-pinboard-handler';
import { useSyncRecentViewsWithRouter } from '../../../hooks/use-recent-views';
import { useRouterAndWorkspaceWithPageIdDefense } from '../../../hooks/use-router-and-workspace-with-page-id-defense';
@@ -37,14 +40,15 @@ const WorkspaceDetail: React.FC = () => {
const { openPage } = useRouterHelper(router);
const currentPageId = useAtomValue(rootCurrentPageIdAtom);
const [currentWorkspace] = useCurrentWorkspace();
- const blockSuiteWorkspace = currentWorkspace?.blockSuiteWorkspace ?? null;
+ assertExists(currentWorkspace);
+ const blockSuiteWorkspace = currentWorkspace.blockSuiteWorkspace;
const { setPageMeta, getPageMeta } = usePageMetaHelper(blockSuiteWorkspace);
const { deletePin } = usePinboardHandler({
blockSuiteWorkspace,
- metas: usePageMeta(currentWorkspace?.blockSuiteWorkspace ?? null ?? null),
+ metas: useBlockSuitePageMeta(currentWorkspace.blockSuiteWorkspace),
});
- useSyncRecentViewsWithRouter(router);
+ useSyncRecentViewsWithRouter(router, blockSuiteWorkspace);
useReferenceLinkEffect({
pageLinkClicked: useCallback(
@@ -79,9 +83,6 @@ const WorkspaceDetail: React.FC = () => {
enableFullFlags(currentWorkspace.blockSuiteWorkspace);
}
}, [currentWorkspace]);
- if (currentWorkspace === null) {
- return <PageLoading />;
- }
if (!currentPageId) {
return <PageLoading text="Loading page." />;
}
diff --git a/apps/web/src/pages/workspace/[workspaceId]/all.tsx b/apps/web/src/pages/workspace/[workspaceId]/all.tsx
index a1ac34d8a4..ea3d772c22 100644
--- a/apps/web/src/pages/workspace/[workspaceId]/all.tsx
+++ b/apps/web/src/pages/workspace/[workspaceId]/all.tsx
@@ -42,9 +42,6 @@ const AllPage: NextPageWithLayout = () => {
if (typeof router.query.workspaceId !== 'string') {
throw new QueryParamError('workspaceId', router.query.workspaceId);
}
- if (currentWorkspace === null) {
- return <PageLoading />;
- }
if (currentWorkspace.flavour === WorkspaceFlavour.AFFINE) {
const PageList = WorkspacePlugins[currentWorkspace.flavour].UI.PageList;
return (
diff --git a/packages/component/src/components/share-menu/ShareMenu.tsx b/packages/component/src/components/share-menu/ShareMenu.tsx
index c5338ee5af..61bc83d127 100644
--- a/packages/component/src/components/share-menu/ShareMenu.tsx
+++ b/packages/component/src/components/share-menu/ShareMenu.tsx
@@ -1,7 +1,7 @@
import type { AffineWorkspace, LocalWorkspace } from '@affine/workspace/type';
import { ExportIcon, PublishIcon, ShareIcon } from '@blocksuite/icons';
import type { Page } from '@blocksuite/store';
-import { useBlockSuiteWorkspacePageIsPublic } from '@toeverything/hooks/use-blocksuite-workspace-page-is-public';
+import { useBlockSuiteWorkspacePageIsPublic } from '@toeverything/hooks/use-block-suite-workspace-page-is-public';
import type { FC } from 'react';
import { useRef } from 'react';
import { useCallback, useState } from 'react';
diff --git a/packages/component/src/components/share-menu/SharePage.tsx b/packages/component/src/components/share-menu/SharePage.tsx
index 50c8bb9f59..d6d2df72c4 100644
--- a/packages/component/src/components/share-menu/SharePage.tsx
+++ b/packages/component/src/components/share-menu/SharePage.tsx
@@ -2,7 +2,7 @@ import { prefixUrl } from '@affine/env';
import { Trans, useTranslation } from '@affine/i18n';
import type { LocalWorkspace } from '@affine/workspace/type';
import { WorkspaceFlavour } from '@affine/workspace/type';
-import { useBlockSuiteWorkspacePageIsPublic } from '@toeverything/hooks/use-blocksuite-workspace-page-is-public';
+import { useBlockSuiteWorkspacePageIsPublic } from '@toeverything/hooks/use-block-suite-workspace-page-is-public';
import type { FC } from 'react';
import { useState } from 'react';
import { useCallback, useMemo } from 'react';
diff --git a/packages/component/src/components/share-menu/disable-public-link/index.tsx b/packages/component/src/components/share-menu/disable-public-link/index.tsx
index 567daa110f..0d7b945af2 100644
--- a/packages/component/src/components/share-menu/disable-public-link/index.tsx
+++ b/packages/component/src/components/share-menu/disable-public-link/index.tsx
@@ -1,6 +1,6 @@
import { useTranslation } from '@affine/i18n';
import type { Page } from '@blocksuite/store';
-import { useBlockSuiteWorkspacePageIsPublic } from '@toeverything/hooks/use-blocksuite-workspace-page-is-public';
+import { useBlockSuiteWorkspacePageIsPublic } from '@toeverything/hooks/use-block-suite-workspace-page-is-public';
import { useCallback } from 'react';
import { Modal, ModalCloseButton, toast } from '../../..';
diff --git a/packages/component/src/components/workspace-avatar/index.tsx b/packages/component/src/components/workspace-avatar/index.tsx
index 8eafdf7b34..7bab7a8e9c 100644
--- a/packages/component/src/components/workspace-avatar/index.tsx
+++ b/packages/component/src/components/workspace-avatar/index.tsx
@@ -5,8 +5,8 @@ import type {
} from '@affine/workspace/type';
import type { Workspace } from '@blocksuite/store';
import * as RadixAvatar from '@radix-ui/react-avatar';
-import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-blocksuite-workspace-avatar-url';
-import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-blocksuite-workspace-name';
+import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-block-suite-workspace-avatar-url';
+import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-block-suite-workspace-name';
import clsx from 'clsx';
import type React from 'react';
diff --git a/packages/component/src/components/workspace-card/index.tsx b/packages/component/src/components/workspace-card/index.tsx
index d2ecba795b..2bbf86a332 100644
--- a/packages/component/src/components/workspace-card/index.tsx
+++ b/packages/component/src/components/workspace-card/index.tsx
@@ -3,7 +3,7 @@ import { PermissionType } from '@affine/workspace/affine/api';
import type { AffineWorkspace, LocalWorkspace } from '@affine/workspace/type';
import { WorkspaceFlavour } from '@affine/workspace/type';
import { SettingsIcon } from '@blocksuite/icons';
-import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-blocksuite-workspace-name';
+import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-block-suite-workspace-name';
import type { FC, MouseEvent } from 'react';
import { useCallback } from 'react';
diff --git a/packages/hooks/src/__tests__/index.spec.ts b/packages/hooks/src/__tests__/index.spec.ts
index e7fac359ad..b10ba5c96a 100644
--- a/packages/hooks/src/__tests__/index.spec.ts
+++ b/packages/hooks/src/__tests__/index.spec.ts
@@ -8,12 +8,12 @@ import type { Page } from '@blocksuite/store';
import { assertExists } from '@blocksuite/store';
import { Workspace as BlockSuiteWorkspace } from '@blocksuite/store';
import { renderHook } from '@testing-library/react';
-import { useBlockSuiteWorkspacePageIsPublic } from '@toeverything/hooks/use-blocksuite-workspace-page-is-public';
-import { useBlockSuiteWorkspacePageTitle } from '@toeverything/hooks/use-blocksuite-workspace-page-title';
+import { useBlockSuiteWorkspacePageIsPublic } from '@toeverything/hooks/use-block-suite-workspace-page-is-public';
+import { useBlockSuiteWorkspacePageTitle } from '@toeverything/hooks/use-block-suite-workspace-page-title';
import { describe, expect, test } from 'vitest';
import { beforeEach } from 'vitest';
-import { useBlockSuiteWorkspaceName } from '../use-blocksuite-workspace-name';
+import { useBlockSuiteWorkspaceName } from '../use-block-suite-workspace-name';
let blockSuiteWorkspace: BlockSuiteWorkspace;
diff --git a/apps/web/src/hooks/__tests__/use-blocksuite-workspace-helper.spec.ts b/packages/hooks/src/__tests__/use-blocksuite-workspace-helper.spec.ts
similarity index 65%
rename from apps/web/src/hooks/__tests__/use-blocksuite-workspace-helper.spec.ts
rename to packages/hooks/src/__tests__/use-blocksuite-workspace-helper.spec.ts
index 0e92057448..38a1a6c16a 100644
--- a/apps/web/src/hooks/__tests__/use-blocksuite-workspace-helper.spec.ts
+++ b/packages/hooks/src/__tests__/use-blocksuite-workspace-helper.spec.ts
@@ -3,32 +3,25 @@
*/
import 'fake-indexeddb/auto';
+import { initPage } from '@affine/env/blocksuite';
import { __unstableSchemas, AffineSchemas } from '@blocksuite/blocks/models';
-import type { Page } from '@blocksuite/store';
+import { Workspace } from '@blocksuite/store';
import { renderHook } from '@testing-library/react';
+import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page-meta';
+import { useBlockSuiteWorkspaceHelper } from '@toeverything/hooks/use-block-suite-workspace-helper';
import { beforeEach, describe, expect, test } from 'vitest';
-import { BlockSuiteWorkspace } from '../../shared';
-import { useBlockSuiteWorkspaceHelper } from '../use-blocksuite-workspace-helper';
-import { usePageMeta } from '../use-page-meta';
-
-let blockSuiteWorkspace: BlockSuiteWorkspace;
-
-function handleNewPage(page: Page) {
- const pageBlockId = page.addBlock('affine:page', { title: '' });
- const frameId = page.addBlock('affine:frame', {}, pageBlockId);
- page.addBlock('affine:paragraph', {}, frameId);
-}
+let blockSuiteWorkspace: Workspace;
beforeEach(() => {
- blockSuiteWorkspace = new BlockSuiteWorkspace({
+ blockSuiteWorkspace = new Workspace({
id: 'test',
})
.register(AffineSchemas)
.register(__unstableSchemas);
- handleNewPage(blockSuiteWorkspace.createPage('page0'));
- handleNewPage(blockSuiteWorkspace.createPage('page1'));
- handleNewPage(blockSuiteWorkspace.createPage('page2'));
+ initPage(blockSuiteWorkspace.createPage('page0'));
+ initPage(blockSuiteWorkspace.createPage('page1'));
+ initPage(blockSuiteWorkspace.createPage('page2'));
});
describe('useBlockSuiteWorkspaceHelper', () => {
@@ -37,7 +30,9 @@ describe('useBlockSuiteWorkspaceHelper', () => {
const helperHook = renderHook(() =>
useBlockSuiteWorkspaceHelper(blockSuiteWorkspace)
);
- const pageMetaHook = renderHook(() => usePageMeta(blockSuiteWorkspace));
+ const pageMetaHook = renderHook(() =>
+ useBlockSuitePageMeta(blockSuiteWorkspace)
+ );
expect(pageMetaHook.result.current.length).toBe(3);
expect(blockSuiteWorkspace.meta.pageMetas.length).toBe(3);
const page = helperHook.result.current.createPage('page4');
@@ -54,7 +49,7 @@ describe('useBlockSuiteWorkspaceHelper', () => {
);
await helperHook.result.current.markMilestone('test');
expect(blockSuiteWorkspace.meta.pageMetas.length).toBe(3);
- handleNewPage(helperHook.result.current.createPage('page4'));
+ initPage(helperHook.result.current.createPage('page4'));
expect(blockSuiteWorkspace.meta.pageMetas.length).toBe(4);
expect(await helperHook.result.current.listMilestone()).toHaveProperty(
'test'
diff --git a/apps/web/src/hooks/use-page-meta.ts b/packages/hooks/src/use-block-suite-page-meta.ts
similarity index 90%
rename from apps/web/src/hooks/use-page-meta.ts
rename to packages/hooks/src/use-block-suite-page-meta.ts
index 7b2e2b2d0e..8fefe393e7 100644
--- a/apps/web/src/hooks/use-page-meta.ts
+++ b/packages/hooks/src/use-block-suite-page-meta.ts
@@ -1,10 +1,8 @@
import type { PageBlockModel } from '@blocksuite/blocks';
-import type { PageMeta } from '@blocksuite/store';
+import type { PageMeta, Workspace } from '@blocksuite/store';
import { assertExists } from '@blocksuite/store';
import { useEffect, useMemo, useState } from 'react';
-import type { BlockSuiteWorkspace } from '../shared';
-
declare module '@blocksuite/store' {
interface PageMeta {
favorite?: boolean;
@@ -15,12 +13,14 @@ declare module '@blocksuite/store' {
trashDate?: number;
// whether to create the page with the default template
init?: boolean;
+ // todo: support `number` in the future
+ isPublic?: boolean;
isRootPinboard?: boolean;
}
}
-export function usePageMeta(
- blockSuiteWorkspace: BlockSuiteWorkspace | null
+export function useBlockSuitePageMeta(
+ blockSuiteWorkspace: Workspace
): PageMeta[] {
const [pageMeta, setPageMeta] = useState<PageMeta[]>(
() => blockSuiteWorkspace?.meta.pageMetas ?? []
@@ -45,9 +45,7 @@ export function usePageMeta(
return pageMeta;
}
-export function usePageMetaHelper(
- blockSuiteWorkspace: BlockSuiteWorkspace | null
-) {
+export function usePageMetaHelper(blockSuiteWorkspace: Workspace) {
return useMemo(
() => ({
setPageTitle: (pageId: string, newTitle: string) => {
diff --git a/packages/hooks/src/use-blocksuite-workspace-avatar-url.ts b/packages/hooks/src/use-block-suite-workspace-avatar-url.ts
similarity index 100%
rename from packages/hooks/src/use-blocksuite-workspace-avatar-url.ts
rename to packages/hooks/src/use-block-suite-workspace-avatar-url.ts
diff --git a/apps/web/src/hooks/use-blocksuite-workspace-helper.ts b/packages/hooks/src/use-block-suite-workspace-helper.ts
similarity index 85%
rename from apps/web/src/hooks/use-blocksuite-workspace-helper.ts
rename to packages/hooks/src/use-block-suite-workspace-helper.ts
index 489032f0d3..6c69d9800a 100644
--- a/apps/web/src/hooks/use-blocksuite-workspace-helper.ts
+++ b/packages/hooks/src/use-block-suite-workspace-helper.ts
@@ -1,4 +1,4 @@
-import type { Page } from '@blocksuite/store';
+import type { Page, Workspace } from '@blocksuite/store';
import { assertExists } from '@blocksuite/store';
import {
getMilestones,
@@ -7,11 +7,7 @@ import {
} from '@toeverything/y-indexeddb';
import { useMemo } from 'react';
-import type { BlockSuiteWorkspace } from '../shared';
-
-export function useBlockSuiteWorkspaceHelper(
- blockSuiteWorkspace: BlockSuiteWorkspace | null
-) {
+export function useBlockSuiteWorkspaceHelper(blockSuiteWorkspace: Workspace) {
return useMemo(
() => ({
createPage: (pageId: string, parentId?: string): Page => {
diff --git a/packages/hooks/src/use-blocksuite-workspace-name.ts b/packages/hooks/src/use-block-suite-workspace-name.ts
similarity index 100%
rename from packages/hooks/src/use-blocksuite-workspace-name.ts
rename to packages/hooks/src/use-block-suite-workspace-name.ts
diff --git a/packages/hooks/src/use-blocksuite-workspace-page-is-public.ts b/packages/hooks/src/use-block-suite-workspace-page-is-public.ts
similarity index 88%
rename from packages/hooks/src/use-blocksuite-workspace-page-is-public.ts
rename to packages/hooks/src/use-block-suite-workspace-page-is-public.ts
index e8c941b5e9..9730a0396f 100644
--- a/packages/hooks/src/use-blocksuite-workspace-page-is-public.ts
+++ b/packages/hooks/src/use-block-suite-workspace-page-is-public.ts
@@ -1,12 +1,6 @@
import type { Page } from '@blocksuite/store';
import { useCallback, useEffect, useState } from 'react';
-declare module '@blocksuite/store' {
- interface PageMeta {
- isPublic?: boolean;
- }
-}
-
export function useBlockSuiteWorkspacePageIsPublic(page: Page) {
const [isPublic, set] = useState<boolean>(() => page.meta.isPublic ?? false);
useEffect(() => {
diff --git a/packages/hooks/src/use-blocksuite-workspace-page-title.ts b/packages/hooks/src/use-block-suite-workspace-page-title.ts
similarity index 100%
rename from packages/hooks/src/use-blocksuite-workspace-page-title.ts
rename to packages/hooks/src/use-block-suite-workspace-page-title.ts
diff --git a/packages/hooks/src/use-blocksuite-workspace-page.ts b/packages/hooks/src/use-block-suite-workspace-page.ts
similarity index 100%
rename from packages/hooks/src/use-blocksuite-workspace-page.ts
rename to packages/hooks/src/use-block-suite-workspace-page.ts
diff --git a/packages/workspace/src/providers/index.ts b/packages/workspace/src/providers/index.ts
index 4d57dea9ef..a9b57e2166 100644
--- a/packages/workspace/src/providers/index.ts
+++ b/packages/workspace/src/providers/index.ts
@@ -109,7 +109,10 @@ const createIndexedDBProvider = (
const callbacks = new CallbackSet();
return {
flavour: 'local-indexeddb',
+ // fixme: remove callbacks
callbacks,
+ // fixme: remove whenSynced
+ whenSynced: indexeddbProvider.whenSynced,
// fixme: remove background long polling
background: true,
cleanup: () => {
diff --git a/packages/workspace/src/type.ts b/packages/workspace/src/type.ts
index de8e3fe276..9b8812bb68 100644
--- a/packages/workspace/src/type.ts
+++ b/packages/workspace/src/type.ts
@@ -32,6 +32,7 @@ export interface BroadCastChannelProvider extends BaseProvider {
export interface LocalIndexedDBProvider extends BackgroundProvider {
flavour: 'local-indexeddb';
+ whenSynced: Promise<void>;
}
export interface AffineWebSocketProvider extends BaseProvider {