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:
7
front/src/sync-hooks/HotkeysScopeAutoSyncHook.tsx
Normal file
7
front/src/sync-hooks/HotkeysScopeAutoSyncHook.tsx
Normal file
@ -0,0 +1,7 @@
|
||||
import { useHotkeysScopeAutoSync } from '@/hotkeys/hooks/internal/useHotkeysScopeAutoSync';
|
||||
|
||||
export function HotkeysScopeAutoSyncHook() {
|
||||
useHotkeysScopeAutoSync();
|
||||
|
||||
return <></>;
|
||||
}
|
||||
71
front/src/sync-hooks/HotkeysScopeBrowserRouterSync.tsx
Normal file
71
front/src/sync-hooks/HotkeysScopeBrowserRouterSync.tsx
Normal 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 <></>;
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
import { useHotkeysScopeStackAutoSync } from '@/hotkeys/hooks/internal/useHotkeysScopeStackAutoSync';
|
||||
|
||||
export function HotkeysScopeStackAutoSyncHook() {
|
||||
useHotkeysScopeStackAutoSync();
|
||||
|
||||
return <></>;
|
||||
}
|
||||
16
front/src/sync-hooks/hooks/useIsMatchingLocation.ts
Normal file
16
front/src/sync-hooks/hooks/useIsMatchingLocation.ts
Normal 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);
|
||||
};
|
||||
}
|
||||
5
front/src/sync-hooks/types/AppBasePath.ts
Normal file
5
front/src/sync-hooks/types/AppBasePath.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export enum AppBasePath {
|
||||
Auth = '/auth',
|
||||
Settings = '/settings',
|
||||
Root = '/',
|
||||
}
|
||||
9
front/src/sync-hooks/types/AppPath.ts
Normal file
9
front/src/sync-hooks/types/AppPath.ts
Normal file
@ -0,0 +1,9 @@
|
||||
export enum AppPath {
|
||||
AuthCatchAll = `/auth/*`,
|
||||
PeoplePage = '/people',
|
||||
CompaniesPage = '/companies',
|
||||
CompanyShowPage = '/companies/:companyId',
|
||||
PersonShowPage = '/person/:personId',
|
||||
OpportunitiesPage = '/opportunities',
|
||||
SettingsCatchAll = `/settings/*`,
|
||||
}
|
||||
7
front/src/sync-hooks/types/AuthPath.ts
Normal file
7
front/src/sync-hooks/types/AuthPath.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export enum AuthPath {
|
||||
Index = '',
|
||||
Callback = 'callback',
|
||||
PasswordLogin = 'password-login',
|
||||
CreateWorkspace = 'create/workspace',
|
||||
CreateProfile = 'create/profile',
|
||||
}
|
||||
5
front/src/sync-hooks/types/SettingsPath.ts
Normal file
5
front/src/sync-hooks/types/SettingsPath.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export enum SettingsPath {
|
||||
ProfilePage = 'profile',
|
||||
WorkspaceMembersPage = 'workspace-members',
|
||||
Workspace = 'workspace',
|
||||
}
|
||||
Reference in New Issue
Block a user