Refactor hotkyes in its own lib folder (#660)
* Refactor hotkyes in its own lib folder * Lint * Fix PR comments * rename hotkeysScope into hotkeyScope
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { useGoToHotkeys } from '@/hotkeys/hooks/useGoToHotkeys';
|
||||
import { useGoToHotkeys } from '@/lib/hotkeys/hooks/useGoToHotkeys';
|
||||
|
||||
export function GotoHotkeysHooks() {
|
||||
useGoToHotkeys('p', '/people');
|
||||
|
||||
7
front/src/sync-hooks/HotkeyScopeAutoSyncHook.tsx
Normal file
7
front/src/sync-hooks/HotkeyScopeAutoSyncHook.tsx
Normal file
@ -0,0 +1,7 @@
|
||||
import { useHotkeyScopeAutoSync } from '@/lib/hotkeys/hooks/internal/useHotkeyScopeAutoSync';
|
||||
|
||||
export function HotkeyScopeAutoSyncHook() {
|
||||
useHotkeyScopeAutoSync();
|
||||
|
||||
return <></>;
|
||||
}
|
||||
@ -1,71 +1,71 @@
|
||||
import { useEffect } from 'react';
|
||||
|
||||
import { useSetHotkeysScope } from '@/hotkeys/hooks/useSetHotkeysScope';
|
||||
import { InternalHotkeysScope } from '@/hotkeys/types/internal/InternalHotkeysScope';
|
||||
import { PageHotkeysScope } from '@/hotkeys/types/internal/PageHotkeysScope';
|
||||
import { useSetHotkeyScope } from '@/lib/hotkeys/hooks/useSetHotkeyScope';
|
||||
import { TableHotkeyScope } from '@/ui/tables/types/TableHotkeyScope';
|
||||
|
||||
import { useIsMatchingLocation } from './hooks/useIsMatchingLocation';
|
||||
import { AppBasePath } from './types/AppBasePath';
|
||||
import { AppPath } from './types/AppPath';
|
||||
import { AuthPath } from './types/AuthPath';
|
||||
import { PageHotkeyScope } from './types/PageHotkeyScope';
|
||||
import { SettingsPath } from './types/SettingsPath';
|
||||
|
||||
export function HotkeysScopeBrowserRouterSync() {
|
||||
export function HotkeyScopeBrowserRouterSync() {
|
||||
const isMatchingLocation = useIsMatchingLocation();
|
||||
|
||||
const setHotkeysScope = useSetHotkeysScope();
|
||||
const setHotkeyScope = useSetHotkeyScope();
|
||||
|
||||
useEffect(() => {
|
||||
switch (true) {
|
||||
case isMatchingLocation(AppBasePath.Root, AppPath.CompaniesPage): {
|
||||
setHotkeysScope(InternalHotkeysScope.Table, { goto: true });
|
||||
setHotkeyScope(TableHotkeyScope.Table, { goto: true });
|
||||
break;
|
||||
}
|
||||
case isMatchingLocation(AppBasePath.Root, AppPath.PeoplePage): {
|
||||
setHotkeysScope(InternalHotkeysScope.Table, { goto: true });
|
||||
setHotkeyScope(TableHotkeyScope.Table, { goto: true });
|
||||
break;
|
||||
}
|
||||
case isMatchingLocation(AppBasePath.Root, AppPath.CompanyShowPage): {
|
||||
setHotkeysScope(PageHotkeysScope.CompanyShowPage, { goto: true });
|
||||
setHotkeyScope(PageHotkeyScope.CompanyShowPage, { goto: true });
|
||||
break;
|
||||
}
|
||||
case isMatchingLocation(AppBasePath.Root, AppPath.PersonShowPage): {
|
||||
setHotkeysScope(PageHotkeysScope.PersonShowPage, { goto: true });
|
||||
setHotkeyScope(PageHotkeyScope.PersonShowPage, { goto: true });
|
||||
break;
|
||||
}
|
||||
case isMatchingLocation(AppBasePath.Root, AppPath.OpportunitiesPage): {
|
||||
setHotkeysScope(PageHotkeysScope.OpportunitiesPage, { goto: true });
|
||||
setHotkeyScope(PageHotkeyScope.OpportunitiesPage, { goto: true });
|
||||
break;
|
||||
}
|
||||
case isMatchingLocation(AppBasePath.Auth, AuthPath.Index): {
|
||||
setHotkeysScope(InternalHotkeysScope.AuthIndex);
|
||||
setHotkeyScope(PageHotkeyScope.AuthIndex);
|
||||
break;
|
||||
}
|
||||
case isMatchingLocation(AppBasePath.Auth, AuthPath.CreateProfile): {
|
||||
setHotkeysScope(InternalHotkeysScope.CreateProfile);
|
||||
setHotkeyScope(PageHotkeyScope.CreateProfile);
|
||||
break;
|
||||
}
|
||||
case isMatchingLocation(AppBasePath.Auth, AuthPath.CreateWorkspace): {
|
||||
setHotkeysScope(InternalHotkeysScope.CreateWokspace);
|
||||
setHotkeyScope(PageHotkeyScope.CreateWokspace);
|
||||
break;
|
||||
}
|
||||
case isMatchingLocation(AppBasePath.Auth, AuthPath.PasswordLogin): {
|
||||
setHotkeysScope(InternalHotkeysScope.PasswordLogin);
|
||||
setHotkeyScope(PageHotkeyScope.PasswordLogin);
|
||||
break;
|
||||
}
|
||||
case isMatchingLocation(AppBasePath.Settings, SettingsPath.ProfilePage): {
|
||||
setHotkeysScope(PageHotkeysScope.ProfilePage, { goto: true });
|
||||
setHotkeyScope(PageHotkeyScope.ProfilePage, { goto: true });
|
||||
break;
|
||||
}
|
||||
case isMatchingLocation(
|
||||
AppBasePath.Settings,
|
||||
SettingsPath.WorkspaceMembersPage,
|
||||
): {
|
||||
setHotkeysScope(PageHotkeysScope.WorkspaceMemberPage, { goto: true });
|
||||
setHotkeyScope(PageHotkeyScope.WorkspaceMemberPage, { goto: true });
|
||||
break;
|
||||
}
|
||||
}
|
||||
}, [isMatchingLocation, setHotkeysScope]);
|
||||
}, [isMatchingLocation, setHotkeyScope]);
|
||||
|
||||
return <></>;
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
import { useHotkeysScopeAutoSync } from '@/hotkeys/hooks/internal/useHotkeysScopeAutoSync';
|
||||
|
||||
export function HotkeysScopeAutoSyncHook() {
|
||||
useHotkeysScopeAutoSync();
|
||||
|
||||
return <></>;
|
||||
}
|
||||
15
front/src/sync-hooks/types/PageHotkeyScope.ts
Normal file
15
front/src/sync-hooks/types/PageHotkeyScope.ts
Normal file
@ -0,0 +1,15 @@
|
||||
export enum PageHotkeyScope {
|
||||
Settings = 'settings',
|
||||
CreateWokspace = 'create-workspace',
|
||||
PasswordLogin = 'password-login',
|
||||
AuthIndex = 'auth-index',
|
||||
CreateProfile = 'create-profile',
|
||||
ShowPage = 'show-page',
|
||||
PersonShowPage = 'person-show-page',
|
||||
CompanyShowPage = 'company-show-page',
|
||||
CompaniesPage = 'companies-page',
|
||||
PeoplePage = 'people-page',
|
||||
OpportunitiesPage = 'opportunities-page',
|
||||
ProfilePage = 'profile-page',
|
||||
WorkspaceMemberPage = 'workspace-member-page',
|
||||
}
|
||||
Reference in New Issue
Block a user