refactor: move non-affine hooks (#1857)

This commit is contained in:
Himself65 2023-04-09 17:15:07 -05:00 committed by GitHub
parent d9e42d6a0f
commit 401cad799e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 42 additions and 36 deletions

View File

@ -5,9 +5,9 @@ import { RemoveIcon, SearchIcon } from '@blocksuite/icons';
import type { PageMeta } from '@blocksuite/store'; import type { PageMeta } from '@blocksuite/store';
import React, { useCallback, useState } from 'react'; import React, { useCallback, useState } from 'react';
import { usePinboardData } from '../../../../hooks/affine/use-pinboard-data';
import { usePinboardHandler } from '../../../../hooks/affine/use-pinboard-handler';
import { usePageMetaHelper } from '../../../../hooks/use-page-meta'; 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'; import type { BlockSuiteWorkspace } from '../../../../shared';
import { toast } from '../../../../utils'; import { toast } from '../../../../utils';
import { PinboardRender } from '../pinboard-render/'; import { PinboardRender } from '../pinboard-render/';

View File

@ -10,8 +10,8 @@ import { useRouter } from 'next/router';
import { useMemo, useState } from 'react'; import { useMemo, useState } from 'react';
import { workspacePreferredModeAtom } from '../../../../atoms'; import { workspacePreferredModeAtom } from '../../../../atoms';
import type { PinboardNode } from '../../../../hooks/affine/use-pinboard-data';
import { usePageMetaHelper } from '../../../../hooks/use-page-meta'; import { usePageMetaHelper } from '../../../../hooks/use-page-meta';
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';
import { OperationButton } from './OperationButton'; import { OperationButton } from './OperationButton';

View File

@ -6,8 +6,8 @@ import {
useGuideHidden, useGuideHidden,
useGuideHiddenUntilNextUpdate, useGuideHiddenUntilNextUpdate,
useUpdateTipsOnVersionChange, useUpdateTipsOnVersionChange,
} from '../../../hooks/affine/use-is-first-load'; } from '../../../hooks/use-is-first-load';
import { useSidebarStatus } from '../../../hooks/affine/use-sidebar-status'; import { useSidebarStatus } from '../../../hooks/use-sidebar-status';
import { SidebarSwitchIcon } from './icons'; import { SidebarSwitchIcon } from './icons';
import { StyledSidebarSwitch } from './style'; import { StyledSidebarSwitch } from './style';
type SidebarSwitchProps = { type SidebarSwitchProps = {

View File

@ -7,7 +7,7 @@ import { forwardRef, useEffect, useMemo, useState } from 'react';
import { import {
useSidebarFloating, useSidebarFloating,
useSidebarStatus, useSidebarStatus,
} from '../../../hooks/affine/use-sidebar-status'; } from '../../../hooks/use-sidebar-status';
import { SidebarSwitch } from '../../affine/sidebar-switch'; import { SidebarSwitch } from '../../affine/sidebar-switch';
import { EditorOptionMenu } from './header-right-items/EditorOptionMenu'; import { EditorOptionMenu } from './header-right-items/EditorOptionMenu';
import SyncUser from './header-right-items/SyncUser'; import SyncUser from './header-right-items/SyncUser';

View File

@ -8,7 +8,7 @@ import type { HTMLAttributes } 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/affine/use-is-first-load'; import { useGuideHidden } from '../../../hooks/use-is-first-load';
import { usePageMeta } from '../../../hooks/use-page-meta'; import { usePageMeta } from '../../../hooks/use-page-meta';
import { useElementResizeEffect } from '../../../hooks/use-workspaces'; import { useElementResizeEffect } from '../../../hooks/use-workspaces';
import type { BlockSuiteWorkspace } from '../../../shared'; import type { BlockSuiteWorkspace } from '../../../shared';

View File

@ -8,9 +8,9 @@ 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 { useRecentlyViewed } from '../../../hooks/affine/use-recent-views';
import { useBlockSuiteWorkspaceHelper } from '../../../hooks/use-blocksuite-workspace-helper'; import { useBlockSuiteWorkspaceHelper } from '../../../hooks/use-blocksuite-workspace-helper';
import { usePageMeta } from '../../../hooks/use-page-meta'; import { usePageMeta } from '../../../hooks/use-page-meta';
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';
import { useSwitchToConfig } from './config'; import { useSwitchToConfig } from './config';

View File

@ -3,9 +3,9 @@ import type { PageMeta } from '@blocksuite/store';
import type { MouseEvent } from 'react'; import type { MouseEvent } from 'react';
import { useCallback } from 'react'; import { useCallback } from 'react';
import type { PinboardNode } from '../../../hooks/affine/use-pinboard-data'; import type { PinboardNode } from '../../../hooks/use-pinboard-data';
import { usePinboardData } from '../../../hooks/affine/use-pinboard-data'; import { usePinboardData } from '../../../hooks/use-pinboard-data';
import { usePinboardHandler } from '../../../hooks/affine/use-pinboard-handler'; import { usePinboardHandler } from '../../../hooks/use-pinboard-handler';
import type { BlockSuiteWorkspace } from '../../../shared'; import type { BlockSuiteWorkspace } from '../../../shared';
import { PinboardRender } from '../../affine/pinboard'; import { PinboardRender } from '../../affine/pinboard';

View File

@ -6,7 +6,7 @@ import { useCallback, useState } from 'react';
import { import {
useGuideHidden, useGuideHidden,
useGuideHiddenUntilNextUpdate, useGuideHiddenUntilNextUpdate,
} from '../../../../hooks/affine/use-is-first-load'; } from '../../../../hooks/use-is-first-load';
import { StyledChangeLog, StyledChangeLogWrapper } from '../shared-styles'; import { StyledChangeLog, StyledChangeLogWrapper } from '../shared-styles';
import { StyledLink } from '../style'; import { StyledLink } from '../style';

View File

@ -11,13 +11,13 @@ import type { Page, PageMeta } from '@blocksuite/store';
import type React from 'react'; import type React from 'react';
import { useCallback, useEffect, useState } from 'react'; import { useCallback, useEffect, useState } from 'react';
import { usePageMeta } from '../../../hooks/use-page-meta';
import { import {
useSidebarFloating, useSidebarFloating,
useSidebarResizing, useSidebarResizing,
useSidebarStatus, useSidebarStatus,
useSidebarWidth, useSidebarWidth,
} from '../../../hooks/affine/use-sidebar-status'; } from '../../../hooks/use-sidebar-status';
import { usePageMeta } from '../../../hooks/use-page-meta';
import type { AllWorkspace } from '../../../shared'; import type { AllWorkspace } from '../../../shared';
import { SidebarSwitch } from '../../affine/sidebar-switch'; import { SidebarSwitch } from '../../affine/sidebar-switch';
import { ChangeLog } from './changeLog'; import { ChangeLog } from './changeLog';

View File

@ -23,21 +23,21 @@ import { beforeAll, beforeEach, describe, expect, test, vi } from 'vitest';
import { currentWorkspaceIdAtom, workspacesAtom } from '../../atoms'; import { currentWorkspaceIdAtom, workspacesAtom } from '../../atoms';
import { LocalPlugin } from '../../plugins/local'; import { LocalPlugin } from '../../plugins/local';
import { BlockSuiteWorkspace, WorkspaceSubPath } from '../../shared'; import { BlockSuiteWorkspace, WorkspaceSubPath } from '../../shared';
import {
currentWorkspaceAtom,
useCurrentWorkspace,
} from '../current/use-current-workspace';
import { import {
useGuideHidden, useGuideHidden,
useGuideHiddenUntilNextUpdate, useGuideHiddenUntilNextUpdate,
useLastVersion, useLastVersion,
useTipsDisplayStatus, useTipsDisplayStatus,
} from '../affine/use-is-first-load'; } from '../use-is-first-load';
import { usePageMeta, usePageMetaHelper } from '../use-page-meta';
import { import {
useRecentlyViewed, useRecentlyViewed,
useSyncRecentViewsWithRouter, useSyncRecentViewsWithRouter,
} from '../affine/use-recent-views'; } from '../use-recent-views';
import {
currentWorkspaceAtom,
useCurrentWorkspace,
} from '../current/use-current-workspace';
import { usePageMeta, usePageMetaHelper } from '../use-page-meta';
import { import {
REDIRECT_TIMEOUT, REDIRECT_TIMEOUT,
useSyncRouterWithCurrentWorkspaceAndPage, useSyncRouterWithCurrentWorkspaceAndPage,

View File

@ -0,0 +1,6 @@
# AFFiNE Hooks
> This directory will be moved to `@affine/worksapce/affine/hooks` in the future.
Only put hooks in this directory if they are specific to AFFiNE, for example
if they are using the AFFiNE API, or if the `AffineWorkspace` is required.

View File

@ -6,7 +6,7 @@ import {
guideHiddenAtom, guideHiddenAtom,
guideHiddenUntilNextUpdateAtom, guideHiddenUntilNextUpdateAtom,
lastVersionAtom, lastVersionAtom,
} from '../../atoms/first-load'; } from '../atoms/first-load';
export function useLastVersion() { export function useLastVersion() {
return useAtom(lastVersionAtom); return useAtom(lastVersionAtom);

View File

@ -3,7 +3,7 @@ import type { PageMeta } from '@blocksuite/store';
import type { MouseEvent } from 'react'; import type { MouseEvent } from 'react';
import { useMemo } from 'react'; import { useMemo } from 'react';
import type { BlockSuiteWorkspace } from '../../shared'; import type { BlockSuiteWorkspace } from '../shared';
export type RenderProps = { export type RenderProps = {
blockSuiteWorkspace: BlockSuiteWorkspace; blockSuiteWorkspace: BlockSuiteWorkspace;

View File

@ -4,9 +4,9 @@ import type { PageMeta } from '@blocksuite/store';
import { nanoid } from '@blocksuite/store'; import { nanoid } from '@blocksuite/store';
import { useCallback } from 'react'; import { useCallback } from 'react';
import type { BlockSuiteWorkspace } from '../../shared'; import type { BlockSuiteWorkspace } from '../shared';
import { useBlockSuiteWorkspaceHelper } from '../use-blocksuite-workspace-helper'; import { useBlockSuiteWorkspaceHelper } from './use-blocksuite-workspace-helper';
import { usePageMetaHelper } from '../use-page-meta'; import { usePageMetaHelper } from './use-page-meta';
import type { NodeRenderProps, PinboardNode } from './use-pinboard-data'; import type { NodeRenderProps, PinboardNode } from './use-pinboard-data';
const logger = new DebugLogger('pinboard'); const logger = new DebugLogger('pinboard');

View File

@ -6,9 +6,9 @@ import {
workspacePreferredModeAtom, workspacePreferredModeAtom,
workspaceRecentViewsAtom, workspaceRecentViewsAtom,
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'; import { usePageMeta } from './use-page-meta';
export function useRecentlyViewed() { export function useRecentlyViewed() {
const [workspace] = useCurrentWorkspace(); const [workspace] = useCurrentWorkspace();

View File

@ -25,18 +25,18 @@ import {
import { HelpIsland } from '../components/pure/help-island'; 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 {
useSidebarFloating,
useSidebarResizing,
useSidebarStatus,
useSidebarWidth,
} from '../hooks/affine/use-sidebar-status';
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 { useBlockSuiteWorkspaceHelper } from '../hooks/use-blocksuite-workspace-helper'; import { useBlockSuiteWorkspaceHelper } from '../hooks/use-blocksuite-workspace-helper';
import { useCreateFirstWorkspace } from '../hooks/use-create-first-workspace'; import { useCreateFirstWorkspace } from '../hooks/use-create-first-workspace';
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 {
useSidebarFloating,
useSidebarResizing,
useSidebarStatus,
useSidebarWidth,
} from '../hooks/use-sidebar-status';
import { useWorkspaces } from '../hooks/use-workspaces'; import { useWorkspaces } from '../hooks/use-workspaces';
import { WorkspacePlugins } from '../plugins'; import { WorkspacePlugins } from '../plugins';
import { ModalProvider } from '../providers/ModalProvider'; import { ModalProvider } from '../providers/ModalProvider';

View File

@ -5,9 +5,9 @@ import { useEffect } from 'react';
import { Unreachable } from '../../../components/affine/affine-error-eoundary'; import { Unreachable } from '../../../components/affine/affine-error-eoundary';
import { PageLoading } from '../../../components/pure/loading'; import { PageLoading } from '../../../components/pure/loading';
import { useSyncRecentViewsWithRouter } from '../../../hooks/affine/use-recent-views';
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 { useSyncRecentViewsWithRouter } from '../../../hooks/use-recent-views';
import { useSyncRouterWithCurrentWorkspaceAndPage } from '../../../hooks/use-sync-router-with-current-workspace-and-page'; import { useSyncRouterWithCurrentWorkspaceAndPage } from '../../../hooks/use-sync-router-with-current-workspace-and-page';
import { WorkspaceLayout } from '../../../layouts'; import { WorkspaceLayout } from '../../../layouts';
import { WorkspacePlugins } from '../../../plugins'; import { WorkspacePlugins } from '../../../plugins';