spacedrive/interface/hooks/useKeybind.ts
Arnab Chakraborty 3bd1622e93
[MOB-23] Mobile Hardware Information for Overview Page (#2106)
* wip for iDevices

* Working HardwareModel Info for iOS

* wip

* Merge 'main' into 'mob-hw-info-overview'

* Half-Working `get_volume()`

* Objective c bridge to talk to FS

* Working objc bridge

The bridge works now, and we can now access the iOS file system using the native objective-c APIs instead for proper values, including on the simulator.

* Isolate `icrate` for `ios` deployments only

* Working Stats for Android

* Clean Up + `pnpm format`

* Fix to FSInfoResult Type

Due to the RNFS fork change, I had to change the types to make it so it doesn't fail building and CI.

* iOS Device Name Fix
2024-03-06 06:46:22 +00:00

36 lines
958 B
TypeScript

import { DependencyList } from 'react';
import { HotkeyCallback, Options, useHotkeys } from 'react-hotkeys-hook';
interface UseKeyBindOptions extends Options {
repeatable?: boolean;
}
type UseKeyBindOptionsOrDependencyArray = UseKeyBindOptions | DependencyList;
export const useKeybind = (
keys: string | string[] | string[][],
callback: HotkeyCallback,
options?: UseKeyBindOptionsOrDependencyArray,
dependencies?: UseKeyBindOptionsOrDependencyArray
) => {
const keyCombination = Array.isArray(keys)
? Array.isArray(keys[0])
? keys.map((k) => (k as string[]).join('+'))
: keys.join('+')
: keys;
const repeatable =
typeof options === 'object' && 'repeatable' in options
? options.repeatable
: typeof dependencies === 'object' && 'repeatable' in dependencies
? dependencies.repeatable
: false;
return useHotkeys(
keyCombination,
(e, k) => (repeatable || !e.repeat) && callback(e, k),
options,
dependencies
);
};