mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 06:03:45 +01:00
[web] Pre-labs-release changes for command palette GitOrigin-RevId: 578cf56f1ef51996ce928466edf50e360fa73b42
56 lines
1.3 KiB
TypeScript
56 lines
1.3 KiB
TypeScript
import {
|
|
Dispatch,
|
|
SetStateAction,
|
|
useCallback,
|
|
useEffect,
|
|
useState,
|
|
} from 'react'
|
|
import useCommandPaletteTriggers from '../hooks/use-command-palette-triggers'
|
|
import CommandPaletteBody from './command-palette-body'
|
|
import { useLayoutContext } from '@/shared/context/layout-context'
|
|
import { useCommandProvider } from '@/features/ide-react/hooks/use-command-provider'
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
const CommandPaletteRoot = () => {
|
|
const [show, _setShow] = useState(false)
|
|
const { view } = useLayoutContext()
|
|
const { t } = useTranslation()
|
|
|
|
const setShow: Dispatch<SetStateAction<boolean>> = useCallback(
|
|
value => {
|
|
_setShow(view === 'history' ? false : value)
|
|
},
|
|
[view]
|
|
)
|
|
|
|
useEffect(() => {
|
|
if (view === 'history') {
|
|
_setShow(false)
|
|
}
|
|
}, [view])
|
|
|
|
useCommandPaletteTriggers(setShow)
|
|
const onHide = useCallback(() => setShow(false), [setShow])
|
|
|
|
useCommandProvider(() => {
|
|
if (view === 'history') {
|
|
return
|
|
}
|
|
return [
|
|
{
|
|
id: 'command-palette',
|
|
label: t('command_palette'),
|
|
handler: () => setShow(true),
|
|
},
|
|
]
|
|
}, [view, t, setShow])
|
|
|
|
if (!show) {
|
|
return null
|
|
}
|
|
|
|
return <CommandPaletteBody show={show} onHide={onHide} />
|
|
}
|
|
|
|
export default CommandPaletteRoot
|