diff --git a/renderer/providers/Hotkeys/index.js b/renderer/providers/Hotkeys/index.js index eec833b44..1adcfdff2 100644 --- a/renderer/providers/Hotkeys/index.js +++ b/renderer/providers/Hotkeys/index.js @@ -1,21 +1,22 @@ import React, { useEffect } from 'react'; import find from 'lodash/find'; import Mousetrap from 'mousetrap'; -import { saveRequest } from 'providers/ReduxStore/slices/collections'; -import { requestSaved } from 'providers/ReduxStore/slices/tabs'; import { useSelector, useDispatch } from 'react-redux'; +import { saveRequest, sendRequest } from 'providers/ReduxStore/slices/collections'; +import { requestSaved } from 'providers/ReduxStore/slices/tabs'; +import { findCollectionByUid, findItemInCollection } from 'utils/collections'; export const HotkeysContext = React.createContext(); export const HotkeysProvider = props => { const dispatch = useDispatch(); const tabs = useSelector((state) => state.tabs.tabs); + const collections = useSelector((state) => state.collections.collections); const activeTabUid = useSelector((state) => state.tabs.activeTabUid); + // save hotkey useEffect(() => { Mousetrap.bind(['command+s', 'ctrl+s'], (e) => { - console.log("Save hotkey"); - if(activeTabUid) { const activeTab = find(tabs, (t) => t.uid === activeTabUid); if(activeTab) { @@ -35,6 +36,31 @@ export const HotkeysProvider = props => { }; }, [activeTabUid, tabs, saveRequest, requestSaved]); + // send request (ctrl/cmd + enter) + useEffect(() => { + Mousetrap.bind(['ctrl+command', 'ctrl+enter'], (e) => { + if(activeTabUid) { + const activeTab = find(tabs, (t) => t.uid === activeTabUid); + if(activeTab) { + const collection = findCollectionByUid(collections, activeTab.collectionUid); + + if(collection) { + const item = findItemInCollection(collection, activeTab.uid); + if(item) { + dispatch(sendRequest(item, collection.uid)); + } + } + } + } + + return false; // this stops the event bubbling + }); + + return () => { + Mousetrap.unbind(['command+s', 'ctrl+s']); + }; + }, [activeTabUid, tabs, saveRequest, requestSaved, collections]); + return ( {props.children}