mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-25 06:32:27 +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 () => {};
|
||||
}
|
||||
|
||||
function noopGetSnapshot() {
|
||||
function nullGetSnapshot() {
|
||||
return null;
|
||||
}
|
||||
|
||||
function undefinedGetSnapshot() {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* subscribe LiveData and return the value.
|
||||
*/
|
||||
@ -25,7 +29,11 @@ export function useLiveData<Input extends LiveData<any> | null | undefined>(
|
||||
: never {
|
||||
return useSyncExternalStore(
|
||||
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 { assertExists } from '@blocksuite/global/utils';
|
||||
import {
|
||||
@ -10,12 +9,12 @@ import {
|
||||
useSensor,
|
||||
useSensors,
|
||||
} from '@dnd-kit/core';
|
||||
import { Workspace } from '@toeverything/infra';
|
||||
import { PageRecordList, useLiveData, Workspace } from '@toeverything/infra';
|
||||
import { useService } from '@toeverything/infra/di';
|
||||
import { useAtom, useAtomValue, useSetAtom } from 'jotai';
|
||||
import type { PropsWithChildren, ReactNode } 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 { 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 { useNavigateHelper } from '../hooks/use-navigate-helper';
|
||||
import { useRegisterWorkspaceCommands } from '../hooks/use-register-workspace-commands';
|
||||
import { Workbench } from '../modules/workbench';
|
||||
import {
|
||||
AllWorkspaceModals,
|
||||
CurrentWorkspaceModals,
|
||||
@ -55,16 +55,15 @@ export const QuickSearch = () => {
|
||||
openQuickSearchModalAtom
|
||||
);
|
||||
|
||||
const currentWorkspace = useService(Workspace);
|
||||
const { pageId } = useParams();
|
||||
const blockSuiteWorkspace = currentWorkspace.blockSuiteWorkspace;
|
||||
const pageMeta = useBlockSuiteDocMeta(
|
||||
currentWorkspace.blockSuiteWorkspace
|
||||
).find(meta => meta.id === pageId);
|
||||
|
||||
if (!blockSuiteWorkspace) {
|
||||
return null;
|
||||
}
|
||||
const workbench = useService(Workbench);
|
||||
const currentPath = useLiveData(workbench.location.map(l => l.pathname));
|
||||
const pageRecordList = useService(PageRecordList);
|
||||
const currentPathId = matchPath('/:pageId', currentPath)?.params.pageId;
|
||||
// TODO: getting pageid from route is fragile, get current page from context
|
||||
const currentPage = useLiveData(
|
||||
currentPathId ? pageRecordList.record(currentPathId) : null
|
||||
);
|
||||
const pageMeta = useLiveData(currentPage?.meta);
|
||||
|
||||
return (
|
||||
<CMDKQuickSearchModal
|
||||
|
Loading…
Reference in New Issue
Block a user