refactor: remove null type in hooks (#1955)
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
|||||||
import { WorkspaceFlavour } from '@affine/workspace/type';
|
import { WorkspaceFlavour } from '@affine/workspace/type';
|
||||||
import { assertExists } from '@blocksuite/store';
|
import { assertExists } from '@blocksuite/store';
|
||||||
import { render, renderHook } from '@testing-library/react';
|
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 { createStore, getDefaultStore, Provider, useAtomValue } from 'jotai';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import type React from 'react';
|
import type React from 'react';
|
||||||
@@ -22,7 +23,6 @@ import {
|
|||||||
currentWorkspaceAtom,
|
currentWorkspaceAtom,
|
||||||
useCurrentWorkspace,
|
useCurrentWorkspace,
|
||||||
} from '../../hooks/current/use-current-workspace';
|
} from '../../hooks/current/use-current-workspace';
|
||||||
import { useBlockSuiteWorkspaceHelper } from '../../hooks/use-blocksuite-workspace-helper';
|
|
||||||
import { useAppHelper } from '../../hooks/use-workspaces';
|
import { useAppHelper } from '../../hooks/use-workspaces';
|
||||||
import { ThemeProvider } from '../../providers/ThemeProvider';
|
import { ThemeProvider } from '../../providers/ThemeProvider';
|
||||||
import { pathGenerator } from '../../shared';
|
import { pathGenerator } from '../../shared';
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ import { Input, PureMenu, TreeView } from '@affine/component';
|
|||||||
import { useTranslation } from '@affine/i18n';
|
import { useTranslation } from '@affine/i18n';
|
||||||
import { RemoveIcon, SearchIcon } from '@blocksuite/icons';
|
import { RemoveIcon, SearchIcon } from '@blocksuite/icons';
|
||||||
import type { PageMeta } from '@blocksuite/store';
|
import type { PageMeta } from '@blocksuite/store';
|
||||||
|
import { usePageMetaHelper } from '@toeverything/hooks/use-block-suite-page-meta';
|
||||||
import React, { useCallback, useMemo, useState } from 'react';
|
import React, { useCallback, useMemo, useState } from 'react';
|
||||||
|
|
||||||
import { usePageMetaHelper } from '../../../../hooks/use-page-meta';
|
|
||||||
import { usePinboardData } from '../../../../hooks/use-pinboard-data';
|
import { usePinboardData } from '../../../../hooks/use-pinboard-data';
|
||||||
import { usePinboardHandler } from '../../../../hooks/use-pinboard-handler';
|
import { usePinboardHandler } from '../../../../hooks/use-pinboard-handler';
|
||||||
import type { BlockSuiteWorkspace } from '../../../../shared';
|
import type { BlockSuiteWorkspace } from '../../../../shared';
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import type { PageMeta } from '@blocksuite/store';
|
|||||||
import { useTheme } from '@mui/material';
|
import { useTheme } from '@mui/material';
|
||||||
import { useMemo, useRef, useState } from 'react';
|
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 type { BlockSuiteWorkspace } from '../../../../shared';
|
||||||
import { toast } from '../../../../utils';
|
import { toast } from '../../../../utils';
|
||||||
import { CopyLink, MoveToTrash } from '../../operation-menu-items';
|
import { CopyLink, MoveToTrash } from '../../operation-menu-items';
|
||||||
@@ -50,7 +50,7 @@ export const OperationButton = ({
|
|||||||
const [pinboardMenuOpen, setPinboardMenuOpen] = useState(false);
|
const [pinboardMenuOpen, setPinboardMenuOpen] = useState(false);
|
||||||
const [confirmModalOpen, setConfirmModalOpen] = useState(false);
|
const [confirmModalOpen, setConfirmModalOpen] = useState(false);
|
||||||
const menuIndex = useMemo(() => modalIndex + 1, [modalIndex]);
|
const menuIndex = useMemo(() => modalIndex + 1, [modalIndex]);
|
||||||
const { removeToTrash } = useMetaHelper(blockSuiteWorkspace);
|
const { removeToTrash } = useBlockSuiteMetaHelper(blockSuiteWorkspace);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MuiClickAwayListener
|
<MuiClickAwayListener
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ import {
|
|||||||
PageIcon,
|
PageIcon,
|
||||||
PivotsIcon,
|
PivotsIcon,
|
||||||
} from '@blocksuite/icons';
|
} from '@blocksuite/icons';
|
||||||
|
import { usePageMetaHelper } from '@toeverything/hooks/use-block-suite-page-meta';
|
||||||
import { useAtomValue } from 'jotai';
|
import { useAtomValue } from 'jotai';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import { useMemo, useState } from 'react';
|
import { useMemo, useState } from 'react';
|
||||||
|
|
||||||
import { workspacePreferredModeAtom } from '../../../../atoms';
|
import { workspacePreferredModeAtom } from '../../../../atoms';
|
||||||
import { usePageMetaHelper } from '../../../../hooks/use-page-meta';
|
|
||||||
import type { PinboardNode } from '../../../../hooks/use-pinboard-data';
|
import type { PinboardNode } from '../../../../hooks/use-pinboard-data';
|
||||||
import { StyledCollapsedButton, StyledPinboard } from '../styles';
|
import { StyledCollapsedButton, StyledPinboard } from '../styles';
|
||||||
import EmptyItem from './EmptyItem';
|
import EmptyItem from './EmptyItem';
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Button, Input, Modal, ModalCloseButton } from '@affine/component';
|
import { Button, Input, Modal, ModalCloseButton } from '@affine/component';
|
||||||
import { Trans, useTranslation } from '@affine/i18n';
|
import { Trans, useTranslation } from '@affine/i18n';
|
||||||
import { WorkspaceFlavour } from '@affine/workspace/type';
|
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 { useCallback, useState } from 'react';
|
||||||
|
|
||||||
import type { AffineOfficialWorkspace } from '../../../../../../shared';
|
import type { AffineOfficialWorkspace } from '../../../../../../shared';
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import { Button, FlexWrapper, MuiFade } from '@affine/component';
|
|||||||
import { WorkspaceAvatar } from '@affine/component/workspace-avatar';
|
import { WorkspaceAvatar } from '@affine/component/workspace-avatar';
|
||||||
import { useTranslation } from '@affine/i18n';
|
import { useTranslation } from '@affine/i18n';
|
||||||
import { WorkspaceFlavour } from '@affine/workspace/type';
|
import { WorkspaceFlavour } from '@affine/workspace/type';
|
||||||
import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-blocksuite-workspace-avatar-url';
|
import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-block-suite-workspace-avatar-url';
|
||||||
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 type React from 'react';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { Content, FlexWrapper, styled } from '@affine/component';
|
import { Content, FlexWrapper, styled } from '@affine/component';
|
||||||
import { Trans, useTranslation } from '@affine/i18n';
|
import { Trans, useTranslation } from '@affine/i18n';
|
||||||
import { WorkspaceFlavour } from '@affine/workspace/type';
|
import { WorkspaceFlavour } from '@affine/workspace/type';
|
||||||
import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-blocksuite-workspace-avatar-url';
|
import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-block-suite-workspace-avatar-url';
|
||||||
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 type React from 'react';
|
||||||
|
|
||||||
import { useCurrentUser } from '../../../../../hooks/current/use-current-user';
|
import { useCurrentUser } from '../../../../../hooks/current/use-current-user';
|
||||||
|
|||||||
@@ -17,16 +17,16 @@ import {
|
|||||||
} from '@blocksuite/icons';
|
} from '@blocksuite/icons';
|
||||||
import type { PageMeta } from '@blocksuite/store';
|
import type { PageMeta } from '@blocksuite/store';
|
||||||
import { useMediaQuery, useTheme } from '@mui/material';
|
import { useMediaQuery, useTheme } from '@mui/material';
|
||||||
|
import {
|
||||||
|
useBlockSuitePageMeta,
|
||||||
|
usePageMetaHelper,
|
||||||
|
} from '@toeverything/hooks/use-block-suite-page-meta';
|
||||||
import { useAtomValue } from 'jotai';
|
import { useAtomValue } from 'jotai';
|
||||||
import type React from 'react';
|
import type React from 'react';
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
|
|
||||||
import { workspacePreferredModeAtom } from '../../../../atoms';
|
import { workspacePreferredModeAtom } from '../../../../atoms';
|
||||||
import { useMetaHelper } from '../../../../hooks/affine/use-meta-helper';
|
import { useBlockSuiteMetaHelper } from '../../../../hooks/affine/use-block-suite-meta-helper';
|
||||||
import {
|
|
||||||
usePageMeta,
|
|
||||||
usePageMetaHelper,
|
|
||||||
} from '../../../../hooks/use-page-meta';
|
|
||||||
import type { BlockSuiteWorkspace } from '../../../../shared';
|
import type { BlockSuiteWorkspace } from '../../../../shared';
|
||||||
import { toast } from '../../../../utils';
|
import { toast } from '../../../../utils';
|
||||||
import DateCell from './DateCell';
|
import DateCell from './DateCell';
|
||||||
@@ -101,10 +101,10 @@ export const PageList: React.FC<PageListProps> = ({
|
|||||||
listType,
|
listType,
|
||||||
onClickPage,
|
onClickPage,
|
||||||
}) => {
|
}) => {
|
||||||
const pageList = usePageMeta(blockSuiteWorkspace);
|
const pageList = useBlockSuitePageMeta(blockSuiteWorkspace);
|
||||||
const helper = usePageMetaHelper(blockSuiteWorkspace);
|
const helper = usePageMetaHelper(blockSuiteWorkspace);
|
||||||
const { removeToTrash, restoreFromTrash } =
|
const { removeToTrash, restoreFromTrash } =
|
||||||
useMetaHelper(blockSuiteWorkspace);
|
useBlockSuiteMetaHelper(blockSuiteWorkspace);
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const matches = useMediaQuery(theme.breakpoints.up('sm'));
|
const matches = useMediaQuery(theme.breakpoints.up('sm'));
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { assertExists } from '@blocksuite/store';
|
import { assertExists } from '@blocksuite/store';
|
||||||
|
import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page-meta';
|
||||||
import { useAtomValue, useSetAtom } from 'jotai';
|
import { useAtomValue, useSetAtom } from 'jotai';
|
||||||
import type { CSSProperties } from 'react';
|
import type { CSSProperties } from 'react';
|
||||||
|
|
||||||
import { workspacePreferredModeAtom } from '../../../../atoms';
|
import { workspacePreferredModeAtom } from '../../../../atoms';
|
||||||
import { usePageMeta } from '../../../../hooks/use-page-meta';
|
|
||||||
import type { BlockSuiteWorkspace } from '../../../../shared';
|
import type { BlockSuiteWorkspace } from '../../../../shared';
|
||||||
import { toast } from '../../../../utils';
|
import { toast } from '../../../../utils';
|
||||||
import { StyledEditorModeSwitch } from './style';
|
import { StyledEditorModeSwitch } from './style';
|
||||||
@@ -24,7 +24,7 @@ export const EditorModeSwitch = ({
|
|||||||
const currentMode =
|
const currentMode =
|
||||||
useAtomValue(workspacePreferredModeAtom)[pageId] ?? 'page';
|
useAtomValue(workspacePreferredModeAtom)[pageId] ?? 'page';
|
||||||
const setMode = useSetAtom(workspacePreferredModeAtom);
|
const setMode = useSetAtom(workspacePreferredModeAtom);
|
||||||
const pageMeta = usePageMeta(blockSuiteWorkspace).find(
|
const pageMeta = useBlockSuitePageMeta(blockSuiteWorkspace).find(
|
||||||
meta => meta.id === pageId
|
meta => meta.id === pageId
|
||||||
);
|
);
|
||||||
assertExists(pageMeta);
|
assertExists(pageMeta);
|
||||||
|
|||||||
@@ -10,17 +10,17 @@ import {
|
|||||||
} from '@blocksuite/icons';
|
} from '@blocksuite/icons';
|
||||||
import { assertExists } from '@blocksuite/store';
|
import { assertExists } from '@blocksuite/store';
|
||||||
import { useTheme } from '@mui/material';
|
import { useTheme } from '@mui/material';
|
||||||
|
import {
|
||||||
|
useBlockSuitePageMeta,
|
||||||
|
usePageMetaHelper,
|
||||||
|
} from '@toeverything/hooks/use-block-suite-page-meta';
|
||||||
import { useAtom } from 'jotai';
|
import { useAtom } from 'jotai';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
|
||||||
import { workspacePreferredModeAtom } from '../../../../atoms';
|
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 { useCurrentPageId } from '../../../../hooks/current/use-current-page-id';
|
||||||
import { useCurrentWorkspace } from '../../../../hooks/current/use-current-workspace';
|
import { useCurrentWorkspace } from '../../../../hooks/current/use-current-workspace';
|
||||||
import {
|
|
||||||
usePageMeta,
|
|
||||||
usePageMetaHelper,
|
|
||||||
} from '../../../../hooks/use-page-meta';
|
|
||||||
import { toast } from '../../../../utils';
|
import { toast } from '../../../../utils';
|
||||||
import {
|
import {
|
||||||
Export,
|
Export,
|
||||||
@@ -38,17 +38,17 @@ export const EditorOptionMenu = () => {
|
|||||||
assertExists(workspace);
|
assertExists(workspace);
|
||||||
assertExists(pageId);
|
assertExists(pageId);
|
||||||
const blockSuiteWorkspace = workspace.blockSuiteWorkspace;
|
const blockSuiteWorkspace = workspace.blockSuiteWorkspace;
|
||||||
const pageMeta = usePageMeta(blockSuiteWorkspace).find(
|
const pageMeta = useBlockSuitePageMeta(blockSuiteWorkspace).find(
|
||||||
meta => meta.id === pageId
|
meta => meta.id === pageId
|
||||||
);
|
);
|
||||||
const allMetas = usePageMeta(blockSuiteWorkspace);
|
const allMetas = useBlockSuitePageMeta(blockSuiteWorkspace);
|
||||||
const [record, set] = useAtom(workspacePreferredModeAtom);
|
const [record, set] = useAtom(workspacePreferredModeAtom);
|
||||||
const mode = record[pageId] ?? 'page';
|
const mode = record[pageId] ?? 'page';
|
||||||
assertExists(pageMeta);
|
assertExists(pageMeta);
|
||||||
const { favorite } = pageMeta;
|
const { favorite } = pageMeta;
|
||||||
const { setPageMeta } = usePageMetaHelper(blockSuiteWorkspace);
|
const { setPageMeta } = usePageMetaHelper(blockSuiteWorkspace);
|
||||||
const [openConfirm, setOpenConfirm] = useState(false);
|
const [openConfirm, setOpenConfirm] = useState(false);
|
||||||
const { removeToTrash } = useMetaHelper(blockSuiteWorkspace);
|
const { removeToTrash } = useBlockSuiteMetaHelper(blockSuiteWorkspace);
|
||||||
const EditMenu = (
|
const EditMenu = (
|
||||||
<>
|
<>
|
||||||
<MenuItem
|
<MenuItem
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import { Button, Confirm } from '@affine/component';
|
import { Button, Confirm } from '@affine/component';
|
||||||
import { useTranslation } from '@affine/i18n';
|
import { useTranslation } from '@affine/i18n';
|
||||||
import { assertExists } from '@blocksuite/store';
|
import { assertExists } from '@blocksuite/store';
|
||||||
|
import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page-meta';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import { useState } from 'react';
|
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 { useCurrentPageId } from '../../../../hooks/current/use-current-page-id';
|
||||||
import { useCurrentWorkspace } from '../../../../hooks/current/use-current-workspace';
|
import { useCurrentWorkspace } from '../../../../hooks/current/use-current-workspace';
|
||||||
import { usePageMeta } from '../../../../hooks/use-page-meta';
|
|
||||||
|
|
||||||
export const TrashButtonGroup = () => {
|
export const TrashButtonGroup = () => {
|
||||||
// fixme(himself65): remove these hooks ASAP
|
// fixme(himself65): remove these hooks ASAP
|
||||||
@@ -16,13 +16,13 @@ export const TrashButtonGroup = () => {
|
|||||||
assertExists(workspace);
|
assertExists(workspace);
|
||||||
assertExists(pageId);
|
assertExists(pageId);
|
||||||
const blockSuiteWorkspace = workspace.blockSuiteWorkspace;
|
const blockSuiteWorkspace = workspace.blockSuiteWorkspace;
|
||||||
const pageMeta = usePageMeta(blockSuiteWorkspace).find(
|
const pageMeta = useBlockSuitePageMeta(blockSuiteWorkspace).find(
|
||||||
meta => meta.id === pageId
|
meta => meta.id === pageId
|
||||||
);
|
);
|
||||||
assertExists(pageMeta);
|
assertExists(pageMeta);
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { restoreFromTrash } = useMetaHelper(blockSuiteWorkspace);
|
const { restoreFromTrash } = useBlockSuiteMetaHelper(blockSuiteWorkspace);
|
||||||
|
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ import { QuickSearchTips } from '@affine/component';
|
|||||||
import { getEnvironment } from '@affine/env';
|
import { getEnvironment } from '@affine/env';
|
||||||
import { ArrowDownSmallIcon } from '@blocksuite/icons';
|
import { ArrowDownSmallIcon } from '@blocksuite/icons';
|
||||||
import { assertExists } from '@blocksuite/store';
|
import { assertExists } from '@blocksuite/store';
|
||||||
|
import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page-meta';
|
||||||
import { useAtomValue, useSetAtom } from 'jotai';
|
import { useAtomValue, useSetAtom } from 'jotai';
|
||||||
import type { HTMLAttributes, PropsWithChildren } from 'react';
|
import type { HTMLAttributes, PropsWithChildren } from 'react';
|
||||||
import { forwardRef, useCallback, useRef } from 'react';
|
import { forwardRef, useCallback, useRef } from 'react';
|
||||||
|
|
||||||
import { currentEditorAtom, openQuickSearchModalAtom } from '../../../atoms';
|
import { currentEditorAtom, openQuickSearchModalAtom } from '../../../atoms';
|
||||||
import { useGuideHidden } from '../../../hooks/use-is-first-load';
|
import { useGuideHidden } from '../../../hooks/use-is-first-load';
|
||||||
import { usePageMeta } from '../../../hooks/use-page-meta';
|
|
||||||
import { useElementResizeEffect } from '../../../hooks/use-workspaces';
|
import { useElementResizeEffect } from '../../../hooks/use-workspaces';
|
||||||
import { QuickSearchButton } from '../../pure/quick-search-button';
|
import { QuickSearchButton } from '../../pure/quick-search-button';
|
||||||
import { EditorModeSwitch } from './editor-mode-switch';
|
import { EditorModeSwitch } from './editor-mode-switch';
|
||||||
@@ -34,7 +34,7 @@ export const WorkspaceHeader = forwardRef<
|
|||||||
const { workspace, currentPage, children, isPublic } = props;
|
const { workspace, currentPage, children, isPublic } = props;
|
||||||
// fixme(himself65): remove this atom and move it to props
|
// fixme(himself65): remove this atom and move it to props
|
||||||
const setOpenQuickSearch = useSetAtom(openQuickSearchModalAtom);
|
const setOpenQuickSearch = useSetAtom(openQuickSearchModalAtom);
|
||||||
const pageMeta = usePageMeta(workspace.blockSuiteWorkspace).find(
|
const pageMeta = useBlockSuitePageMeta(workspace.blockSuiteWorkspace).find(
|
||||||
meta => meta.id === currentPage?.id
|
meta => meta.id === currentPage?.id
|
||||||
);
|
);
|
||||||
assertExists(pageMeta);
|
assertExists(pageMeta);
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import type { EditorContainer } from '@blocksuite/editor';
|
import type { EditorContainer } from '@blocksuite/editor';
|
||||||
import type { Page } from '@blocksuite/store';
|
import type { Page } from '@blocksuite/store';
|
||||||
import { assertExists } 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 { useAtomValue, useSetAtom } from 'jotai';
|
||||||
import Head from 'next/head';
|
import Head from 'next/head';
|
||||||
import type React from 'react';
|
import type React from 'react';
|
||||||
import { startTransition, useCallback } from 'react';
|
import { startTransition, useCallback } from 'react';
|
||||||
|
|
||||||
import { currentEditorAtom, workspacePreferredModeAtom } from '../atoms';
|
import { currentEditorAtom, workspacePreferredModeAtom } from '../atoms';
|
||||||
import { usePageMeta } from '../hooks/use-page-meta';
|
|
||||||
import type { AffineOfficialWorkspace } from '../shared';
|
import type { AffineOfficialWorkspace } from '../shared';
|
||||||
import { PageNotFoundError } from './affine/affine-error-eoundary';
|
import { PageNotFoundError } from './affine/affine-error-eoundary';
|
||||||
import { BlockSuiteEditor as Editor } from './blocksuite/block-suite-editor';
|
import { BlockSuiteEditor as Editor } from './blocksuite/block-suite-editor';
|
||||||
@@ -39,7 +39,7 @@ export const PageDetailEditor: React.FC<PageDetailEditorProps> = ({
|
|||||||
throw new PageNotFoundError(blockSuiteWorkspace, pageId);
|
throw new PageNotFoundError(blockSuiteWorkspace, pageId);
|
||||||
}
|
}
|
||||||
const title = useBlockSuiteWorkspacePageTitle(blockSuiteWorkspace, pageId);
|
const title = useBlockSuiteWorkspacePageTitle(blockSuiteWorkspace, pageId);
|
||||||
const meta = usePageMeta(blockSuiteWorkspace).find(
|
const meta = useBlockSuitePageMeta(blockSuiteWorkspace).find(
|
||||||
meta => meta.id === pageId
|
meta => meta.id === pageId
|
||||||
);
|
);
|
||||||
const currentMode =
|
const currentMode =
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ import { useTranslation } from '@affine/i18n';
|
|||||||
import type { PageBlockModel } from '@blocksuite/blocks';
|
import type { PageBlockModel } from '@blocksuite/blocks';
|
||||||
import { PlusIcon } from '@blocksuite/icons';
|
import { PlusIcon } from '@blocksuite/icons';
|
||||||
import { assertEquals, nanoid } from '@blocksuite/store';
|
import { assertEquals, nanoid } from '@blocksuite/store';
|
||||||
|
import { useBlockSuiteWorkspaceHelper } from '@toeverything/hooks/use-block-suite-workspace-helper';
|
||||||
import { Command } from 'cmdk';
|
import { Command } from 'cmdk';
|
||||||
import type { NextRouter } from 'next/router';
|
import type { NextRouter } from 'next/router';
|
||||||
import type React from 'react';
|
import type React from 'react';
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
|
|
||||||
import { useBlockSuiteWorkspaceHelper } from '../../../hooks/use-blocksuite-workspace-helper';
|
|
||||||
import { useRouterHelper } from '../../../hooks/use-router-helper';
|
import { useRouterHelper } from '../../../hooks/use-router-helper';
|
||||||
import type { BlockSuiteWorkspace } from '../../../shared';
|
import type { BlockSuiteWorkspace } from '../../../shared';
|
||||||
import { StyledModalFooterContent } from './style';
|
import { StyledModalFooterContent } from './style';
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { useTranslation } from '@affine/i18n';
|
import { useTranslation } from '@affine/i18n';
|
||||||
import { EdgelessIcon, PageIcon } from '@blocksuite/icons';
|
import { EdgelessIcon, PageIcon } from '@blocksuite/icons';
|
||||||
|
import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page-meta';
|
||||||
import { Command } from 'cmdk';
|
import { Command } from 'cmdk';
|
||||||
import Image from 'next/legacy/image';
|
import Image from 'next/legacy/image';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import type { FC } from 'react';
|
import type { FC } from 'react';
|
||||||
import { useEffect, useMemo, useState } from 'react';
|
import { useEffect, useMemo, useState } from 'react';
|
||||||
|
|
||||||
import { usePageMeta } from '../../../hooks/use-page-meta';
|
|
||||||
import type { BlockSuiteWorkspace } from '../../../shared';
|
import type { BlockSuiteWorkspace } from '../../../shared';
|
||||||
import { StyledListItem, StyledNotFound } from './style';
|
import { StyledListItem, StyledNotFound } from './style';
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ export const PublishedResults: FC<PublishedResultsProps> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const [results, setResults] = useState(new Map<string, string | undefined>());
|
const [results, setResults] = useState(new Map<string, string | undefined>());
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const pageList = usePageMeta(blockSuiteWorkspace);
|
const pageList = useBlockSuitePageMeta(blockSuiteWorkspace);
|
||||||
// useEffect(() => {
|
// useEffect(() => {
|
||||||
// dataCenter
|
// dataCenter
|
||||||
// .loadPublicWorkspace(router.query.workspaceId as string)
|
// .loadPublicWorkspace(router.query.workspaceId as string)
|
||||||
|
|||||||
@@ -2,14 +2,14 @@ import { UNTITLED_WORKSPACE_NAME } from '@affine/env';
|
|||||||
import { useTranslation } from '@affine/i18n';
|
import { useTranslation } from '@affine/i18n';
|
||||||
import { EdgelessIcon, PageIcon } from '@blocksuite/icons';
|
import { EdgelessIcon, PageIcon } from '@blocksuite/icons';
|
||||||
import { assertExists } from '@blocksuite/store';
|
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 { Command } from 'cmdk';
|
||||||
import Image from 'next/legacy/image';
|
import Image from 'next/legacy/image';
|
||||||
import type { NextRouter } from 'next/router';
|
import type { NextRouter } from 'next/router';
|
||||||
import type { Dispatch, FC, SetStateAction } from 'react';
|
import type { Dispatch, FC, SetStateAction } from 'react';
|
||||||
import { useEffect } 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 { useRecentlyViewed } from '../../../hooks/use-recent-views';
|
||||||
import { useRouterHelper } from '../../../hooks/use-router-helper';
|
import { useRouterHelper } from '../../../hooks/use-router-helper';
|
||||||
import type { BlockSuiteWorkspace } from '../../../shared';
|
import type { BlockSuiteWorkspace } from '../../../shared';
|
||||||
@@ -31,7 +31,7 @@ export const Results: FC<ResultsProps> = ({
|
|||||||
onClose,
|
onClose,
|
||||||
}) => {
|
}) => {
|
||||||
useBlockSuiteWorkspaceHelper(blockSuiteWorkspace);
|
useBlockSuiteWorkspaceHelper(blockSuiteWorkspace);
|
||||||
const pageList = usePageMeta(blockSuiteWorkspace);
|
const pageList = useBlockSuitePageMeta(blockSuiteWorkspace);
|
||||||
assertExists(blockSuiteWorkspace.id);
|
assertExists(blockSuiteWorkspace.id);
|
||||||
const List = useSwitchToConfig(blockSuiteWorkspace.id);
|
const List = useSwitchToConfig(blockSuiteWorkspace.id);
|
||||||
|
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ import {
|
|||||||
MoreHorizontalIcon,
|
MoreHorizontalIcon,
|
||||||
} from '@blocksuite/icons';
|
} from '@blocksuite/icons';
|
||||||
import type { PageMeta } from '@blocksuite/store';
|
import type { PageMeta } from '@blocksuite/store';
|
||||||
|
import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page-meta';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import type { MouseEvent } from 'react';
|
import type { MouseEvent } from 'react';
|
||||||
import { Fragment, useCallback, useMemo, useState } 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 type { PinboardNode } from '../../../../hooks/use-pinboard-data';
|
||||||
import { usePinboardData } from '../../../../hooks/use-pinboard-data';
|
import { usePinboardData } from '../../../../hooks/use-pinboard-data';
|
||||||
import { useRouterHelper } from '../../../../hooks/use-router-helper';
|
import { useRouterHelper } from '../../../../hooks/use-router-helper';
|
||||||
@@ -33,7 +33,7 @@ export const NavigationPath = ({
|
|||||||
pageId?: string;
|
pageId?: string;
|
||||||
onJumpToPage?: (pageId: string) => void;
|
onJumpToPage?: (pageId: string) => void;
|
||||||
}) => {
|
}) => {
|
||||||
const metas = usePageMeta(blockSuiteWorkspace);
|
const metas = useBlockSuitePageMeta(blockSuiteWorkspace);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { TreeView } from '@affine/component';
|
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 type { MouseEvent } from 'react';
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
|
|
||||||
@@ -12,14 +12,10 @@ import { PinboardRender } from '../../affine/pinboard';
|
|||||||
export type PinboardProps = {
|
export type PinboardProps = {
|
||||||
blockSuiteWorkspace: BlockSuiteWorkspace;
|
blockSuiteWorkspace: BlockSuiteWorkspace;
|
||||||
openPage: (pageId: string) => void;
|
openPage: (pageId: string) => void;
|
||||||
allMetas: PageMeta[];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Pinboard = ({
|
export const Pinboard = ({ blockSuiteWorkspace, openPage }: PinboardProps) => {
|
||||||
blockSuiteWorkspace,
|
const allMetas = useBlockSuitePageMeta(blockSuiteWorkspace);
|
||||||
openPage,
|
|
||||||
allMetas,
|
|
||||||
}: PinboardProps) => {
|
|
||||||
const handlePinboardClick = useCallback(
|
const handlePinboardClick = useCallback(
|
||||||
(e: MouseEvent<HTMLDivElement>, node: PinboardNode) => {
|
(e: MouseEvent<HTMLDivElement>, node: PinboardNode) => {
|
||||||
openPage(node.id);
|
openPage(node.id);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { WorkspaceAvatar } from '@affine/component/workspace-avatar';
|
import { WorkspaceAvatar } from '@affine/component/workspace-avatar';
|
||||||
import { CloudWorkspaceIcon, LocalWorkspaceIcon } from '@blocksuite/icons';
|
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 type React from 'react';
|
||||||
|
|
||||||
import { useCurrentWorkspace } from '../../../../hooks/current/use-current-workspace';
|
import { useCurrentWorkspace } from '../../../../hooks/current/use-current-workspace';
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
import { useTranslation } from '@affine/i18n';
|
import { useTranslation } from '@affine/i18n';
|
||||||
import { ArrowDownSmallIcon, FavoriteIcon } from '@blocksuite/icons';
|
import { ArrowDownSmallIcon, FavoriteIcon } from '@blocksuite/icons';
|
||||||
|
import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page-meta';
|
||||||
import { useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
|
|
||||||
import { usePageMeta } from '../../../../hooks/use-page-meta';
|
import type { AllWorkspace } from '../../../../shared';
|
||||||
import type { WorkSpaceSliderBarProps } from '../index';
|
import type { WorkSpaceSliderBarProps } from '../index';
|
||||||
import { StyledCollapseButton, StyledListItem } from '../shared-styles';
|
import { StyledCollapseButton, StyledListItem } from '../shared-styles';
|
||||||
import { StyledLink } from '../style';
|
import { StyledLink } from '../style';
|
||||||
import FavoriteList from './favorite-list';
|
import FavoriteList from './favorite-list';
|
||||||
|
|
||||||
export const Favorite = ({
|
export const Favorite = ({
|
||||||
currentPath,
|
currentPath,
|
||||||
paths,
|
paths,
|
||||||
@@ -15,10 +17,12 @@ export const Favorite = ({
|
|||||||
currentWorkspace,
|
currentWorkspace,
|
||||||
}: Pick<
|
}: Pick<
|
||||||
WorkSpaceSliderBarProps,
|
WorkSpaceSliderBarProps,
|
||||||
'currentPath' | 'paths' | 'currentPageId' | 'openPage' | 'currentWorkspace'
|
'currentPath' | 'paths' | 'currentPageId' | 'openPage'
|
||||||
>) => {
|
> & {
|
||||||
const currentWorkspaceId = currentWorkspace?.id || null;
|
currentWorkspace: AllWorkspace;
|
||||||
const pageMeta = usePageMeta(currentWorkspace?.blockSuiteWorkspace ?? null);
|
}) => {
|
||||||
|
const currentWorkspaceId = currentWorkspace.id;
|
||||||
|
const pageMeta = useBlockSuitePageMeta(currentWorkspace.blockSuiteWorkspace);
|
||||||
|
|
||||||
const [showSubFavorite, setOpenSubFavorite] = useState(true);
|
const [showSubFavorite, setOpenSubFavorite] = useState(true);
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import type React from 'react';
|
|||||||
import type { UIEvent } from 'react';
|
import type { UIEvent } from 'react';
|
||||||
import { lazy, Suspense, useCallback, useEffect, useState } from 'react';
|
import { lazy, Suspense, useCallback, useEffect, useState } from 'react';
|
||||||
|
|
||||||
import { usePageMeta } from '../../../hooks/use-page-meta';
|
|
||||||
import {
|
import {
|
||||||
useSidebarFloating,
|
useSidebarFloating,
|
||||||
useSidebarResizing,
|
useSidebarResizing,
|
||||||
@@ -85,7 +84,6 @@ export const WorkSpaceSliderBar: React.FC<WorkSpaceSliderBarProps> = ({
|
|||||||
const blockSuiteWorkspace = currentWorkspace?.blockSuiteWorkspace;
|
const blockSuiteWorkspace = currentWorkspace?.blockSuiteWorkspace;
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [sidebarOpen, setSidebarOpen] = useSidebarStatus();
|
const [sidebarOpen, setSidebarOpen] = useSidebarStatus();
|
||||||
const pageMeta = usePageMeta(blockSuiteWorkspace ?? null);
|
|
||||||
const onClickNewPage = useCallback(async () => {
|
const onClickNewPage = useCallback(async () => {
|
||||||
const page = await createPage();
|
const page = await createPage();
|
||||||
openPage(page.id);
|
openPage(page.id);
|
||||||
@@ -190,18 +188,19 @@ export const WorkSpaceSliderBar: React.FC<WorkSpaceSliderBarProps> = ({
|
|||||||
: setIsScrollAtTop(false);
|
: setIsScrollAtTop(false);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Favorite
|
{blockSuiteWorkspace && (
|
||||||
currentPath={currentPath}
|
<Favorite
|
||||||
paths={paths}
|
currentPath={currentPath}
|
||||||
currentPageId={currentPageId}
|
paths={paths}
|
||||||
openPage={openPage}
|
currentPageId={currentPageId}
|
||||||
currentWorkspace={currentWorkspace}
|
openPage={openPage}
|
||||||
/>
|
currentWorkspace={currentWorkspace}
|
||||||
{!!blockSuiteWorkspace && (
|
/>
|
||||||
|
)}
|
||||||
|
{blockSuiteWorkspace && (
|
||||||
<Pinboard
|
<Pinboard
|
||||||
blockSuiteWorkspace={blockSuiteWorkspace}
|
blockSuiteWorkspace={blockSuiteWorkspace}
|
||||||
openPage={openPage}
|
openPage={openPage}
|
||||||
allMetas={pageMeta}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</StyledScrollWrapper>
|
</StyledScrollWrapper>
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ import { __unstableSchemas, AffineSchemas } from '@blocksuite/blocks/models';
|
|||||||
import type { Page } from '@blocksuite/store';
|
import type { Page } from '@blocksuite/store';
|
||||||
import { assertExists } from '@blocksuite/store';
|
import { assertExists } from '@blocksuite/store';
|
||||||
import { render, renderHook } from '@testing-library/react';
|
import { render, renderHook } from '@testing-library/react';
|
||||||
|
import {
|
||||||
|
useBlockSuitePageMeta,
|
||||||
|
usePageMetaHelper,
|
||||||
|
} from '@toeverything/hooks/use-block-suite-page-meta';
|
||||||
import { createStore, Provider } from 'jotai';
|
import { createStore, Provider } from 'jotai';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import routerMock from 'next-router-mock';
|
import routerMock from 'next-router-mock';
|
||||||
@@ -36,7 +40,6 @@ import {
|
|||||||
useLastVersion,
|
useLastVersion,
|
||||||
useTipsDisplayStatus,
|
useTipsDisplayStatus,
|
||||||
} from '../use-is-first-load';
|
} from '../use-is-first-load';
|
||||||
import { usePageMeta, usePageMetaHelper } from '../use-page-meta';
|
|
||||||
import {
|
import {
|
||||||
useRecentlyViewed,
|
useRecentlyViewed,
|
||||||
useSyncRecentViewsWithRouter,
|
useSyncRecentViewsWithRouter,
|
||||||
@@ -103,7 +106,7 @@ beforeEach(async () => {
|
|||||||
describe('usePageMetas', async () => {
|
describe('usePageMetas', async () => {
|
||||||
test('basic', async () => {
|
test('basic', async () => {
|
||||||
const Component = () => {
|
const Component = () => {
|
||||||
const pageMetas = usePageMeta(blockSuiteWorkspace);
|
const pageMetas = useBlockSuitePageMeta(blockSuiteWorkspace);
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{pageMetas.map(meta => (
|
{pageMetas.map(meta => (
|
||||||
@@ -121,7 +124,7 @@ describe('usePageMetas', async () => {
|
|||||||
|
|
||||||
test('mutation', () => {
|
test('mutation', () => {
|
||||||
const { result, rerender } = renderHook(() =>
|
const { result, rerender } = renderHook(() =>
|
||||||
usePageMeta(blockSuiteWorkspace)
|
useBlockSuitePageMeta(blockSuiteWorkspace)
|
||||||
);
|
);
|
||||||
expect(result.current.length).toBe(3);
|
expect(result.current.length).toBe(3);
|
||||||
expect(result.current[0].mode).not.exist;
|
expect(result.current[0].mode).not.exist;
|
||||||
@@ -143,7 +146,7 @@ describe('usePageMetas', async () => {
|
|||||||
|
|
||||||
test('update title', () => {
|
test('update title', () => {
|
||||||
const { result, rerender } = renderHook(() =>
|
const { result, rerender } = renderHook(() =>
|
||||||
usePageMeta(blockSuiteWorkspace)
|
useBlockSuitePageMeta(blockSuiteWorkspace)
|
||||||
);
|
);
|
||||||
expect(result.current.length).toBe(3);
|
expect(result.current.length).toBe(3);
|
||||||
expect(result.current[0].mode).not.exist;
|
expect(result.current[0].mode).not.exist;
|
||||||
@@ -260,7 +263,7 @@ describe('useRecentlyViewed', () => {
|
|||||||
});
|
});
|
||||||
routerHook.rerender();
|
routerHook.rerender();
|
||||||
const syncHook = renderHook(
|
const syncHook = renderHook(
|
||||||
router => useSyncRecentViewsWithRouter(router),
|
router => useSyncRecentViewsWithRouter(router, blockSuiteWorkspace),
|
||||||
{
|
{
|
||||||
wrapper: ProviderWrapper,
|
wrapper: ProviderWrapper,
|
||||||
initialProps: routerHook.result.current,
|
initialProps: routerHook.result.current,
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
|
import {
|
||||||
|
useBlockSuitePageMeta,
|
||||||
|
usePageMetaHelper,
|
||||||
|
} from '@toeverything/hooks/use-block-suite-page-meta';
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
|
|
||||||
import type { BlockSuiteWorkspace } from '../../shared';
|
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 { setPageMeta, getPageMeta } = usePageMetaHelper(blockSuiteWorkspace);
|
||||||
const metas = usePageMeta(blockSuiteWorkspace);
|
const metas = useBlockSuitePageMeta(blockSuiteWorkspace);
|
||||||
|
|
||||||
const removeToTrash = useCallback(
|
const removeToTrash = useCallback(
|
||||||
(pageId: string, isRoot = true) => {
|
(pageId: string, isRoot = true) => {
|
||||||
@@ -17,7 +17,7 @@ export const lastWorkspaceIdAtom = atomWithSyncStorage<string | null>(
|
|||||||
);
|
);
|
||||||
|
|
||||||
export function useCurrentWorkspace(): [
|
export function useCurrentWorkspace(): [
|
||||||
AllWorkspace | null,
|
AllWorkspace,
|
||||||
(id: string | null) => void
|
(id: string | null) => void
|
||||||
] {
|
] {
|
||||||
const currentWorkspace = useAtomValue(rootCurrentWorkspaceAtom);
|
const currentWorkspace = useAtomValue(rootCurrentWorkspaceAtom);
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ import type { TreeViewProps } from '@affine/component';
|
|||||||
import { DebugLogger } from '@affine/debug';
|
import { DebugLogger } from '@affine/debug';
|
||||||
import type { PageMeta } from '@blocksuite/store';
|
import type { PageMeta } from '@blocksuite/store';
|
||||||
import { nanoid } 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 { useCallback } from 'react';
|
||||||
|
|
||||||
import type { BlockSuiteWorkspace } from '../shared';
|
import type { BlockSuiteWorkspace } from '../shared';
|
||||||
import { useMetaHelper } from './affine/use-meta-helper';
|
import { useBlockSuiteMetaHelper } from './affine/use-block-suite-meta-helper';
|
||||||
import { useBlockSuiteWorkspaceHelper } from './use-blocksuite-workspace-helper';
|
|
||||||
import { usePageMetaHelper } from './use-page-meta';
|
|
||||||
import type { NodeRenderProps } from './use-pinboard-data';
|
import type { NodeRenderProps } from './use-pinboard-data';
|
||||||
|
|
||||||
const logger = new DebugLogger('pinboard');
|
const logger = new DebugLogger('pinboard');
|
||||||
@@ -26,7 +26,7 @@ export function usePinboardHandler({
|
|||||||
onDelete,
|
onDelete,
|
||||||
onDrop,
|
onDrop,
|
||||||
}: {
|
}: {
|
||||||
blockSuiteWorkspace: BlockSuiteWorkspace | null;
|
blockSuiteWorkspace: BlockSuiteWorkspace;
|
||||||
metas: PageMeta[];
|
metas: PageMeta[];
|
||||||
onAdd?: (addedId: string, parentId: string) => void;
|
onAdd?: (addedId: string, parentId: string) => void;
|
||||||
onDelete?: TreeViewProps<NodeRenderProps>['onDelete'];
|
onDelete?: TreeViewProps<NodeRenderProps>['onDelete'];
|
||||||
@@ -35,7 +35,7 @@ export function usePinboardHandler({
|
|||||||
const { createPage } = useBlockSuiteWorkspaceHelper(blockSuiteWorkspace);
|
const { createPage } = useBlockSuiteWorkspaceHelper(blockSuiteWorkspace);
|
||||||
const { setPageMeta } = usePageMetaHelper(blockSuiteWorkspace);
|
const { setPageMeta } = usePageMetaHelper(blockSuiteWorkspace);
|
||||||
const { removeToTrash: removeToTrashHelper } =
|
const { removeToTrash: removeToTrashHelper } =
|
||||||
useMetaHelper(blockSuiteWorkspace);
|
useBlockSuiteMetaHelper(blockSuiteWorkspace);
|
||||||
// Just need handle add operation, delete check is handled in blockSuite's reference link
|
// Just need handle add operation, delete check is handled in blockSuite's reference link
|
||||||
const addReferenceLink = useCallback(
|
const addReferenceLink = useCallback(
|
||||||
(pageId: string, referenceId: string) => {
|
(pageId: string, referenceId: string) => {
|
||||||
|
|||||||
@@ -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 { useAtomValue, useSetAtom } from 'jotai';
|
||||||
import type { NextRouter } from 'next/router';
|
import type { NextRouter } from 'next/router';
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
@@ -8,7 +10,6 @@ import {
|
|||||||
workspaceRecentViresWriteAtom,
|
workspaceRecentViresWriteAtom,
|
||||||
} from '../atoms';
|
} from '../atoms';
|
||||||
import { useCurrentWorkspace } from './current/use-current-workspace';
|
import { useCurrentWorkspace } from './current/use-current-workspace';
|
||||||
import { usePageMeta } from './use-page-meta';
|
|
||||||
|
|
||||||
export function useRecentlyViewed() {
|
export function useRecentlyViewed() {
|
||||||
const [workspace] = useCurrentWorkspace();
|
const [workspace] = useCurrentWorkspace();
|
||||||
@@ -19,13 +20,14 @@ export function useRecentlyViewed() {
|
|||||||
return recentlyViewed[workspaceId] ?? [];
|
return recentlyViewed[workspaceId] ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useSyncRecentViewsWithRouter(router: NextRouter) {
|
export function useSyncRecentViewsWithRouter(
|
||||||
const [workspace] = useCurrentWorkspace();
|
router: NextRouter,
|
||||||
const workspaceId = workspace?.id || null;
|
blockSuiteWorkspace: Workspace
|
||||||
const blockSuiteWorkspace = workspace?.blockSuiteWorkspace || null;
|
) {
|
||||||
|
const workspaceId = blockSuiteWorkspace.id;
|
||||||
const pageId = router.query.pageId;
|
const pageId = router.query.pageId;
|
||||||
const set = useSetAtom(workspaceRecentViresWriteAtom);
|
const set = useSetAtom(workspaceRecentViresWriteAtom);
|
||||||
const meta = usePageMeta(blockSuiteWorkspace).find(
|
const meta = useBlockSuitePageMeta(blockSuiteWorkspace).find(
|
||||||
meta => meta.id === pageId
|
meta => meta.id === pageId
|
||||||
);
|
);
|
||||||
const currentMode = useAtomValue(workspacePreferredModeAtom)[
|
const currentMode = useAtomValue(workspacePreferredModeAtom)[
|
||||||
|
|||||||
@@ -25,26 +25,6 @@ export function useRouterHelper(router: NextRouter) {
|
|||||||
},
|
},
|
||||||
[router]
|
[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(
|
const jumpToPublicWorkspacePage = useCallback(
|
||||||
(
|
(
|
||||||
workspaceId: string,
|
workspaceId: string,
|
||||||
@@ -91,7 +71,6 @@ export function useRouterHelper(router: NextRouter) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
jumpToPage,
|
jumpToPage,
|
||||||
jumpToWorkspace,
|
|
||||||
jumpToPublicWorkspacePage,
|
jumpToPublicWorkspacePage,
|
||||||
jumpToSubPath,
|
jumpToSubPath,
|
||||||
openPage,
|
openPage,
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
import type { LocalIndexedDBProvider } from '@affine/workspace/type';
|
import type { LocalIndexedDBProvider } from '@affine/workspace/type';
|
||||||
import { WorkspaceFlavour } from '@affine/workspace/type';
|
import { WorkspaceFlavour } from '@affine/workspace/type';
|
||||||
import { assertEquals, assertExists, nanoid } from '@blocksuite/store';
|
import { assertEquals, assertExists, nanoid } from '@blocksuite/store';
|
||||||
|
import { useBlockSuiteWorkspaceHelper } from '@toeverything/hooks/use-block-suite-workspace-helper';
|
||||||
import { useAtom, useAtomValue, useSetAtom } from 'jotai';
|
import { useAtom, useAtomValue, useSetAtom } from 'jotai';
|
||||||
import Head from 'next/head';
|
import Head from 'next/head';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
@@ -27,7 +28,6 @@ import { HelpIsland } from '../components/pure/help-island';
|
|||||||
import { PageLoading } from '../components/pure/loading';
|
import { PageLoading } from '../components/pure/loading';
|
||||||
import WorkSpaceSliderBar from '../components/pure/workspace-slider-bar';
|
import WorkSpaceSliderBar from '../components/pure/workspace-slider-bar';
|
||||||
import { useCurrentWorkspace } from '../hooks/current/use-current-workspace';
|
import { useCurrentWorkspace } from '../hooks/current/use-current-workspace';
|
||||||
import { useBlockSuiteWorkspaceHelper } from '../hooks/use-blocksuite-workspace-helper';
|
|
||||||
import { useRouterHelper } from '../hooks/use-router-helper';
|
import { useRouterHelper } from '../hooks/use-router-helper';
|
||||||
import { useRouterTitle } from '../hooks/use-router-title';
|
import { useRouterTitle } from '../hooks/use-router-title';
|
||||||
import { useRouterWithWorkspaceIdDefense } from '../hooks/use-router-with-workspace-id-defense';
|
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 { openPage } = useRouterHelper(router);
|
||||||
const [, setOpenWorkspacesModal] = useAtom(openWorkspacesModalAtom);
|
const [, setOpenWorkspacesModal] = useAtom(openWorkspacesModalAtom);
|
||||||
const helper = useBlockSuiteWorkspaceHelper(
|
const helper = useBlockSuiteWorkspaceHelper(
|
||||||
currentWorkspace?.blockSuiteWorkspace ?? null
|
currentWorkspace.blockSuiteWorkspace
|
||||||
);
|
);
|
||||||
const isPublicWorkspace =
|
const isPublicWorkspace =
|
||||||
router.pathname.split('/')[1] === 'public-workspace';
|
router.pathname.split('/')[1] === 'public-workspace';
|
||||||
@@ -393,16 +393,11 @@ export const WorkspaceLayoutInner: FC<PropsWithChildren> = ({ children }) => {
|
|||||||
);
|
);
|
||||||
}, [setIsResizing, setSidebarOpen, setSliderWidth]);
|
}, [setIsResizing, setSidebarOpen, setSliderWidth]);
|
||||||
|
|
||||||
const Provider = currentWorkspace
|
const Provider =
|
||||||
? WorkspacePlugins[currentWorkspace.flavour].UI.Provider
|
WorkspacePlugins[currentWorkspace.flavour].UI.Provider ?? DefaultProvider;
|
||||||
: DefaultProvider;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Provider
|
<Provider>
|
||||||
key={`${
|
|
||||||
currentWorkspace ? currentWorkspace.flavour : 'default'
|
|
||||||
}-provider`}
|
|
||||||
>
|
|
||||||
<Head>
|
<Head>
|
||||||
<title>{title}</title>
|
<title>{title}</title>
|
||||||
</Head>
|
</Head>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Breadcrumbs, IconButton, ListSkeleton } from '@affine/component';
|
import { Breadcrumbs, IconButton, ListSkeleton } from '@affine/component';
|
||||||
import { SearchIcon } from '@blocksuite/icons';
|
import { SearchIcon } from '@blocksuite/icons';
|
||||||
import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-blocksuite-workspace-avatar-url';
|
import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-block-suite-workspace-avatar-url';
|
||||||
import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-blocksuite-workspace-name';
|
import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-block-suite-workspace-name';
|
||||||
import { useAtomValue, useSetAtom } from 'jotai';
|
import { useAtomValue, useSetAtom } from 'jotai';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import type React from 'react';
|
import type React from 'react';
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import { initPage } from '@affine/env/blocksuite';
|
|||||||
import { useTranslation } from '@affine/i18n';
|
import { useTranslation } from '@affine/i18n';
|
||||||
import { PageIcon } from '@blocksuite/icons';
|
import { PageIcon } from '@blocksuite/icons';
|
||||||
import { assertExists } from '@blocksuite/store';
|
import { assertExists } from '@blocksuite/store';
|
||||||
import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-blocksuite-workspace-avatar-url';
|
import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-block-suite-workspace-avatar-url';
|
||||||
import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-blocksuite-workspace-name';
|
import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-block-suite-workspace-name';
|
||||||
import { useAtom, useAtomValue } from 'jotai';
|
import { useAtom, useAtomValue } from 'jotai';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
import { rootCurrentPageIdAtom } from '@affine/workspace/atom';
|
import { rootCurrentPageIdAtom } from '@affine/workspace/atom';
|
||||||
import { WorkspaceFlavour } from '@affine/workspace/type';
|
import { WorkspaceFlavour } from '@affine/workspace/type';
|
||||||
import { assertExists } from '@blocksuite/store';
|
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 { useAtomValue } from 'jotai';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import type React from 'react';
|
import type React from 'react';
|
||||||
@@ -12,7 +16,6 @@ import { Unreachable } from '../../../components/affine/affine-error-eoundary';
|
|||||||
import { PageLoading } from '../../../components/pure/loading';
|
import { PageLoading } from '../../../components/pure/loading';
|
||||||
import { useReferenceLinkEffect } from '../../../hooks/affine/use-reference-link-effect';
|
import { useReferenceLinkEffect } from '../../../hooks/affine/use-reference-link-effect';
|
||||||
import { useCurrentWorkspace } from '../../../hooks/current/use-current-workspace';
|
import { useCurrentWorkspace } from '../../../hooks/current/use-current-workspace';
|
||||||
import { usePageMeta, usePageMetaHelper } from '../../../hooks/use-page-meta';
|
|
||||||
import { usePinboardHandler } from '../../../hooks/use-pinboard-handler';
|
import { usePinboardHandler } from '../../../hooks/use-pinboard-handler';
|
||||||
import { useSyncRecentViewsWithRouter } from '../../../hooks/use-recent-views';
|
import { useSyncRecentViewsWithRouter } from '../../../hooks/use-recent-views';
|
||||||
import { useRouterAndWorkspaceWithPageIdDefense } from '../../../hooks/use-router-and-workspace-with-page-id-defense';
|
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 { openPage } = useRouterHelper(router);
|
||||||
const currentPageId = useAtomValue(rootCurrentPageIdAtom);
|
const currentPageId = useAtomValue(rootCurrentPageIdAtom);
|
||||||
const [currentWorkspace] = useCurrentWorkspace();
|
const [currentWorkspace] = useCurrentWorkspace();
|
||||||
const blockSuiteWorkspace = currentWorkspace?.blockSuiteWorkspace ?? null;
|
assertExists(currentWorkspace);
|
||||||
|
const blockSuiteWorkspace = currentWorkspace.blockSuiteWorkspace;
|
||||||
const { setPageMeta, getPageMeta } = usePageMetaHelper(blockSuiteWorkspace);
|
const { setPageMeta, getPageMeta } = usePageMetaHelper(blockSuiteWorkspace);
|
||||||
const { deletePin } = usePinboardHandler({
|
const { deletePin } = usePinboardHandler({
|
||||||
blockSuiteWorkspace,
|
blockSuiteWorkspace,
|
||||||
metas: usePageMeta(currentWorkspace?.blockSuiteWorkspace ?? null ?? null),
|
metas: useBlockSuitePageMeta(currentWorkspace.blockSuiteWorkspace),
|
||||||
});
|
});
|
||||||
|
|
||||||
useSyncRecentViewsWithRouter(router);
|
useSyncRecentViewsWithRouter(router, blockSuiteWorkspace);
|
||||||
|
|
||||||
useReferenceLinkEffect({
|
useReferenceLinkEffect({
|
||||||
pageLinkClicked: useCallback(
|
pageLinkClicked: useCallback(
|
||||||
@@ -79,9 +83,6 @@ const WorkspaceDetail: React.FC = () => {
|
|||||||
enableFullFlags(currentWorkspace.blockSuiteWorkspace);
|
enableFullFlags(currentWorkspace.blockSuiteWorkspace);
|
||||||
}
|
}
|
||||||
}, [currentWorkspace]);
|
}, [currentWorkspace]);
|
||||||
if (currentWorkspace === null) {
|
|
||||||
return <PageLoading />;
|
|
||||||
}
|
|
||||||
if (!currentPageId) {
|
if (!currentPageId) {
|
||||||
return <PageLoading text="Loading page." />;
|
return <PageLoading text="Loading page." />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,9 +42,6 @@ const AllPage: NextPageWithLayout = () => {
|
|||||||
if (typeof router.query.workspaceId !== 'string') {
|
if (typeof router.query.workspaceId !== 'string') {
|
||||||
throw new QueryParamError('workspaceId', router.query.workspaceId);
|
throw new QueryParamError('workspaceId', router.query.workspaceId);
|
||||||
}
|
}
|
||||||
if (currentWorkspace === null) {
|
|
||||||
return <PageLoading />;
|
|
||||||
}
|
|
||||||
if (currentWorkspace.flavour === WorkspaceFlavour.AFFINE) {
|
if (currentWorkspace.flavour === WorkspaceFlavour.AFFINE) {
|
||||||
const PageList = WorkspacePlugins[currentWorkspace.flavour].UI.PageList;
|
const PageList = WorkspacePlugins[currentWorkspace.flavour].UI.PageList;
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { AffineWorkspace, LocalWorkspace } from '@affine/workspace/type';
|
import type { AffineWorkspace, LocalWorkspace } from '@affine/workspace/type';
|
||||||
import { ExportIcon, PublishIcon, ShareIcon } from '@blocksuite/icons';
|
import { ExportIcon, PublishIcon, ShareIcon } from '@blocksuite/icons';
|
||||||
import type { Page } from '@blocksuite/store';
|
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 type { FC } from 'react';
|
||||||
import { useRef } from 'react';
|
import { useRef } from 'react';
|
||||||
import { useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { prefixUrl } from '@affine/env';
|
|||||||
import { Trans, useTranslation } from '@affine/i18n';
|
import { Trans, useTranslation } from '@affine/i18n';
|
||||||
import type { LocalWorkspace } from '@affine/workspace/type';
|
import type { LocalWorkspace } from '@affine/workspace/type';
|
||||||
import { WorkspaceFlavour } 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 type { FC } from 'react';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { useCallback, useMemo } from 'react';
|
import { useCallback, useMemo } from 'react';
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useTranslation } from '@affine/i18n';
|
import { useTranslation } from '@affine/i18n';
|
||||||
import type { Page } from '@blocksuite/store';
|
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 { useCallback } from 'react';
|
||||||
|
|
||||||
import { Modal, ModalCloseButton, toast } from '../../..';
|
import { Modal, ModalCloseButton, toast } from '../../..';
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import type {
|
|||||||
} from '@affine/workspace/type';
|
} from '@affine/workspace/type';
|
||||||
import type { Workspace } from '@blocksuite/store';
|
import type { Workspace } from '@blocksuite/store';
|
||||||
import * as RadixAvatar from '@radix-ui/react-avatar';
|
import * as RadixAvatar from '@radix-ui/react-avatar';
|
||||||
import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-blocksuite-workspace-avatar-url';
|
import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-block-suite-workspace-avatar-url';
|
||||||
import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-blocksuite-workspace-name';
|
import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-block-suite-workspace-name';
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import type React from 'react';
|
import type React from 'react';
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { PermissionType } from '@affine/workspace/affine/api';
|
|||||||
import type { AffineWorkspace, LocalWorkspace } from '@affine/workspace/type';
|
import type { AffineWorkspace, LocalWorkspace } from '@affine/workspace/type';
|
||||||
import { WorkspaceFlavour } from '@affine/workspace/type';
|
import { WorkspaceFlavour } from '@affine/workspace/type';
|
||||||
import { SettingsIcon } from '@blocksuite/icons';
|
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 type { FC, MouseEvent } from 'react';
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
|
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ import type { Page } from '@blocksuite/store';
|
|||||||
import { assertExists } from '@blocksuite/store';
|
import { assertExists } from '@blocksuite/store';
|
||||||
import { Workspace as BlockSuiteWorkspace } from '@blocksuite/store';
|
import { Workspace as BlockSuiteWorkspace } from '@blocksuite/store';
|
||||||
import { renderHook } from '@testing-library/react';
|
import { renderHook } from '@testing-library/react';
|
||||||
import { useBlockSuiteWorkspacePageIsPublic } from '@toeverything/hooks/use-blocksuite-workspace-page-is-public';
|
import { useBlockSuiteWorkspacePageIsPublic } from '@toeverything/hooks/use-block-suite-workspace-page-is-public';
|
||||||
import { useBlockSuiteWorkspacePageTitle } from '@toeverything/hooks/use-blocksuite-workspace-page-title';
|
import { useBlockSuiteWorkspacePageTitle } from '@toeverything/hooks/use-block-suite-workspace-page-title';
|
||||||
import { describe, expect, test } from 'vitest';
|
import { describe, expect, test } from 'vitest';
|
||||||
import { beforeEach } from 'vitest';
|
import { beforeEach } from 'vitest';
|
||||||
|
|
||||||
import { useBlockSuiteWorkspaceName } from '../use-blocksuite-workspace-name';
|
import { useBlockSuiteWorkspaceName } from '../use-block-suite-workspace-name';
|
||||||
|
|
||||||
let blockSuiteWorkspace: BlockSuiteWorkspace;
|
let blockSuiteWorkspace: BlockSuiteWorkspace;
|
||||||
|
|
||||||
|
|||||||
@@ -3,32 +3,25 @@
|
|||||||
*/
|
*/
|
||||||
import 'fake-indexeddb/auto';
|
import 'fake-indexeddb/auto';
|
||||||
|
|
||||||
|
import { initPage } from '@affine/env/blocksuite';
|
||||||
import { __unstableSchemas, AffineSchemas } from '@blocksuite/blocks/models';
|
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 { 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 { beforeEach, describe, expect, test } from 'vitest';
|
||||||
|
|
||||||
import { BlockSuiteWorkspace } from '../../shared';
|
let blockSuiteWorkspace: Workspace;
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
blockSuiteWorkspace = new BlockSuiteWorkspace({
|
blockSuiteWorkspace = new Workspace({
|
||||||
id: 'test',
|
id: 'test',
|
||||||
})
|
})
|
||||||
.register(AffineSchemas)
|
.register(AffineSchemas)
|
||||||
.register(__unstableSchemas);
|
.register(__unstableSchemas);
|
||||||
handleNewPage(blockSuiteWorkspace.createPage('page0'));
|
initPage(blockSuiteWorkspace.createPage('page0'));
|
||||||
handleNewPage(blockSuiteWorkspace.createPage('page1'));
|
initPage(blockSuiteWorkspace.createPage('page1'));
|
||||||
handleNewPage(blockSuiteWorkspace.createPage('page2'));
|
initPage(blockSuiteWorkspace.createPage('page2'));
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('useBlockSuiteWorkspaceHelper', () => {
|
describe('useBlockSuiteWorkspaceHelper', () => {
|
||||||
@@ -37,7 +30,9 @@ describe('useBlockSuiteWorkspaceHelper', () => {
|
|||||||
const helperHook = renderHook(() =>
|
const helperHook = renderHook(() =>
|
||||||
useBlockSuiteWorkspaceHelper(blockSuiteWorkspace)
|
useBlockSuiteWorkspaceHelper(blockSuiteWorkspace)
|
||||||
);
|
);
|
||||||
const pageMetaHook = renderHook(() => usePageMeta(blockSuiteWorkspace));
|
const pageMetaHook = renderHook(() =>
|
||||||
|
useBlockSuitePageMeta(blockSuiteWorkspace)
|
||||||
|
);
|
||||||
expect(pageMetaHook.result.current.length).toBe(3);
|
expect(pageMetaHook.result.current.length).toBe(3);
|
||||||
expect(blockSuiteWorkspace.meta.pageMetas.length).toBe(3);
|
expect(blockSuiteWorkspace.meta.pageMetas.length).toBe(3);
|
||||||
const page = helperHook.result.current.createPage('page4');
|
const page = helperHook.result.current.createPage('page4');
|
||||||
@@ -54,7 +49,7 @@ describe('useBlockSuiteWorkspaceHelper', () => {
|
|||||||
);
|
);
|
||||||
await helperHook.result.current.markMilestone('test');
|
await helperHook.result.current.markMilestone('test');
|
||||||
expect(blockSuiteWorkspace.meta.pageMetas.length).toBe(3);
|
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(blockSuiteWorkspace.meta.pageMetas.length).toBe(4);
|
||||||
expect(await helperHook.result.current.listMilestone()).toHaveProperty(
|
expect(await helperHook.result.current.listMilestone()).toHaveProperty(
|
||||||
'test'
|
'test'
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
import type { PageBlockModel } from '@blocksuite/blocks';
|
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 { assertExists } from '@blocksuite/store';
|
||||||
import { useEffect, useMemo, useState } from 'react';
|
import { useEffect, useMemo, useState } from 'react';
|
||||||
|
|
||||||
import type { BlockSuiteWorkspace } from '../shared';
|
|
||||||
|
|
||||||
declare module '@blocksuite/store' {
|
declare module '@blocksuite/store' {
|
||||||
interface PageMeta {
|
interface PageMeta {
|
||||||
favorite?: boolean;
|
favorite?: boolean;
|
||||||
@@ -15,12 +13,14 @@ declare module '@blocksuite/store' {
|
|||||||
trashDate?: number;
|
trashDate?: number;
|
||||||
// whether to create the page with the default template
|
// whether to create the page with the default template
|
||||||
init?: boolean;
|
init?: boolean;
|
||||||
|
// todo: support `number` in the future
|
||||||
|
isPublic?: boolean;
|
||||||
isRootPinboard?: boolean;
|
isRootPinboard?: boolean;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function usePageMeta(
|
export function useBlockSuitePageMeta(
|
||||||
blockSuiteWorkspace: BlockSuiteWorkspace | null
|
blockSuiteWorkspace: Workspace
|
||||||
): PageMeta[] {
|
): PageMeta[] {
|
||||||
const [pageMeta, setPageMeta] = useState<PageMeta[]>(
|
const [pageMeta, setPageMeta] = useState<PageMeta[]>(
|
||||||
() => blockSuiteWorkspace?.meta.pageMetas ?? []
|
() => blockSuiteWorkspace?.meta.pageMetas ?? []
|
||||||
@@ -45,9 +45,7 @@ export function usePageMeta(
|
|||||||
return pageMeta;
|
return pageMeta;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function usePageMetaHelper(
|
export function usePageMetaHelper(blockSuiteWorkspace: Workspace) {
|
||||||
blockSuiteWorkspace: BlockSuiteWorkspace | null
|
|
||||||
) {
|
|
||||||
return useMemo(
|
return useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
setPageTitle: (pageId: string, newTitle: string) => {
|
setPageTitle: (pageId: string, newTitle: string) => {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { Page } from '@blocksuite/store';
|
import type { Page, Workspace } from '@blocksuite/store';
|
||||||
import { assertExists } from '@blocksuite/store';
|
import { assertExists } from '@blocksuite/store';
|
||||||
import {
|
import {
|
||||||
getMilestones,
|
getMilestones,
|
||||||
@@ -7,11 +7,7 @@ import {
|
|||||||
} from '@toeverything/y-indexeddb';
|
} from '@toeverything/y-indexeddb';
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
|
|
||||||
import type { BlockSuiteWorkspace } from '../shared';
|
export function useBlockSuiteWorkspaceHelper(blockSuiteWorkspace: Workspace) {
|
||||||
|
|
||||||
export function useBlockSuiteWorkspaceHelper(
|
|
||||||
blockSuiteWorkspace: BlockSuiteWorkspace | null
|
|
||||||
) {
|
|
||||||
return useMemo(
|
return useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
createPage: (pageId: string, parentId?: string): Page => {
|
createPage: (pageId: string, parentId?: string): Page => {
|
||||||
@@ -1,12 +1,6 @@
|
|||||||
import type { Page } from '@blocksuite/store';
|
import type { Page } from '@blocksuite/store';
|
||||||
import { useCallback, useEffect, useState } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
|
|
||||||
declare module '@blocksuite/store' {
|
|
||||||
interface PageMeta {
|
|
||||||
isPublic?: boolean;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useBlockSuiteWorkspacePageIsPublic(page: Page) {
|
export function useBlockSuiteWorkspacePageIsPublic(page: Page) {
|
||||||
const [isPublic, set] = useState<boolean>(() => page.meta.isPublic ?? false);
|
const [isPublic, set] = useState<boolean>(() => page.meta.isPublic ?? false);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -109,7 +109,10 @@ const createIndexedDBProvider = (
|
|||||||
const callbacks = new CallbackSet();
|
const callbacks = new CallbackSet();
|
||||||
return {
|
return {
|
||||||
flavour: 'local-indexeddb',
|
flavour: 'local-indexeddb',
|
||||||
|
// fixme: remove callbacks
|
||||||
callbacks,
|
callbacks,
|
||||||
|
// fixme: remove whenSynced
|
||||||
|
whenSynced: indexeddbProvider.whenSynced,
|
||||||
// fixme: remove background long polling
|
// fixme: remove background long polling
|
||||||
background: true,
|
background: true,
|
||||||
cleanup: () => {
|
cleanup: () => {
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ export interface BroadCastChannelProvider extends BaseProvider {
|
|||||||
|
|
||||||
export interface LocalIndexedDBProvider extends BackgroundProvider {
|
export interface LocalIndexedDBProvider extends BackgroundProvider {
|
||||||
flavour: 'local-indexeddb';
|
flavour: 'local-indexeddb';
|
||||||
|
whenSynced: Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AffineWebSocketProvider extends BaseProvider {
|
export interface AffineWebSocketProvider extends BaseProvider {
|
||||||
|
|||||||
Reference in New Issue
Block a user