mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-11-28 17:22:30 +03:00
refactor: remove null type in hooks (#1955)
This commit is contained in:
parent
9c517907eb
commit
3d70a36dd3
@ -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';
|
||||
|
@ -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';
|
||||
|
@ -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
|
||||
|
@ -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';
|
||||
|
@ -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';
|
||||
|
@ -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';
|
||||
|
||||
|
@ -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';
|
||||
|
@ -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'));
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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 =
|
||||
|
@ -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';
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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';
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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>
|
||||
|
@ -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,
|
||||
|
@ -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) => {
|
@ -17,7 +17,7 @@ export const lastWorkspaceIdAtom = atomWithSyncStorage<string | null>(
|
||||
);
|
||||
|
||||
export function useCurrentWorkspace(): [
|
||||
AllWorkspace | null,
|
||||
AllWorkspace,
|
||||
(id: string | null) => void
|
||||
] {
|
||||
const currentWorkspace = useAtomValue(rootCurrentWorkspaceAtom);
|
||||
|
@ -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) => {
|
||||
|
@ -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)[
|
||||
|
@ -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,
|
||||
|
@ -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>
|
||||
|
@ -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';
|
||||
|
@ -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';
|
||||
|
@ -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." />;
|
||||
}
|
||||
|
@ -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 (
|
||||
|
@ -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';
|
||||
|
@ -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';
|
||||
|
@ -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 '../../..';
|
||||
|
@ -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';
|
||||
|
||||
|
@ -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';
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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'
|
@ -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) => {
|
@ -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 => {
|
@ -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(() => {
|
@ -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: () => {
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user