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:
Charles Bochet
2023-07-14 12:27:26 -07:00
committed by GitHub
parent 7bcea343e2
commit e93a96b3b1
71 changed files with 398 additions and 386 deletions

View File

@ -0,0 +1,71 @@
import { useEffect } from 'react';
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 HotkeyScopeBrowserRouterSync() {
const isMatchingLocation = useIsMatchingLocation();
const setHotkeyScope = useSetHotkeyScope();
useEffect(() => {
switch (true) {
case isMatchingLocation(AppBasePath.Root, AppPath.CompaniesPage): {
setHotkeyScope(TableHotkeyScope.Table, { goto: true });
break;
}
case isMatchingLocation(AppBasePath.Root, AppPath.PeoplePage): {
setHotkeyScope(TableHotkeyScope.Table, { goto: true });
break;
}
case isMatchingLocation(AppBasePath.Root, AppPath.CompanyShowPage): {
setHotkeyScope(PageHotkeyScope.CompanyShowPage, { goto: true });
break;
}
case isMatchingLocation(AppBasePath.Root, AppPath.PersonShowPage): {
setHotkeyScope(PageHotkeyScope.PersonShowPage, { goto: true });
break;
}
case isMatchingLocation(AppBasePath.Root, AppPath.OpportunitiesPage): {
setHotkeyScope(PageHotkeyScope.OpportunitiesPage, { goto: true });
break;
}
case isMatchingLocation(AppBasePath.Auth, AuthPath.Index): {
setHotkeyScope(PageHotkeyScope.AuthIndex);
break;
}
case isMatchingLocation(AppBasePath.Auth, AuthPath.CreateProfile): {
setHotkeyScope(PageHotkeyScope.CreateProfile);
break;
}
case isMatchingLocation(AppBasePath.Auth, AuthPath.CreateWorkspace): {
setHotkeyScope(PageHotkeyScope.CreateWokspace);
break;
}
case isMatchingLocation(AppBasePath.Auth, AuthPath.PasswordLogin): {
setHotkeyScope(PageHotkeyScope.PasswordLogin);
break;
}
case isMatchingLocation(AppBasePath.Settings, SettingsPath.ProfilePage): {
setHotkeyScope(PageHotkeyScope.ProfilePage, { goto: true });
break;
}
case isMatchingLocation(
AppBasePath.Settings,
SettingsPath.WorkspaceMembersPage,
): {
setHotkeyScope(PageHotkeyScope.WorkspaceMemberPage, { goto: true });
break;
}
}
}, [isMatchingLocation, setHotkeyScope]);
return <></>;
}