set initial tab name correctly
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
1e3a180150
commit
316b5578e8
@ -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]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const defaultTab = pubKey ? preferences.defaultRootTab ?? `${base}/notes` : `${base}/trending/notes`;
|
const defaultTab = pubKey ? preferences.defaultRootTab ?? `${base}/notes` : `${base}/trending/notes`;
|
||||||
const pathname = location.pathname === "/" ? defaultTab : location.pathname;
|
const initialPathname = location.pathname === "/" ? defaultTab : location.pathname;
|
||||||
const currentTab = menuItems.find(a => a.path === pathname)?.tab;
|
const initialRootType = menuItems.find(a => a.path === initialPathname)?.tab || "following";
|
||||||
if (currentTab) {
|
|
||||||
|
const [rootType, setRootType] = useState<RootTab>(initialRootType);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const currentTab = menuItems.find(a => a.path === location.pathname)?.tab;
|
||||||
|
if (currentTab && currentTab !== rootType) {
|
||||||
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/`)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user