From 01a2495e47d56b07e21742e79378e8325fb04e88 Mon Sep 17 00:00:00 2001
From: shamoon <4887959+shamoon@users.noreply.github.com>
Date: Sat, 23 Mar 2024 23:22:27 -0700
Subject: [PATCH] Fix: correctly handle direct tab navigation with encoded
chars (#3172)
---
src/components/tab.jsx | 20 ++++++++++++--------
src/pages/index.jsx | 8 ++++----
2 files changed, 16 insertions(+), 12 deletions(-)
diff --git a/src/components/tab.jsx b/src/components/tab.jsx
index 699b1912..e0c2f46e 100644
--- a/src/components/tab.jsx
+++ b/src/components/tab.jsx
@@ -3,13 +3,19 @@ import classNames from "classnames";
import { TabContext } from "utils/contexts/tab";
-export function slugify(tabName) {
- return tabName !== undefined ? encodeURIComponent(tabName.toString().replace(/\s+/g, "-").toLowerCase()) : "";
+function slugify(tabName) {
+ return tabName.toString().replace(/\s+/g, "-").toLowerCase();
+}
+
+export function slugifyAndEncode(tabName) {
+ return tabName !== undefined ? encodeURIComponent(slugify(tabName)) : "";
}
export default function Tab({ tab }) {
const { activeTab, setActiveTab } = useContext(TabContext);
+ const matchesTab = decodeURI(activeTab) === slugify(tab);
+
return (
{
- setActiveTab(slugify(tab));
- window.location.hash = `#${slugify(tab)}`;
+ setActiveTab(slugifyAndEncode(tab));
+ window.location.hash = `#${slugifyAndEncode(tab)}`;
}}
>
{tab}
diff --git a/src/pages/index.jsx b/src/pages/index.jsx
index 10b2f6d5..5e1bd6e2 100644
--- a/src/pages/index.jsx
+++ b/src/pages/index.jsx
@@ -10,7 +10,7 @@ import { BiError } from "react-icons/bi";
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import { useRouter } from "next/router";
-import Tab, { slugify } from "components/tab";
+import Tab, { slugifyAndEncode } from "components/tab";
import ServicesGroup from "components/services/group";
import BookmarksGroup from "components/bookmarks/group";
import Widget from "components/widgets/widget";
@@ -258,13 +258,13 @@ function Home({ initialSettings }) {
useEffect(() => {
if (!activeTab) {
- const initialTab = decodeURI(asPath.substring(asPath.indexOf("#") + 1));
- setActiveTab(initialTab === "/" ? slugify(tabs["0"]) : initialTab);
+ const initialTab = asPath.substring(asPath.indexOf("#") + 1);
+ setActiveTab(initialTab === "/" ? slugifyAndEncode(tabs["0"]) : initialTab);
}
});
const servicesAndBookmarksGroups = useMemo(() => {
- const tabGroupFilter = (g) => g && [activeTab, ""].includes(slugify(settings.layout?.[g.name]?.tab));
+ const tabGroupFilter = (g) => g && [activeTab, ""].includes(slugifyAndEncode(settings.layout?.[g.name]?.tab));
const undefinedGroupFilter = (g) => settings.layout?.[g.name] === undefined;
const layoutGroups = Object.keys(settings.layout ?? {})