mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
refactor: use useCallback (#3254)
(cherry picked from commit c0749fbb9f)
This commit is contained in:
@@ -109,7 +109,7 @@ export const BlockSuitePageList: React.FC<BlockSuitePageListProps> = ({
|
|||||||
const { createPage, createEdgeless, importFile, isPreferredEdgeless } =
|
const { createPage, createEdgeless, importFile, isPreferredEdgeless } =
|
||||||
usePageHelper(blockSuiteWorkspace);
|
usePageHelper(blockSuiteWorkspace);
|
||||||
const t = useAFFiNEI18N();
|
const t = useAFFiNEI18N();
|
||||||
const getPageInfo = useGetPageInfoById();
|
const getPageInfo = useGetPageInfoById(blockSuiteWorkspace);
|
||||||
const tagOptionMap = useMemo(
|
const tagOptionMap = useMemo(
|
||||||
() =>
|
() =>
|
||||||
Object.fromEntries(
|
Object.fromEntries(
|
||||||
|
|||||||
@@ -255,7 +255,7 @@ const CollectionRenderer = ({
|
|||||||
export const CollectionsList = ({ workspace }: CollectionsListProps) => {
|
export const CollectionsList = ({ workspace }: CollectionsListProps) => {
|
||||||
const metas = useBlockSuitePageMeta(workspace);
|
const metas = useBlockSuitePageMeta(workspace);
|
||||||
const { savedCollections } = useSavedCollections(workspace.id);
|
const { savedCollections } = useSavedCollections(workspace.id);
|
||||||
const getPageInfo = useGetPageInfoById();
|
const getPageInfo = useGetPageInfoById(workspace);
|
||||||
return (
|
return (
|
||||||
<div data-testid="collections" className={styles.wrapper}>
|
<div data-testid="collections" className={styles.wrapper}>
|
||||||
{savedCollections
|
{savedCollections
|
||||||
|
|||||||
@@ -35,7 +35,9 @@ export function WorkspaceHeader({
|
|||||||
|
|
||||||
const currentWorkspace = useWorkspace(currentWorkspaceId);
|
const currentWorkspace = useWorkspace(currentWorkspaceId);
|
||||||
|
|
||||||
const getPageInfoById = useGetPageInfoById();
|
const getPageInfoById = useGetPageInfoById(
|
||||||
|
currentWorkspace.blockSuiteWorkspace
|
||||||
|
);
|
||||||
if ('subPath' in currentEntry) {
|
if ('subPath' in currentEntry) {
|
||||||
if (currentEntry.subPath === WorkspaceSubPath.ALL) {
|
if (currentEntry.subPath === WorkspaceSubPath.ALL) {
|
||||||
const leftSlot = (
|
const leftSlot = (
|
||||||
|
|||||||
@@ -1,27 +1,29 @@
|
|||||||
import type { GetPageInfoById } from '@affine/env/page-info';
|
import type { GetPageInfoById } from '@affine/env/page-info';
|
||||||
|
import type { Workspace } from '@blocksuite/store';
|
||||||
import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page-meta';
|
import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page-meta';
|
||||||
import { useAtomValue } from 'jotai';
|
import { useAtomValue } from 'jotai';
|
||||||
import { useMemo } from 'react';
|
import { useCallback, useMemo } from 'react';
|
||||||
|
|
||||||
import { pageSettingsAtom } from '../atoms';
|
import { pageSettingsAtom } from '../atoms';
|
||||||
import { useCurrentWorkspace } from './current/use-current-workspace';
|
|
||||||
|
|
||||||
export const useGetPageInfoById = (): GetPageInfoById => {
|
export const useGetPageInfoById = (workspace: Workspace): GetPageInfoById => {
|
||||||
const [currentWorkspace] = useCurrentWorkspace();
|
const pageMetas = useBlockSuitePageMeta(workspace);
|
||||||
const pageMetas = useBlockSuitePageMeta(currentWorkspace.blockSuiteWorkspace);
|
|
||||||
const pageMap = useMemo(
|
const pageMap = useMemo(
|
||||||
() => Object.fromEntries(pageMetas.map(page => [page.id, page])),
|
() => Object.fromEntries(pageMetas.map(page => [page.id, page])),
|
||||||
[pageMetas]
|
[pageMetas]
|
||||||
);
|
);
|
||||||
const pageSettings = useAtomValue(pageSettingsAtom);
|
const pageSettings = useAtomValue(pageSettingsAtom);
|
||||||
return (id: string) => {
|
return useCallback(
|
||||||
const page = pageMap[id];
|
(id: string) => {
|
||||||
if (!page) {
|
const page = pageMap[id];
|
||||||
return;
|
if (!page) {
|
||||||
}
|
return;
|
||||||
return {
|
}
|
||||||
...page,
|
return {
|
||||||
isEdgeless: pageSettings[id]?.mode === 'edgeless',
|
...page,
|
||||||
};
|
isEdgeless: pageSettings[id]?.mode === 'edgeless',
|
||||||
};
|
};
|
||||||
|
},
|
||||||
|
[pageMap, pageSettings]
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user