diff --git a/apps/web/src/components/affine/pinboard/pinboard-menu/index.tsx b/apps/web/src/components/affine/pinboard/pinboard-menu/index.tsx index 25766968c8..3c4c64ebeb 100644 --- a/apps/web/src/components/affine/pinboard/pinboard-menu/index.tsx +++ b/apps/web/src/components/affine/pinboard/pinboard-menu/index.tsx @@ -5,9 +5,9 @@ import { RemoveIcon, SearchIcon } from '@blocksuite/icons'; import type { PageMeta } from '@blocksuite/store'; 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 { usePinboardData } from '../../../../hooks/use-pinboard-data'; +import { usePinboardHandler } from '../../../../hooks/use-pinboard-handler'; import type { BlockSuiteWorkspace } from '../../../../shared'; import { toast } from '../../../../utils'; import { PinboardRender } from '../pinboard-render/'; diff --git a/apps/web/src/components/affine/pinboard/pinboard-render/index.tsx b/apps/web/src/components/affine/pinboard/pinboard-render/index.tsx index b2826136cf..ed582dd241 100644 --- a/apps/web/src/components/affine/pinboard/pinboard-render/index.tsx +++ b/apps/web/src/components/affine/pinboard/pinboard-render/index.tsx @@ -10,8 +10,8 @@ import { useRouter } from 'next/router'; import { useMemo, useState } from 'react'; import { workspacePreferredModeAtom } from '../../../../atoms'; -import type { PinboardNode } from '../../../../hooks/affine/use-pinboard-data'; import { usePageMetaHelper } from '../../../../hooks/use-page-meta'; +import type { PinboardNode } from '../../../../hooks/use-pinboard-data'; import { StyledCollapsedButton, StyledPinboard } from '../styles'; import EmptyItem from './EmptyItem'; import { OperationButton } from './OperationButton'; diff --git a/apps/web/src/components/affine/sidebar-switch/index.tsx b/apps/web/src/components/affine/sidebar-switch/index.tsx index 1073747fb8..9910d13813 100644 --- a/apps/web/src/components/affine/sidebar-switch/index.tsx +++ b/apps/web/src/components/affine/sidebar-switch/index.tsx @@ -6,8 +6,8 @@ import { useGuideHidden, useGuideHiddenUntilNextUpdate, useUpdateTipsOnVersionChange, -} from '../../../hooks/affine/use-is-first-load'; -import { useSidebarStatus } from '../../../hooks/affine/use-sidebar-status'; +} from '../../../hooks/use-is-first-load'; +import { useSidebarStatus } from '../../../hooks/use-sidebar-status'; import { SidebarSwitchIcon } from './icons'; import { StyledSidebarSwitch } from './style'; type SidebarSwitchProps = { diff --git a/apps/web/src/components/blocksuite/header/header.tsx b/apps/web/src/components/blocksuite/header/header.tsx index 9125592905..e060e20735 100644 --- a/apps/web/src/components/blocksuite/header/header.tsx +++ b/apps/web/src/components/blocksuite/header/header.tsx @@ -7,7 +7,7 @@ import { forwardRef, useEffect, useMemo, useState } from 'react'; import { useSidebarFloating, useSidebarStatus, -} from '../../../hooks/affine/use-sidebar-status'; +} from '../../../hooks/use-sidebar-status'; import { SidebarSwitch } from '../../affine/sidebar-switch'; import { EditorOptionMenu } from './header-right-items/EditorOptionMenu'; import SyncUser from './header-right-items/SyncUser'; diff --git a/apps/web/src/components/blocksuite/header/index.tsx b/apps/web/src/components/blocksuite/header/index.tsx index b6ef75c72e..8d287ef9b1 100644 --- a/apps/web/src/components/blocksuite/header/index.tsx +++ b/apps/web/src/components/blocksuite/header/index.tsx @@ -8,7 +8,7 @@ import type { HTMLAttributes } from 'react'; import { forwardRef, useCallback, useRef } from 'react'; 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 { useElementResizeEffect } from '../../../hooks/use-workspaces'; import type { BlockSuiteWorkspace } from '../../../shared'; diff --git a/apps/web/src/components/pure/quick-search-modal/Results.tsx b/apps/web/src/components/pure/quick-search-modal/Results.tsx index 22b0032bd1..3f656d316f 100644 --- a/apps/web/src/components/pure/quick-search-modal/Results.tsx +++ b/apps/web/src/components/pure/quick-search-modal/Results.tsx @@ -8,9 +8,9 @@ import type { NextRouter } from 'next/router'; import type { Dispatch, FC, SetStateAction } from 'react'; import { useEffect } from 'react'; -import { useRecentlyViewed } from '../../../hooks/affine/use-recent-views'; 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'; import { useSwitchToConfig } from './config'; diff --git a/apps/web/src/components/pure/workspace-slider-bar/Pinboard.tsx b/apps/web/src/components/pure/workspace-slider-bar/Pinboard.tsx index 9a97abd1c5..b7d0ec0b10 100644 --- a/apps/web/src/components/pure/workspace-slider-bar/Pinboard.tsx +++ b/apps/web/src/components/pure/workspace-slider-bar/Pinboard.tsx @@ -3,9 +3,9 @@ import type { PageMeta } from '@blocksuite/store'; import type { MouseEvent } from 'react'; import { useCallback } from 'react'; -import type { PinboardNode } from '../../../hooks/affine/use-pinboard-data'; -import { usePinboardData } from '../../../hooks/affine/use-pinboard-data'; -import { usePinboardHandler } from '../../../hooks/affine/use-pinboard-handler'; +import type { PinboardNode } from '../../../hooks/use-pinboard-data'; +import { usePinboardData } from '../../../hooks/use-pinboard-data'; +import { usePinboardHandler } from '../../../hooks/use-pinboard-handler'; import type { BlockSuiteWorkspace } from '../../../shared'; import { PinboardRender } from '../../affine/pinboard'; diff --git a/apps/web/src/components/pure/workspace-slider-bar/changeLog/index.tsx b/apps/web/src/components/pure/workspace-slider-bar/changeLog/index.tsx index 9dcaaeff2f..f61ff9c9f7 100644 --- a/apps/web/src/components/pure/workspace-slider-bar/changeLog/index.tsx +++ b/apps/web/src/components/pure/workspace-slider-bar/changeLog/index.tsx @@ -6,7 +6,7 @@ import { useCallback, useState } from 'react'; import { useGuideHidden, useGuideHiddenUntilNextUpdate, -} from '../../../../hooks/affine/use-is-first-load'; +} from '../../../../hooks/use-is-first-load'; import { StyledChangeLog, StyledChangeLogWrapper } from '../shared-styles'; import { StyledLink } from '../style'; diff --git a/apps/web/src/components/pure/workspace-slider-bar/index.tsx b/apps/web/src/components/pure/workspace-slider-bar/index.tsx index 1d9c2f7242..797e4e2856 100644 --- a/apps/web/src/components/pure/workspace-slider-bar/index.tsx +++ b/apps/web/src/components/pure/workspace-slider-bar/index.tsx @@ -11,13 +11,13 @@ import type { Page, PageMeta } from '@blocksuite/store'; import type React from 'react'; import { useCallback, useEffect, useState } from 'react'; +import { usePageMeta } from '../../../hooks/use-page-meta'; import { useSidebarFloating, useSidebarResizing, useSidebarStatus, useSidebarWidth, -} from '../../../hooks/affine/use-sidebar-status'; -import { usePageMeta } from '../../../hooks/use-page-meta'; +} from '../../../hooks/use-sidebar-status'; import type { AllWorkspace } from '../../../shared'; import { SidebarSwitch } from '../../affine/sidebar-switch'; import { ChangeLog } from './changeLog'; diff --git a/apps/web/src/hooks/__tests__/index.spec.tsx b/apps/web/src/hooks/__tests__/index.spec.tsx index 7f72307661..4cb0c1d917 100644 --- a/apps/web/src/hooks/__tests__/index.spec.tsx +++ b/apps/web/src/hooks/__tests__/index.spec.tsx @@ -23,21 +23,21 @@ import { beforeAll, beforeEach, describe, expect, test, vi } from 'vitest'; import { currentWorkspaceIdAtom, workspacesAtom } from '../../atoms'; import { LocalPlugin } from '../../plugins/local'; import { BlockSuiteWorkspace, WorkspaceSubPath } from '../../shared'; +import { + currentWorkspaceAtom, + useCurrentWorkspace, +} from '../current/use-current-workspace'; import { useGuideHidden, useGuideHiddenUntilNextUpdate, useLastVersion, useTipsDisplayStatus, -} from '../affine/use-is-first-load'; +} from '../use-is-first-load'; +import { usePageMeta, usePageMetaHelper } from '../use-page-meta'; import { useRecentlyViewed, useSyncRecentViewsWithRouter, -} from '../affine/use-recent-views'; -import { - currentWorkspaceAtom, - useCurrentWorkspace, -} from '../current/use-current-workspace'; -import { usePageMeta, usePageMetaHelper } from '../use-page-meta'; +} from '../use-recent-views'; import { REDIRECT_TIMEOUT, useSyncRouterWithCurrentWorkspaceAndPage, diff --git a/apps/web/src/hooks/affine/README.md b/apps/web/src/hooks/affine/README.md new file mode 100644 index 0000000000..152e5630a9 --- /dev/null +++ b/apps/web/src/hooks/affine/README.md @@ -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. diff --git a/apps/web/src/hooks/affine/use-is-first-load.ts b/apps/web/src/hooks/use-is-first-load.ts similarity index 98% rename from apps/web/src/hooks/affine/use-is-first-load.ts rename to apps/web/src/hooks/use-is-first-load.ts index dec11ff01e..3436f8f7e9 100644 --- a/apps/web/src/hooks/affine/use-is-first-load.ts +++ b/apps/web/src/hooks/use-is-first-load.ts @@ -6,7 +6,7 @@ import { guideHiddenAtom, guideHiddenUntilNextUpdateAtom, lastVersionAtom, -} from '../../atoms/first-load'; +} from '../atoms/first-load'; export function useLastVersion() { return useAtom(lastVersionAtom); diff --git a/apps/web/src/hooks/affine/use-pinboard-data.ts b/apps/web/src/hooks/use-pinboard-data.ts similarity index 97% rename from apps/web/src/hooks/affine/use-pinboard-data.ts rename to apps/web/src/hooks/use-pinboard-data.ts index 06f80986f7..c7e4945f9f 100644 --- a/apps/web/src/hooks/affine/use-pinboard-data.ts +++ b/apps/web/src/hooks/use-pinboard-data.ts @@ -3,7 +3,7 @@ import type { PageMeta } from '@blocksuite/store'; import type { MouseEvent } from 'react'; import { useMemo } from 'react'; -import type { BlockSuiteWorkspace } from '../../shared'; +import type { BlockSuiteWorkspace } from '../shared'; export type RenderProps = { blockSuiteWorkspace: BlockSuiteWorkspace; diff --git a/apps/web/src/hooks/affine/use-pinboard-handler.ts b/apps/web/src/hooks/use-pinboard-handler.ts similarity index 96% rename from apps/web/src/hooks/affine/use-pinboard-handler.ts rename to apps/web/src/hooks/use-pinboard-handler.ts index 7a30a193b6..c2ed11de99 100644 --- a/apps/web/src/hooks/affine/use-pinboard-handler.ts +++ b/apps/web/src/hooks/use-pinboard-handler.ts @@ -4,9 +4,9 @@ import type { PageMeta } from '@blocksuite/store'; import { nanoid } from '@blocksuite/store'; import { useCallback } from 'react'; -import type { BlockSuiteWorkspace } from '../../shared'; -import { useBlockSuiteWorkspaceHelper } from '../use-blocksuite-workspace-helper'; -import { usePageMetaHelper } from '../use-page-meta'; +import type { BlockSuiteWorkspace } from '../shared'; +import { useBlockSuiteWorkspaceHelper } from './use-blocksuite-workspace-helper'; +import { usePageMetaHelper } from './use-page-meta'; import type { NodeRenderProps, PinboardNode } from './use-pinboard-data'; const logger = new DebugLogger('pinboard'); diff --git a/apps/web/src/hooks/affine/use-recent-views.ts b/apps/web/src/hooks/use-recent-views.ts similarity index 89% rename from apps/web/src/hooks/affine/use-recent-views.ts rename to apps/web/src/hooks/use-recent-views.ts index 61bb97999c..778903478c 100644 --- a/apps/web/src/hooks/affine/use-recent-views.ts +++ b/apps/web/src/hooks/use-recent-views.ts @@ -6,9 +6,9 @@ import { workspacePreferredModeAtom, workspaceRecentViewsAtom, workspaceRecentViresWriteAtom, -} from '../../atoms'; -import { useCurrentWorkspace } from '../current/use-current-workspace'; -import { usePageMeta } from '../use-page-meta'; +} from '../atoms'; +import { useCurrentWorkspace } from './current/use-current-workspace'; +import { usePageMeta } from './use-page-meta'; export function useRecentlyViewed() { const [workspace] = useCurrentWorkspace(); diff --git a/apps/web/src/hooks/affine/use-sidebar-status.ts b/apps/web/src/hooks/use-sidebar-status.ts similarity index 100% rename from apps/web/src/hooks/affine/use-sidebar-status.ts rename to apps/web/src/hooks/use-sidebar-status.ts diff --git a/apps/web/src/layouts/index.tsx b/apps/web/src/layouts/index.tsx index 7ffacf5992..142f411a54 100644 --- a/apps/web/src/layouts/index.tsx +++ b/apps/web/src/layouts/index.tsx @@ -25,18 +25,18 @@ import { import { HelpIsland } from '../components/pure/help-island'; import { PageLoading } from '../components/pure/loading'; 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 { useCurrentWorkspace } from '../hooks/current/use-current-workspace'; import { useBlockSuiteWorkspaceHelper } from '../hooks/use-blocksuite-workspace-helper'; import { useCreateFirstWorkspace } from '../hooks/use-create-first-workspace'; import { useRouterHelper } from '../hooks/use-router-helper'; import { useRouterTitle } from '../hooks/use-router-title'; +import { + useSidebarFloating, + useSidebarResizing, + useSidebarStatus, + useSidebarWidth, +} from '../hooks/use-sidebar-status'; import { useWorkspaces } from '../hooks/use-workspaces'; import { WorkspacePlugins } from '../plugins'; import { ModalProvider } from '../providers/ModalProvider'; diff --git a/apps/web/src/pages/workspace/[workspaceId]/[pageId].tsx b/apps/web/src/pages/workspace/[workspaceId]/[pageId].tsx index 7112f06ab4..244bb2f42d 100644 --- a/apps/web/src/pages/workspace/[workspaceId]/[pageId].tsx +++ b/apps/web/src/pages/workspace/[workspaceId]/[pageId].tsx @@ -5,9 +5,9 @@ import { useEffect } from 'react'; import { Unreachable } from '../../../components/affine/affine-error-eoundary'; import { PageLoading } from '../../../components/pure/loading'; -import { useSyncRecentViewsWithRouter } from '../../../hooks/affine/use-recent-views'; import { useCurrentPageId } from '../../../hooks/current/use-current-page-id'; 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 { WorkspaceLayout } from '../../../layouts'; import { WorkspacePlugins } from '../../../plugins';