diff --git a/.changeset/funny-onions-exercise.md b/.changeset/funny-onions-exercise.md new file mode 100644 index 000000000000..3f1f49cf8594 --- /dev/null +++ b/.changeset/funny-onions-exercise.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': patch +--- + +Add a shortcut to jump to Home page on Ctrl + h diff --git a/apps/meteor/client/views/root/hooks/useEscapeKeyStroke.ts b/apps/meteor/client/views/root/hooks/useEscapeKeyStroke.ts index 3dc629340f4b..50e746a88ee9 100644 --- a/apps/meteor/client/views/root/hooks/useEscapeKeyStroke.ts +++ b/apps/meteor/client/views/root/hooks/useEscapeKeyStroke.ts @@ -1,4 +1,4 @@ -import { useToastMessageDispatch } from '@rocket.chat/ui-contexts'; +import { useToastMessageDispatch, useRouter } from '@rocket.chat/ui-contexts'; import { useEffect } from 'react'; import { useTranslation } from 'react-i18next'; @@ -9,6 +9,7 @@ import { imperativeModal } from '../../../lib/imperativeModal'; export const useEscapeKeyStroke = () => { const dispatchToastMessage = useToastMessageDispatch(); const { t } = useTranslation(); + const router = useRouter(); const clearUnreadAllMessagesMutation = useClearUnreadAllMessagesMutation({ onError: (error) => { @@ -48,4 +49,23 @@ export const useEscapeKeyStroke = () => { document.body.removeEventListener('keydown', handleKeyDown); }; }, [clearUnreadAllMessagesMutation.mutate, dispatchToastMessage, t]); + + useEffect(() => { + const handleKeyDown = (event: KeyboardEvent) => { + if (event.key !== 'h' || !event.ctrlKey === true) { + return; + } + + event.preventDefault(); + event.stopPropagation(); + + router.navigate('/home'); + }; + + window.addEventListener('keydown', handleKeyDown); + + return () => { + window.removeEventListener('keydown', handleKeyDown); + }; + }, [router]); };