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