Skip to content

Commit

Permalink
fix(home-page): new regex function (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas-Krahn authored Dec 4, 2024
2 parents dedb85f + 5af71b9 commit f5b5090
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
7 changes: 1 addition & 6 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions example/src/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function Layout() {

const views = [
new BasicContentWrapper(
"/example1/",
"/",
simpleNavbarTabFactory({
disabled: false,
name: "Example without Translation",
Expand Down Expand Up @@ -226,7 +226,7 @@ function Layout() {
return (
<UILayer
tabAndContentWrappers={views}
startingPoint="/example1/"
startingPoint="/"
authenticationView={BasicAuthenticationView}
settingsMenuOptions={settingsMenuOptions}
documentsLabelKey="Legal_documents"
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
],
"scripts": {
"devmode": "./scripts/windows/devmode_build.bat",
"devmode:windows": ".\\scripts\\windows\\devmode_build.bat",
"build": "tsc --build --clean && tsc --build && npx babel ./src --out-dir ./build --extensions .ts,.tsx --copy-files",
"test": "jest --passWithNoTests",
"run-example": "./scripts/windows/setup_and_run_example.bat",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,12 @@ export const SimpleNavbarTab: GroupableNavbarTab = (
const colorSettingsContext = useContext(ColorSettingsContext);
const t = useTranslator();

// Use useMemo to improve performance.
const regex = useMemo(() => {
let regexString = path;
// Escape all slashes
// Escape slashes
regexString = regexString.replaceAll("/", "\\/");
// Add ^ to match the beginning of the path. Add * for allowing other characters.
regexString = `^${regexString}.*`;
// Add start (^) and boundary condition with trailing /.*
regexString = `^${regexString}(\\/.*)?$`;
return new RegExp(regexString);
}, [path]);

Expand Down

0 comments on commit f5b5090

Please sign in to comment.