mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-16 17:46:18 +08:00
fix: fix quick search
This commit is contained in:
@@ -1,20 +1,22 @@
|
||||
import { AllPagesIcon, FavouritesIcon, TrashIcon } from '@blocksuite/icons';
|
||||
|
||||
// FIXME: href changed
|
||||
export const List = [
|
||||
{
|
||||
title: 'All pages',
|
||||
href: '/page-list/all',
|
||||
icon: AllPagesIcon,
|
||||
},
|
||||
{
|
||||
title: 'Favourites',
|
||||
href: '/page-list/favorite',
|
||||
icon: FavouritesIcon,
|
||||
},
|
||||
{
|
||||
title: 'Trash',
|
||||
href: '/page-list/trash',
|
||||
icon: TrashIcon,
|
||||
},
|
||||
];
|
||||
export const config = (currentWorkspaceId: string) => {
|
||||
const List = [
|
||||
{
|
||||
title: 'All pages',
|
||||
href: `/workspace/${currentWorkspaceId}/all`,
|
||||
icon: AllPagesIcon,
|
||||
},
|
||||
{
|
||||
title: 'Favourites',
|
||||
href: `/workspace/${currentWorkspaceId}/favorite`,
|
||||
icon: FavouritesIcon,
|
||||
},
|
||||
{
|
||||
title: 'Trash',
|
||||
href: `/workspace/${currentWorkspaceId}/trash`,
|
||||
icon: TrashIcon,
|
||||
},
|
||||
];
|
||||
return List;
|
||||
};
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
import React from 'react';
|
||||
import { AddIcon } from '@blocksuite/icons';
|
||||
import { StyledModalFooterContent } from './style';
|
||||
import { useEditor } from '@/providers/editor-provider';
|
||||
import { useModal } from '@/providers/global-modal-provider';
|
||||
import { useAppState } from '@/providers/app-state-provider/context';
|
||||
import { Command } from 'cmdk';
|
||||
import { useGoToPage } from '@/providers/app-state-provider/hooks';
|
||||
|
||||
export const Footer = (props: { query: string }) => {
|
||||
const { createPage, openPage } = useEditor();
|
||||
const { createPage } = useAppState();
|
||||
const { triggerQuickSearchModal } = useModal();
|
||||
const goToPage = useGoToPage();
|
||||
const query = props.query;
|
||||
|
||||
return (
|
||||
<Command.Item
|
||||
data-testid="quickSearch-addNewPage"
|
||||
onSelect={async () => {
|
||||
const page = await createPage({ title: query });
|
||||
openPage(page.id);
|
||||
const pageId = await createPage();
|
||||
if (pageId) {
|
||||
goToPage(pageId);
|
||||
}
|
||||
|
||||
triggerQuickSearchModal();
|
||||
}}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import { Command } from 'cmdk';
|
||||
import { StyledListItem, StyledNotFound } from './style';
|
||||
import { useModal } from '@/providers/global-modal-provider';
|
||||
import { PaperIcon, EdgelessIcon, LogoUnlogIcon } from '@blocksuite/icons';
|
||||
import { useEditor } from '@/providers/editor-provider';
|
||||
import { PaperIcon, EdgelessIcon } from '@blocksuite/icons';
|
||||
import { Dispatch, SetStateAction, useEffect, useState } from 'react';
|
||||
import { useAppState } from '@/providers/app-state-provider/context';
|
||||
import { useRouter } from 'next/router';
|
||||
import { List } from './config';
|
||||
|
||||
import { config } from './config';
|
||||
import { useGoToPage } from '@/providers/app-state-provider/hooks';
|
||||
import { usePageList } from '@/providers/app-state-provider/usePageList';
|
||||
import { useLoadWorkspace } from '@/providers/app-state-provider/hooks';
|
||||
export const Results = (props: {
|
||||
query: string;
|
||||
loading: boolean;
|
||||
@@ -18,8 +20,12 @@ export const Results = (props: {
|
||||
const setLoading = props.setLoading;
|
||||
const setShowCreatePage = props.setShowCreatePage;
|
||||
const { triggerQuickSearchModal } = useModal();
|
||||
const { search, openPage, pageList } = useEditor();
|
||||
const workspace = useLoadWorkspace();
|
||||
const pageList = usePageList(workspace);
|
||||
const goToPage = useGoToPage();
|
||||
const router = useRouter();
|
||||
const { search, currentWorkspaceId } = useAppState();
|
||||
const List = config(currentWorkspaceId);
|
||||
const [results, setResults] = useState(new Map<string, string | undefined>());
|
||||
useEffect(() => {
|
||||
setResults(search(query));
|
||||
@@ -46,7 +52,7 @@ export const Results = (props: {
|
||||
<Command.Item
|
||||
key={result.id}
|
||||
onSelect={() => {
|
||||
openPage(result.id);
|
||||
goToPage(result.id);
|
||||
triggerQuickSearchModal();
|
||||
}}
|
||||
value={result.title}
|
||||
@@ -66,7 +72,6 @@ export const Results = (props: {
|
||||
) : (
|
||||
<StyledNotFound>
|
||||
<span>Find 0 result</span>
|
||||
<LogoUnlogIcon />
|
||||
</StyledNotFound>
|
||||
)
|
||||
) : (
|
||||
|
||||
@@ -7,6 +7,7 @@ import type {
|
||||
Workspace as StoreWorkspace,
|
||||
} from '@blocksuite/store';
|
||||
import type { EditorContainer } from '@blocksuite/editor';
|
||||
import { QueryContent } from '@blocksuite/store/dist/workspace/search';
|
||||
|
||||
export interface AppStateValue {
|
||||
user: AccessTokenMessage | null;
|
||||
@@ -32,6 +33,7 @@ export interface AppStateContext extends AppStateValue {
|
||||
getPageMeta: (pageId: string) => PageMeta | null;
|
||||
toggleFavoritePage: (pageId: string) => void;
|
||||
toggleDeletePage: (pageId: string) => void;
|
||||
search: (query: QueryContent) => Map<string, string | undefined>;
|
||||
}
|
||||
|
||||
export const AppState = createContext<AppStateContext>({
|
||||
@@ -54,6 +56,7 @@ export const AppState = createContext<AppStateContext>({
|
||||
getPageMeta: () => null,
|
||||
toggleFavoritePage: () => {},
|
||||
toggleDeletePage: () => {},
|
||||
search: () => new Map<string, string>(),
|
||||
});
|
||||
|
||||
export const useAppState = () => {
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
} from '@pathfinder/data-services';
|
||||
import { AppState } from './context';
|
||||
import type { AppStateValue, AppStateContext } from './context';
|
||||
import { QueryContent } from '@blocksuite/store/dist/workspace/search';
|
||||
|
||||
const DynamicBlocksuite = dynamic(() => import('./dynamic-blocksuite'), {
|
||||
ssr: false,
|
||||
@@ -150,6 +151,10 @@ export const AppStateProvider = ({ children }: { children?: ReactNode }) => {
|
||||
});
|
||||
}
|
||||
},
|
||||
search: (query: QueryContent) => {
|
||||
const { currentWorkspace } = state;
|
||||
return currentWorkspace!.search(query);
|
||||
},
|
||||
}),
|
||||
[state, setState, loadWorkspaceHandler, createEditorHandler]
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user