mirror of
https://github.com/usebruno/bruno.git
synced 2025-02-16 09:50:17 +01:00
feat: hotkeys (ctrl.cmd E, B, H)
This commit is contained in:
parent
fe900b90c9
commit
6573df41b0
@ -17,7 +17,7 @@ const Placeholder = () => {
|
||||
</div>
|
||||
<div className="flex flex-1 flex-col px-1">
|
||||
<div className="px-1 py-2">Cmd + Enter</div>
|
||||
<div className="px-1 py-2">Cmd + N</div>
|
||||
<div className="px-1 py-2">Cmd + B</div>
|
||||
<div className="px-1 py-2">Cmd + E</div>
|
||||
<div className="px-1 py-2">Cmd + H</div>
|
||||
</div>
|
||||
|
@ -3,6 +3,9 @@ import find from 'lodash/find';
|
||||
import Mousetrap from 'mousetrap';
|
||||
import { useSelector, useDispatch } from 'react-redux';
|
||||
import SaveRequest from 'components/RequestPane/SaveRequest';
|
||||
import EnvironmentSettings from "components/Environments/EnvironmentSettings";
|
||||
import NewRequest from "components/Sidebar/NewRequest";
|
||||
import BrunoSupport from 'components/BrunoSupport';
|
||||
import { sendRequest, saveRequest } from 'providers/ReduxStore/slices/collections/actions';
|
||||
import { findCollectionByUid, findItemInCollection } from 'utils/collections';
|
||||
|
||||
@ -14,6 +17,9 @@ export const HotkeysProvider = props => {
|
||||
const collections = useSelector((state) => state.collections.collections);
|
||||
const activeTabUid = useSelector((state) => state.tabs.activeTabUid);
|
||||
const [showSaveRequestModal, setShowSaveRequestModal] = useState(false);
|
||||
const [showEnvSettingsModal, setShowEnvSettingsModal] = useState(false);
|
||||
const [showNewRequestModal, setShowNewRequestModal] = useState(false);
|
||||
const [showBrunoSupportModal, setShowBrunoSupportModal] = useState(false);
|
||||
|
||||
const getCurrentCollectionItems = () => {
|
||||
const activeTab = find(tabs, (t) => t.uid === activeTabUid);
|
||||
@ -24,6 +30,15 @@ export const HotkeysProvider = props => {
|
||||
};
|
||||
};
|
||||
|
||||
const getCurrentCollection = () => {
|
||||
const activeTab = find(tabs, (t) => t.uid === activeTabUid);
|
||||
if(activeTab) {
|
||||
const collection = findCollectionByUid(collections, activeTab.collectionUid);
|
||||
|
||||
return collection;
|
||||
};
|
||||
};
|
||||
|
||||
// save hotkey
|
||||
useEffect(() => {
|
||||
Mousetrap.bind(['command+s', 'ctrl+s'], (e) => {
|
||||
@ -71,9 +86,64 @@ export const HotkeysProvider = props => {
|
||||
};
|
||||
}, [activeTabUid, tabs, saveRequest, collections]);
|
||||
|
||||
// edit environmentss (ctrl/cmd + e)
|
||||
useEffect(() => {
|
||||
Mousetrap.bind(['command+e', 'ctrl+e'], (e) => {
|
||||
const activeTab = find(tabs, (t) => t.uid === activeTabUid);
|
||||
if(activeTab) {
|
||||
const collection = findCollectionByUid(collections, activeTab.collectionUid);
|
||||
|
||||
if(collection) {
|
||||
setShowEnvSettingsModal(true);
|
||||
}
|
||||
}
|
||||
|
||||
return false; // this stops the event bubbling
|
||||
});
|
||||
|
||||
return () => {
|
||||
Mousetrap.unbind(['command+e', 'ctrl+e']);
|
||||
};
|
||||
}, [activeTabUid, tabs, collections, setShowEnvSettingsModal]);
|
||||
|
||||
// new request (ctrl/cmd + b)
|
||||
useEffect(() => {
|
||||
Mousetrap.bind(['command+b', 'ctrl+b'], (e) => {
|
||||
const activeTab = find(tabs, (t) => t.uid === activeTabUid);
|
||||
if(activeTab) {
|
||||
const collection = findCollectionByUid(collections, activeTab.collectionUid);
|
||||
|
||||
if(collection) {
|
||||
setShowNewRequestModal(true);
|
||||
}
|
||||
}
|
||||
|
||||
return false; // this stops the event bubbling
|
||||
});
|
||||
|
||||
return () => {
|
||||
Mousetrap.unbind(['command+b', 'ctrl+b']);
|
||||
};
|
||||
}, [activeTabUid, tabs, collections, setShowNewRequestModal]);
|
||||
|
||||
// help (ctrl/cmd + h)
|
||||
useEffect(() => {
|
||||
Mousetrap.bind(['command+h', 'ctrl+h'], (e) => {
|
||||
setShowBrunoSupportModal(true);
|
||||
return false; // this stops the event bubbling
|
||||
});
|
||||
|
||||
return () => {
|
||||
Mousetrap.unbind(['command+h', 'ctrl+h']);
|
||||
};
|
||||
}, [setShowNewRequestModal]);
|
||||
|
||||
return (
|
||||
<HotkeysContext.Provider {...props} value='hotkey'>
|
||||
{showBrunoSupportModal && <BrunoSupport onClose={() => setShowBrunoSupportModal(false)}/>}
|
||||
{showSaveRequestModal && <SaveRequest items={getCurrentCollectionItems()} onClose={() => setShowSaveRequestModal(false)}/>}
|
||||
{showEnvSettingsModal && <EnvironmentSettings collection={getCurrentCollection()} onClose={() => setShowEnvSettingsModal(false)}/>}
|
||||
{showNewRequestModal && <NewRequest collection={getCurrentCollection()} onClose={() => setShowNewRequestModal(false)}/>}
|
||||
<div>
|
||||
{props.children}
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user