mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-11 14:08:55 +08:00
Merge branch 'feat/dev' of github.com:toeverything/AFFiNE into feat/dev
This commit is contained in:
@@ -3,9 +3,9 @@ import JumpTo from './JumpTo';
|
|||||||
import { Command } from 'cmdk';
|
import { Command } from 'cmdk';
|
||||||
import SearchResult from './searchResult';
|
import SearchResult from './searchResult';
|
||||||
|
|
||||||
const Result = (props: { search: string }) => {
|
const Result = (props: { result: string }) => {
|
||||||
return (
|
return (
|
||||||
<Command.List>{props.search ? <SearchResult /> : <JumpTo />}</Command.List>
|
<Command.List>{props.result ? <SearchResult /> : <JumpTo />}</Command.List>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import NoResult from './NotFound';
|
import NoResult from './NotFound';
|
||||||
import { Command } from 'cmdk';
|
import { Command } from 'cmdk';
|
||||||
import Store from '@blocksuite/store';
|
|
||||||
|
|
||||||
const SearchResult = () => {
|
const SearchResult = () => {
|
||||||
return (
|
return (
|
||||||
@@ -10,7 +9,6 @@ const SearchResult = () => {
|
|||||||
<Command.Group heading="Letters">
|
<Command.Group heading="Letters">
|
||||||
<Command.Item>a</Command.Item>
|
<Command.Item>a</Command.Item>
|
||||||
<Command.Item>b</Command.Item>
|
<Command.Item>b</Command.Item>
|
||||||
<Command.Separator />
|
|
||||||
<Command.Item>c</Command.Item>
|
<Command.Item>c</Command.Item>
|
||||||
</Command.Group>
|
</Command.Group>
|
||||||
<Command.Item>Apple</Command.Item>
|
<Command.Item>Apple</Command.Item>
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import Result from './content';
|
|||||||
import QuickSearchFooter from './Footer';
|
import QuickSearchFooter from './Footer';
|
||||||
import { Command } from 'cmdk';
|
import { Command } from 'cmdk';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
import { useEditor } from '@/providers/editor-provider';
|
||||||
type TransitionsModalProps = {
|
type TransitionsModalProps = {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
@@ -19,7 +20,11 @@ const isMac = () => {
|
|||||||
return /macintosh|mac os x/i.test(navigator.userAgent);
|
return /macintosh|mac os x/i.test(navigator.userAgent);
|
||||||
};
|
};
|
||||||
export const QuickSearch = ({ open, onClose }: TransitionsModalProps) => {
|
export const QuickSearch = ({ open, onClose }: TransitionsModalProps) => {
|
||||||
const [search, setSearch] = useState('');
|
const [query, setQuery] = useState('');
|
||||||
|
const [result, setResult] = useState({});
|
||||||
|
const { search } = useEditor();
|
||||||
|
const { pageList } = useEditor();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal open={open} onClose={onClose} wrapperPosition={['top', 'center']}>
|
<Modal open={open} onClose={onClose} wrapperPosition={['top', 'center']}>
|
||||||
<ModalWrapper
|
<ModalWrapper
|
||||||
@@ -34,12 +39,12 @@ export const QuickSearch = ({ open, onClose }: TransitionsModalProps) => {
|
|||||||
>
|
>
|
||||||
<Command>
|
<Command>
|
||||||
<StyledModalHeader>
|
<StyledModalHeader>
|
||||||
<Input search={search} setSearch={setSearch} />
|
<Input query={query} setQuery={setQuery} />
|
||||||
<StyledShortcut>{isMac() ? '⌘+K' : 'Ctrl+K'}</StyledShortcut>
|
<StyledShortcut>{isMac() ? '⌘+K' : 'Ctrl+K'}</StyledShortcut>
|
||||||
</StyledModalHeader>
|
</StyledModalHeader>
|
||||||
<StyledModalDivider />
|
<StyledModalDivider />
|
||||||
<StyledContent>
|
<StyledContent>
|
||||||
<Result search={search} />
|
<Result result={query} />
|
||||||
</StyledContent>
|
</StyledContent>
|
||||||
|
|
||||||
<StyledModalFooter>
|
<StyledModalFooter>
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import { MiddleSearchIcon } from '@blocksuite/icons';
|
|||||||
import { StyledInputContent, StyledLabel } from './style';
|
import { StyledInputContent, StyledLabel } from './style';
|
||||||
import { Command } from 'cmdk';
|
import { Command } from 'cmdk';
|
||||||
const Input = (props: {
|
const Input = (props: {
|
||||||
search: string;
|
query: string;
|
||||||
setSearch: Dispatch<SetStateAction<string>>;
|
setQuery: Dispatch<SetStateAction<string>>;
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<StyledInputContent>
|
<StyledInputContent>
|
||||||
@@ -12,8 +12,8 @@ const Input = (props: {
|
|||||||
<MiddleSearchIcon />
|
<MiddleSearchIcon />
|
||||||
</StyledLabel>
|
</StyledLabel>
|
||||||
<Command.Input
|
<Command.Input
|
||||||
value={props.search}
|
value={props.query}
|
||||||
onValueChange={props.setSearch}
|
onValueChange={props.setQuery}
|
||||||
placeholder="Quick Search..."
|
placeholder="Quick Search..."
|
||||||
/>
|
/>
|
||||||
</StyledInputContent>
|
</StyledInputContent>
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import Loading from './loading';
|
|||||||
import { Page, Workspace } from '@blocksuite/store';
|
import { Page, Workspace } from '@blocksuite/store';
|
||||||
import { BlockSchema } from '@blocksuite/editor/dist/block-loader';
|
import { BlockSchema } from '@blocksuite/editor/dist/block-loader';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
|
import { QueryContent } from '@blocksuite/store/dist/workspace/search';
|
||||||
export interface PageMeta {
|
export interface PageMeta {
|
||||||
id: string;
|
id: string;
|
||||||
title: string;
|
title: string;
|
||||||
@@ -40,6 +41,7 @@ type EditorHandlers = {
|
|||||||
unFavoritePage: (pageId: string) => void;
|
unFavoritePage: (pageId: string) => void;
|
||||||
toggleFavoritePage: (pageId: string) => void;
|
toggleFavoritePage: (pageId: string) => void;
|
||||||
permanentlyDeletePage: (pageId: string) => void;
|
permanentlyDeletePage: (pageId: string) => void;
|
||||||
|
search: (query: QueryContent) => any;
|
||||||
};
|
};
|
||||||
|
|
||||||
type EditorContextProps = PropsWithChildren<{}>;
|
type EditorContextProps = PropsWithChildren<{}>;
|
||||||
@@ -61,6 +63,7 @@ export const EditorContext = createContext<EditorContextValue>({
|
|||||||
unFavoritePage: () => {},
|
unFavoritePage: () => {},
|
||||||
toggleFavoritePage: () => {},
|
toggleFavoritePage: () => {},
|
||||||
permanentlyDeletePage: () => {},
|
permanentlyDeletePage: () => {},
|
||||||
|
search: () => {},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const useEditor = () => useContext(EditorContext);
|
export const useEditor = () => useContext(EditorContext);
|
||||||
@@ -137,6 +140,11 @@ export const EditorProvider = ({
|
|||||||
workspace?.setPageMeta(pageId, { favorite: !pageMeta.favorite });
|
workspace?.setPageMeta(pageId, { favorite: !pageMeta.favorite });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
search: (query: QueryContent) => {
|
||||||
|
if (query) {
|
||||||
|
return workspace?.search(query);
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user