* start moving ui to redux tlk * remove unused reducer * changes for gdpr and site types * ui: migrating duck/roles to mobx * ui: drop unreferenced types * ui: drop unreferenced types * ui: move player slice reducer to mobx family * ui: move assignments to issueReportingStore.ts * remove issues store * some fixes after issues store * remove errors reducer, drop old components * finish removing errors reducer * start moving integrations state to mobx * change(ui): funnel duck cleanup * change(ui): custom fields * change(ui): customMetrics cleanup * change(ui): customMetrics cleanup * change(ui): duck/filters minor cleanup * change(ui): duck/filters cleanup * change(ui): duck/customMetrics cleanup and upgrades * fix integrations service, fix babel config to >.25 + not ie * refactoring integrations reducers etc WIP * finish removing integrations state * some fixes for integrated check * start of projects refactoring * move api and "few" files to new project store * new batch for site -> projects * fix setid context * move all critical components, drop site duck * remove all duck/site refs, remove old components * fixup for SessionTags.tsx, remove duck/sources (?) * move session store * init sessionstore outside of context * fix userfilter * replace simple actions for session store * sessions sotre * Rtm temp (#2597) * change(ui): duck/search wip * change(ui): duck/search wip * change(ui): duck/search wip * change(ui): duck/searchLive wip * change(ui): duck/searchLive wip * change(ui): duck/searchLive wip * change(ui): duck/searchLive wip * change(ui): search states * change(ui): search states * change(ui): search states * change(ui): fix savedSearch store * change(ui): fix savedSearch store * some fixes for session connector * change(ui): fix savedSearch store * change(ui): fix searchLive * change(ui): fix searchLive * fixes for session replay * change(ui): bookmark fetch * last components for sessions * add fetchautoplaylist * finish session reducer, remove deleted reducers * change(ui): fix the search fetch * change(ui): fix the search fetch * fix integrations call ctx * ensure ctx for sessionstore * fix(ui): checking for latest sessions path * start removing user reducer * removing user reducer pt2... * finish user store * remove rand log * fix crashes * tinkering workflow file for tracker test * making sure prefetched sessions work properly * fix conflict * fix router redirects during loading --------- Co-authored-by: Shekar Siri <sshekarsiri@gmail.com>
122 lines
3.6 KiB
TypeScript
122 lines
3.6 KiB
TypeScript
import copy from 'copy-to-clipboard';
|
|
import { useContext, useEffect } from 'react';
|
|
import { toast } from 'react-toastify';
|
|
|
|
import { PlayerContext } from 'Components/Session/playerContext';
|
|
import { SKIP_INTERVALS } from 'Components/Session_/Player/Controls/Controls';
|
|
import { blockValues, blocks } from 'App/mstore/uiPlayerStore';
|
|
|
|
function useShortcuts({
|
|
skipInterval,
|
|
fullScreenOn,
|
|
fullScreenOff,
|
|
toggleBottomBlock,
|
|
openNextSession,
|
|
openPrevSession,
|
|
setActiveTab,
|
|
disableDevtools,
|
|
}: {
|
|
skipInterval: keyof typeof SKIP_INTERVALS;
|
|
fullScreenOn: () => void;
|
|
fullScreenOff: () => void;
|
|
toggleBottomBlock: (blockName: (typeof blockValues)[number]) => void;
|
|
openNextSession: () => void;
|
|
openPrevSession: () => void;
|
|
setActiveTab: (tab: string) => void;
|
|
disableDevtools?: boolean;
|
|
}) {
|
|
const { player, store } = useContext(PlayerContext);
|
|
|
|
const copySessionUrl = (withTs?: boolean) => {
|
|
if (withTs) {
|
|
const time = store.get().time;
|
|
const sessUrl = `${window.location.href}?jumpto=${time}`;
|
|
copy(sessUrl);
|
|
} else {
|
|
copy(window.location.href);
|
|
}
|
|
toast.success('Copied session url to clipboard');
|
|
};
|
|
const forthTenSeconds = () => {
|
|
player.jumpInterval(SKIP_INTERVALS[skipInterval]);
|
|
};
|
|
|
|
const backTenSeconds = () => {
|
|
player.jumpInterval(-SKIP_INTERVALS[skipInterval]);
|
|
};
|
|
|
|
useEffect(() => {
|
|
const handleShortcuts = (e: KeyboardEvent) => {
|
|
if (
|
|
e.target instanceof HTMLInputElement ||
|
|
e.target instanceof HTMLTextAreaElement
|
|
) {
|
|
return false;
|
|
} else {
|
|
if (e.shiftKey) {
|
|
e.preventDefault();
|
|
player.toggleInspectorMode(false);
|
|
switch (e.key) {
|
|
case 'F':
|
|
return fullScreenOn();
|
|
case 'X':
|
|
return disableDevtools
|
|
? null
|
|
: toggleBottomBlock(blocks.overview);
|
|
case 'P':
|
|
return disableDevtools
|
|
? null
|
|
: toggleBottomBlock(blocks.performance);
|
|
case 'N':
|
|
return disableDevtools ? null : toggleBottomBlock(blocks.network);
|
|
case 'C':
|
|
return disableDevtools ? null : toggleBottomBlock(blocks.console);
|
|
case 'R':
|
|
return disableDevtools ? null : toggleBottomBlock(blocks.storage);
|
|
case 'E':
|
|
return disableDevtools
|
|
? null
|
|
: toggleBottomBlock(blocks.stackEvents);
|
|
case '>':
|
|
return openNextSession();
|
|
case '<':
|
|
return openPrevSession();
|
|
case 'U':
|
|
return copySessionUrl(true);
|
|
case 'A':
|
|
player.pause();
|
|
return setActiveTab('EVENTS');
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
if (e.key === 'Esc' || e.key === 'Escape') {
|
|
fullScreenOff();
|
|
}
|
|
if (e.key === ' ') {
|
|
(document.activeElement as HTMLInputElement | null)?.blur?.();
|
|
player.togglePlay();
|
|
}
|
|
if (e.key === 'ArrowRight') {
|
|
forthTenSeconds();
|
|
}
|
|
if (e.key === 'ArrowLeft') {
|
|
backTenSeconds();
|
|
}
|
|
if (e.key === 'ArrowDown') {
|
|
player.speedDown();
|
|
}
|
|
if (e.key === 'ArrowUp') {
|
|
player.speedUp();
|
|
}
|
|
}
|
|
};
|
|
|
|
document.addEventListener('keydown', handleShortcuts);
|
|
return () => {
|
|
document.removeEventListener('keydown', handleShortcuts);
|
|
};
|
|
}, [forthTenSeconds, backTenSeconds, player, fullScreenOn, fullScreenOff]);
|
|
}
|
|
|
|
export default useShortcuts;
|