set initial tab name correctly
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Martti Malmi 2023-12-07 10:20:11 +02:00
parent 1e3a180150
commit 316b5578e8

View File

@ -128,18 +128,21 @@ export function RootTabs({ base = "/" }) {
tags: s.tags, tags: s.tags,
preferences: s.appData.item.preferences, preferences: s.appData.item.preferences,
})); }));
const [rootType, setRootType] = useState<RootTab>("following");
const menuItems = useMemo(() => rootTabItems(base, pubKey, tags), [base, pubKey, tags]); 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<RootTab>(initialRootType);
useEffect(() => { useEffect(() => {
const defaultTab = pubKey ? preferences.defaultRootTab ?? `${base}/notes` : `${base}/trending/notes`; const currentTab = menuItems.find(a => a.path === location.pathname)?.tab;
const pathname = location.pathname === "/" ? defaultTab : location.pathname; if (currentTab && currentTab !== rootType) {
const currentTab = menuItems.find(a => a.path === pathname)?.tab;
if (currentTab) {
setRootType(currentTab); setRootType(currentTab);
} }
}, [location, menuItems]); }, [location, menuItems, rootType]);
function currentMenuItem() { function currentMenuItem() {
if (location.pathname.startsWith(`${base}/t/`)) { if (location.pathname.startsWith(`${base}/t/`)) {