Skip to content

The open alternative to Salesforce, designed for AI.

Set the page hotkey scope only once (#11626)

Baptiste Devessier1ba0c240719a
diff --git a/packages/twenty-front/src/hooks/useIsMatchingLocation.ts b/packages/twenty-front/src/hooks/useIsMatchingLocation.ts
index 456efaf1a3c..70c175e3ee8 100644
--- a/packages/twenty-front/src/hooks/useIsMatchingLocation.ts
+++ b/packages/twenty-front/src/hooks/useIsMatchingLocation.ts
@@ -2,27 +2,31 @@ import { matchPath, useLocation } from 'react-router-dom';
import { AppBasePath } from '@/types/AppBasePath';
import { isNonEmptyString } from '@sniptt/guards';
+import { useCallback } from 'react';
import { isDefined } from 'twenty-shared/utils';
-export const useIsMatchingLocation = () => {
- const location = useLocation();
+const addTrailingSlash = (path: string) =>
+ path.endsWith('/') ? path : path + '/';
- const addTrailingSlash = (path: string) =>
- path.endsWith('/') ? path : path + '/';
+const getConstructedPath = (path: string, basePath?: AppBasePath) => {
+ if (!isNonEmptyString(basePath)) return path;
- const getConstructedPath = (path: string, basePath?: AppBasePath) => {
- if (!isNonEmptyString(basePath)) return path;
+ return addTrailingSlash(basePath) + path;
+};
- return addTrailingSlash(basePath) + path;
- };
+export const useIsMatchingLocation = () => {
+ const location = useLocation();
- const isMatchingLocation = (path: string, basePath?: AppBasePath) => {
- const match = matchPath(
- getConstructedPath(path, basePath),
- location.pathname,
- );
- return isDefined(match);
- };
+ const isMatchingLocation = useCallback(
+ (path: string, basePath?: AppBasePath) => {
+ const match = matchPath(
+ getConstructedPath(path, basePath),
+ location.pathname,
+ );
+ return isDefined(match);
+ },
+ [location.pathname],
+ );
return {
isMatchingLocation,