From 316b5578e83088071b8f9a7eac48aa21b3318b22 Mon Sep 17 00:00:00 2001 From: Martti Malmi Date: Thu, 7 Dec 2023 10:20:11 +0200 Subject: [PATCH] set initial tab name correctly --- packages/app/src/Element/Feed/RootTabs.tsx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/app/src/Element/Feed/RootTabs.tsx b/packages/app/src/Element/Feed/RootTabs.tsx index d10fcc11..4a4f7bd3 100644 --- a/packages/app/src/Element/Feed/RootTabs.tsx +++ b/packages/app/src/Element/Feed/RootTabs.tsx @@ -128,18 +128,21 @@ export function RootTabs({ base = "/" }) { tags: s.tags, preferences: s.appData.item.preferences, })); - const [rootType, setRootType] = useState("following"); const menuItems = useMemo(() => rootTabItems(base, pubKey, tags), [base, pubKey, tags]); + const defaultTab = pubKey ? preferences.defaultRootTab ?? `${base}/notes` : `${base}/trending/notes`; + const initialPathname = location.pathname === "/" ? defaultTab : location.pathname; + const initialRootType = menuItems.find(a => a.path === initialPathname)?.tab || "following"; + + const [rootType, setRootType] = useState(initialRootType); + useEffect(() => { - const defaultTab = pubKey ? preferences.defaultRootTab ?? `${base}/notes` : `${base}/trending/notes`; - const pathname = location.pathname === "/" ? defaultTab : location.pathname; - const currentTab = menuItems.find(a => a.path === pathname)?.tab; - if (currentTab) { + const currentTab = menuItems.find(a => a.path === location.pathname)?.tab; + if (currentTab && currentTab !== rootType) { setRootType(currentTab); } - }, [location, menuItems]); + }, [location, menuItems, rootType]); function currentMenuItem() { if (location.pathname.startsWith(`${base}/t/`)) {