mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-25 18:32:00 +03:00
fix(core): fix cmdk not show current page (#6031)
This commit is contained in:
parent
5d63ca0bab
commit
633a5bab53
@ -7,10 +7,14 @@ function noopSubscribe() {
|
|||||||
return () => {};
|
return () => {};
|
||||||
}
|
}
|
||||||
|
|
||||||
function noopGetSnapshot() {
|
function nullGetSnapshot() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function undefinedGetSnapshot() {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* subscribe LiveData and return the value.
|
* subscribe LiveData and return the value.
|
||||||
*/
|
*/
|
||||||
@ -25,7 +29,11 @@ export function useLiveData<Input extends LiveData<any> | null | undefined>(
|
|||||||
: never {
|
: never {
|
||||||
return useSyncExternalStore(
|
return useSyncExternalStore(
|
||||||
liveData ? liveData.reactSubscribe : noopSubscribe,
|
liveData ? liveData.reactSubscribe : noopSubscribe,
|
||||||
liveData ? liveData.reactGetSnapshot : noopGetSnapshot
|
liveData
|
||||||
|
? liveData.reactGetSnapshot
|
||||||
|
: liveData === undefined
|
||||||
|
? undefinedGetSnapshot
|
||||||
|
: nullGetSnapshot
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { useBlockSuiteDocMeta } from '@affine/core/hooks/use-block-suite-page-meta';
|
|
||||||
import { useWorkspaceStatus } from '@affine/core/hooks/use-workspace-status';
|
import { useWorkspaceStatus } from '@affine/core/hooks/use-workspace-status';
|
||||||
import { assertExists } from '@blocksuite/global/utils';
|
import { assertExists } from '@blocksuite/global/utils';
|
||||||
import {
|
import {
|
||||||
@ -10,12 +9,12 @@ import {
|
|||||||
useSensor,
|
useSensor,
|
||||||
useSensors,
|
useSensors,
|
||||||
} from '@dnd-kit/core';
|
} from '@dnd-kit/core';
|
||||||
import { Workspace } from '@toeverything/infra';
|
import { PageRecordList, useLiveData, Workspace } from '@toeverything/infra';
|
||||||
import { useService } from '@toeverything/infra/di';
|
import { useService } from '@toeverything/infra/di';
|
||||||
import { useAtom, useAtomValue, useSetAtom } from 'jotai';
|
import { useAtom, useAtomValue, useSetAtom } from 'jotai';
|
||||||
import type { PropsWithChildren, ReactNode } from 'react';
|
import type { PropsWithChildren, ReactNode } from 'react';
|
||||||
import { lazy, Suspense, useCallback, useEffect, useState } from 'react';
|
import { lazy, Suspense, useCallback, useEffect, useState } from 'react';
|
||||||
import { useParams } from 'react-router-dom';
|
import { matchPath, useParams } from 'react-router-dom';
|
||||||
import { Map as YMap } from 'yjs';
|
import { Map as YMap } from 'yjs';
|
||||||
|
|
||||||
import { openQuickSearchModalAtom, openSettingModalAtom } from '../atoms';
|
import { openQuickSearchModalAtom, openSettingModalAtom } from '../atoms';
|
||||||
@ -37,6 +36,7 @@ import { useAppSettingHelper } from '../hooks/affine/use-app-setting-helper';
|
|||||||
import { useSidebarDrag } from '../hooks/affine/use-sidebar-drag';
|
import { useSidebarDrag } from '../hooks/affine/use-sidebar-drag';
|
||||||
import { useNavigateHelper } from '../hooks/use-navigate-helper';
|
import { useNavigateHelper } from '../hooks/use-navigate-helper';
|
||||||
import { useRegisterWorkspaceCommands } from '../hooks/use-register-workspace-commands';
|
import { useRegisterWorkspaceCommands } from '../hooks/use-register-workspace-commands';
|
||||||
|
import { Workbench } from '../modules/workbench';
|
||||||
import {
|
import {
|
||||||
AllWorkspaceModals,
|
AllWorkspaceModals,
|
||||||
CurrentWorkspaceModals,
|
CurrentWorkspaceModals,
|
||||||
@ -55,16 +55,15 @@ export const QuickSearch = () => {
|
|||||||
openQuickSearchModalAtom
|
openQuickSearchModalAtom
|
||||||
);
|
);
|
||||||
|
|
||||||
const currentWorkspace = useService(Workspace);
|
const workbench = useService(Workbench);
|
||||||
const { pageId } = useParams();
|
const currentPath = useLiveData(workbench.location.map(l => l.pathname));
|
||||||
const blockSuiteWorkspace = currentWorkspace.blockSuiteWorkspace;
|
const pageRecordList = useService(PageRecordList);
|
||||||
const pageMeta = useBlockSuiteDocMeta(
|
const currentPathId = matchPath('/:pageId', currentPath)?.params.pageId;
|
||||||
currentWorkspace.blockSuiteWorkspace
|
// TODO: getting pageid from route is fragile, get current page from context
|
||||||
).find(meta => meta.id === pageId);
|
const currentPage = useLiveData(
|
||||||
|
currentPathId ? pageRecordList.record(currentPathId) : null
|
||||||
if (!blockSuiteWorkspace) {
|
);
|
||||||
return null;
|
const pageMeta = useLiveData(currentPage?.meta);
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CMDKQuickSearchModal
|
<CMDKQuickSearchModal
|
||||||
|
Loading…
Reference in New Issue
Block a user