Fix/scope hotkeys (#581)

* WIP

* asd

* Fix

* Fix lint

* Removed console log

* asd

* Removed isDefined

* Fix/debounce company card onchange (#580)

* Add internal state and debounce for editable text card

* Use debounce for date fields too

* Update refetch

* Nit

* Removed comments

* Ménage

---------

Co-authored-by: Emilien Chauvet <emilien.chauvet.enpc@gmail.com>
This commit is contained in:
Lucas Bordeau
2023-07-11 03:53:46 +02:00
committed by GitHub
parent 1c8aaff39d
commit 5f98b70c6a
71 changed files with 581 additions and 509 deletions

View File

@ -0,0 +1,7 @@
import { useHotkeysScopeAutoSync } from '@/hotkeys/hooks/internal/useHotkeysScopeAutoSync';
export function HotkeysScopeAutoSyncHook() {
useHotkeysScopeAutoSync();
return <></>;
}

View File

@ -0,0 +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 { useIsMatchingLocation } from './hooks/useIsMatchingLocation';
import { AppBasePath } from './types/AppBasePath';
import { AppPath } from './types/AppPath';
import { AuthPath } from './types/AuthPath';
import { SettingsPath } from './types/SettingsPath';
export function HotkeysScopeBrowserRouterSync() {
const isMatchingLocation = useIsMatchingLocation();
const setHotkeysScope = useSetHotkeysScope();
useEffect(() => {
switch (true) {
case isMatchingLocation(AppBasePath.Root, AppPath.CompaniesPage): {
setHotkeysScope(InternalHotkeysScope.Table, { goto: true });
break;
}
case isMatchingLocation(AppBasePath.Root, AppPath.PeoplePage): {
setHotkeysScope(InternalHotkeysScope.Table, { goto: true });
break;
}
case isMatchingLocation(AppBasePath.Root, AppPath.CompanyShowPage): {
setHotkeysScope(PageHotkeysScope.CompanyShowPage, { goto: true });
break;
}
case isMatchingLocation(AppBasePath.Root, AppPath.PersonShowPage): {
setHotkeysScope(PageHotkeysScope.PersonShowPage, { goto: true });
break;
}
case isMatchingLocation(AppBasePath.Root, AppPath.OpportunitiesPage): {
setHotkeysScope(PageHotkeysScope.OpportunitiesPage, { goto: true });
break;
}
case isMatchingLocation(AppBasePath.Auth, AuthPath.Index): {
setHotkeysScope(InternalHotkeysScope.AuthIndex);
break;
}
case isMatchingLocation(AppBasePath.Auth, AuthPath.CreateProfile): {
setHotkeysScope(InternalHotkeysScope.CreateProfile);
break;
}
case isMatchingLocation(AppBasePath.Auth, AuthPath.CreateWorkspace): {
setHotkeysScope(InternalHotkeysScope.CreateWokspace);
break;
}
case isMatchingLocation(AppBasePath.Auth, AuthPath.PasswordLogin): {
setHotkeysScope(InternalHotkeysScope.PasswordLogin);
break;
}
case isMatchingLocation(AppBasePath.Settings, SettingsPath.ProfilePage): {
setHotkeysScope(PageHotkeysScope.ProfilePage, { goto: true });
break;
}
case isMatchingLocation(
AppBasePath.Settings,
SettingsPath.WorkspaceMembersPage,
): {
setHotkeysScope(PageHotkeysScope.WorkspaceMemberPage, { goto: true });
break;
}
}
}, [isMatchingLocation, setHotkeysScope]);
return <></>;
}

View File

@ -1,7 +0,0 @@
import { useHotkeysScopeStackAutoSync } from '@/hotkeys/hooks/internal/useHotkeysScopeStackAutoSync';
export function HotkeysScopeStackAutoSyncHook() {
useHotkeysScopeStackAutoSync();
return <></>;
}

View File

@ -0,0 +1,16 @@
import { matchPath, useLocation } from 'react-router-dom';
import { parse } from 'url';
import { AppBasePath } from '../types/AppBasePath';
export function useIsMatchingLocation() {
const location = useLocation();
return function isMatchingLocation(basePath: AppBasePath, path: string) {
const constructedPath = basePath
? parse(`${basePath}/${path}`).pathname ?? ''
: path;
return !!matchPath(constructedPath, location.pathname);
};
}

View File

@ -0,0 +1,5 @@
export enum AppBasePath {
Auth = '/auth',
Settings = '/settings',
Root = '/',
}

View File

@ -0,0 +1,9 @@
export enum AppPath {
AuthCatchAll = `/auth/*`,
PeoplePage = '/people',
CompaniesPage = '/companies',
CompanyShowPage = '/companies/:companyId',
PersonShowPage = '/person/:personId',
OpportunitiesPage = '/opportunities',
SettingsCatchAll = `/settings/*`,
}

View File

@ -0,0 +1,7 @@
export enum AuthPath {
Index = '',
Callback = 'callback',
PasswordLogin = 'password-login',
CreateWorkspace = 'create/workspace',
CreateProfile = 'create/profile',
}

View File

@ -0,0 +1,5 @@
export enum SettingsPath {
ProfilePage = 'profile',
WorkspaceMembersPage = 'workspace-members',
Workspace = 'workspace',
}