Rename folder "modules" to "features"
This commit is contained in:
13
src/features/hotkeys/Hotkeys.constants.ts
Normal file
13
src/features/hotkeys/Hotkeys.constants.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright (C) Contributors to the Suwayomi project
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
import { HotkeyScope } from '@/features/hotkeys/Hotkeys.types.ts';
|
||||
|
||||
export const HOTKEY_SCOPES = Object.fromEntries(
|
||||
Object.values(HotkeyScope).map((scope) => [scope, { scopes: scope }]),
|
||||
) as Record<HotkeyScope, { scopes: string }>;
|
||||
14
src/features/hotkeys/Hotkeys.types.ts
Normal file
14
src/features/hotkeys/Hotkeys.types.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright (C) Contributors to the Suwayomi project
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
export enum HotkeyScope {
|
||||
NONE = 'none',
|
||||
GLOBAL = 'global',
|
||||
MAIN_APP = 'main_app',
|
||||
READER = 'reader',
|
||||
}
|
||||
32
src/features/hotkeys/Hotkeys.utils.ts
Normal file
32
src/features/hotkeys/Hotkeys.utils.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) Contributors to the Suwayomi project
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { useHotkeysContext } from 'react-hotkeys-hook';
|
||||
import { HotkeyScope } from '@/features/hotkeys/Hotkeys.types.ts';
|
||||
|
||||
export const useDisableAllHotkeysWhileMounted = (shouldDisable?: boolean) => {
|
||||
const { activeScopes, enableScope, disableScope } = useHotkeysContext();
|
||||
const previouslyEnabledScopes = useRef<typeof activeScopes>([]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!shouldDisable) {
|
||||
return () => {};
|
||||
}
|
||||
|
||||
previouslyEnabledScopes.current = [...activeScopes];
|
||||
|
||||
enableScope(HotkeyScope.NONE);
|
||||
previouslyEnabledScopes.current.forEach(disableScope);
|
||||
|
||||
return () => {
|
||||
disableScope(HotkeyScope.NONE);
|
||||
previouslyEnabledScopes.current.forEach(enableScope);
|
||||
};
|
||||
}, [shouldDisable]);
|
||||
};
|
||||
15
src/features/hotkeys/contexts/AppHotkeysProvider.tsx
Normal file
15
src/features/hotkeys/contexts/AppHotkeysProvider.tsx
Normal file
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright (C) Contributors to the Suwayomi project
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
import { HotkeysProvider } from 'react-hotkeys-hook';
|
||||
import { ReactNode } from 'react';
|
||||
import { HotkeyScope } from '@/features/hotkeys/Hotkeys.types.ts';
|
||||
|
||||
export const AppHotkeysProvider = ({ children }: { children?: ReactNode }) => (
|
||||
<HotkeysProvider initiallyActiveScopes={[HotkeyScope.GLOBAL]}>{children}</HotkeysProvider>
|
||||
);
|
||||
Reference in New Issue
Block a user