mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-17 01:56:27 +08:00
chore: update hotkey and style
This commit is contained in:
@@ -6,19 +6,30 @@ import {
|
||||
} from '@blocksuite/icons';
|
||||
import Link from 'next/link';
|
||||
import { StyledJumpTo } from '../style';
|
||||
import { useModal } from '@/providers/global-modal-provider';
|
||||
const JumpTo = () => {
|
||||
const { triggerQuickSearchModal } = useModal();
|
||||
return (
|
||||
<StyledJumpTo>
|
||||
<strong>Jump to</strong>
|
||||
<Link href={{ pathname: '/all-page', query: { name: 'test' } }}>
|
||||
<Link
|
||||
href={{ pathname: '/page-list/all' }}
|
||||
onClick={() => triggerQuickSearchModal()}
|
||||
>
|
||||
<MiddleAllPagesIcon width={20} height={20} />
|
||||
<span> All pages</span>
|
||||
</Link>
|
||||
<Link href={'/'}>
|
||||
<Link
|
||||
href={{ pathname: '/page-list/favorite' }}
|
||||
onClick={() => triggerQuickSearchModal()}
|
||||
>
|
||||
<MiddleFavouritesIcon width={20} height={20} />
|
||||
<span> Favourites</span>
|
||||
</Link>
|
||||
<Link href={'/'}>
|
||||
<Link
|
||||
href={{ pathname: '/page-list/trash' }}
|
||||
onClick={() => triggerQuickSearchModal()}
|
||||
>
|
||||
<MiddleTrashIcon width={20} height={20} />
|
||||
<span> Trash</span>
|
||||
</Link>
|
||||
|
||||
@@ -2,16 +2,19 @@ import React from 'react';
|
||||
import { MiddleAddIcon } from '@blocksuite/icons';
|
||||
import { StyledModalFooterContent } from './style';
|
||||
import { useEditor } from '@/providers/editor-provider';
|
||||
import { useModal } from '@/providers/global-modal-provider';
|
||||
import { IconButton } from '@/ui/button';
|
||||
|
||||
const QuickSearchFooter = () => {
|
||||
const { createPage } = useEditor();
|
||||
const { triggerQuickSearchModal } = useModal();
|
||||
return (
|
||||
<StyledModalFooterContent>
|
||||
<IconButton>
|
||||
<MiddleAddIcon
|
||||
onClick={() => {
|
||||
createPage();
|
||||
triggerQuickSearchModal();
|
||||
}}
|
||||
/>
|
||||
</IconButton>
|
||||
|
||||
@@ -10,8 +10,9 @@ import Input from './Input';
|
||||
import Result from './content';
|
||||
import QuickSearchFooter from './Footer';
|
||||
import { Command } from 'cmdk';
|
||||
import { useState } from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useEditor } from '@/providers/editor-provider';
|
||||
import { useModal } from '@/providers/global-modal-provider';
|
||||
type TransitionsModalProps = {
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
@@ -21,10 +22,29 @@ const isMac = () => {
|
||||
};
|
||||
export const QuickSearch = ({ open, onClose }: TransitionsModalProps) => {
|
||||
const [query, setQuery] = useState('');
|
||||
const [result, setResult] = useState({});
|
||||
const { search } = useEditor();
|
||||
const [result, setResult] = useState({});
|
||||
const { pageList } = useEditor();
|
||||
|
||||
const { triggerQuickSearchModal } = useModal();
|
||||
useEffect(() => {
|
||||
setResult(search(query, { enrich: true }));
|
||||
}, [query]);
|
||||
useEffect(() => {
|
||||
const down = (e: KeyboardEvent) => {
|
||||
if (e.key === 'k' && e.metaKey) {
|
||||
const selection = window.getSelection();
|
||||
if (selection?.toString()) {
|
||||
triggerQuickSearchModal(false);
|
||||
return;
|
||||
}
|
||||
if (selection?.isCollapsed) {
|
||||
triggerQuickSearchModal(!open);
|
||||
}
|
||||
}
|
||||
};
|
||||
document.addEventListener('keydown', down);
|
||||
return () => document.removeEventListener('keydown', down);
|
||||
}, [open]);
|
||||
return (
|
||||
<Modal open={open} onClose={onClose} wrapperPosition={['top', 'center']}>
|
||||
<ModalWrapper
|
||||
|
||||
@@ -36,18 +36,21 @@ export const StyledJumpTo = styled('div')(({ theme }) => {
|
||||
marginBottom: '10px',
|
||||
},
|
||||
a: {
|
||||
color: theme.colors.popoverColor,
|
||||
color: 'inherit',
|
||||
padding: '5px 5px 5px 0',
|
||||
...displayFlex('center', 'center'),
|
||||
':visited': {
|
||||
color: theme.colors.popoverColor,
|
||||
},
|
||||
':hover': {
|
||||
color: theme.colors.primaryColor,
|
||||
},
|
||||
transition: `color .15s`,
|
||||
svg: {
|
||||
marginBottom: '2px',
|
||||
},
|
||||
span: {
|
||||
marginLeft: '12px',
|
||||
|
||||
lineHeight: '22px',
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { createContext, useContext, useEffect, useState } from 'react';
|
||||
import { createContext, useContext, useState } from 'react';
|
||||
import type { PropsWithChildren } from 'react';
|
||||
import ShortcutsModal from '@/components/shortcuts-modal';
|
||||
import ContactModal from '@/components/contact-modal';
|
||||
@@ -8,7 +8,7 @@ import { ImportModal } from '@/components/import';
|
||||
type ModalContextValue = {
|
||||
triggerShortcutsModal: () => void;
|
||||
triggerContactModal: () => void;
|
||||
triggerQuickSearchModal: () => void;
|
||||
triggerQuickSearchModal: (visible?: boolean) => void;
|
||||
triggerImportModal: () => void;
|
||||
};
|
||||
type ModalContextProps = PropsWithChildren<{}>;
|
||||
@@ -22,7 +22,7 @@ type ModalMap = {
|
||||
export const ModalContext = createContext<ModalContextValue>({
|
||||
triggerShortcutsModal: () => {},
|
||||
triggerContactModal: () => {},
|
||||
triggerQuickSearchModal: () => {},
|
||||
triggerQuickSearchModal: (visible?) => {},
|
||||
triggerImportModal: () => {},
|
||||
});
|
||||
|
||||
@@ -45,23 +45,6 @@ export const ModalProvider = ({
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const down = (e: KeyboardEvent) => {
|
||||
if (e.key === 'k' && e.metaKey) {
|
||||
const selection = window.getSelection();
|
||||
if (selection?.toString()) {
|
||||
triggerHandler('quickSearch', false);
|
||||
return;
|
||||
}
|
||||
if (selection?.isCollapsed) {
|
||||
triggerHandler('quickSearch');
|
||||
}
|
||||
}
|
||||
};
|
||||
document.addEventListener('keydown', down);
|
||||
return () => document.removeEventListener('keydown', down);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<ModalContext.Provider
|
||||
value={{
|
||||
@@ -71,8 +54,8 @@ export const ModalProvider = ({
|
||||
triggerContactModal: () => {
|
||||
triggerHandler('contact');
|
||||
},
|
||||
triggerQuickSearchModal: () => {
|
||||
triggerHandler('quickSearch');
|
||||
triggerQuickSearchModal: (visible?) => {
|
||||
triggerHandler('quickSearch', visible);
|
||||
},
|
||||
triggerImportModal: () => {
|
||||
triggerHandler('import');
|
||||
|
||||
Reference in New Issue
Block a user