global tab fix, root tab routing
This commit is contained in:
@ -2,19 +2,9 @@ import { ReactNode } from "react";
|
||||
import { FormattedMessage } from "react-intl";
|
||||
|
||||
import Icon from "@/Components/Icons/Icon";
|
||||
import { RootTabRoutePath } from "@/Pages/Root/RootTabRoutes";
|
||||
import { Newest } from "@/Utils/Login";
|
||||
|
||||
export type RootTab =
|
||||
| "for-you"
|
||||
| "following"
|
||||
| "followed-by-friends"
|
||||
| "conversations"
|
||||
| "trending-notes"
|
||||
| "trending-people"
|
||||
| "suggested"
|
||||
| "tags"
|
||||
| "global";
|
||||
|
||||
export function rootTabItems(base: string, pubKey: string | undefined, tags: Newest<Array<string>>) {
|
||||
const menuItems = [
|
||||
{
|
||||
@ -30,7 +20,7 @@ export function rootTabItems(base: string, pubKey: string | undefined, tags: New
|
||||
},
|
||||
{
|
||||
tab: "following",
|
||||
path: `${base}/notes`,
|
||||
path: `${base}/following`,
|
||||
show: Boolean(pubKey),
|
||||
element: (
|
||||
<>
|
||||
@ -40,7 +30,7 @@ export function rootTabItems(base: string, pubKey: string | undefined, tags: New
|
||||
),
|
||||
},
|
||||
{
|
||||
tab: "trending-notes",
|
||||
tab: "trending/notes",
|
||||
path: `${base}/trending/notes`,
|
||||
show: true,
|
||||
element: (
|
||||
@ -84,7 +74,7 @@ export function rootTabItems(base: string, pubKey: string | undefined, tags: New
|
||||
),
|
||||
},
|
||||
{
|
||||
tab: "trending-hashtags",
|
||||
tab: "trending/hashtags",
|
||||
path: `${base}/trending/hashtags`,
|
||||
show: true,
|
||||
element: (
|
||||
@ -117,7 +107,7 @@ export function rootTabItems(base: string, pubKey: string | undefined, tags: New
|
||||
),
|
||||
},
|
||||
] as Array<{
|
||||
tab: RootTab;
|
||||
tab: RootTabRoutePath;
|
||||
path: string;
|
||||
show: boolean;
|
||||
element: ReactNode;
|
||||
|
@ -4,9 +4,10 @@ import { Menu, MenuItem } from "@szhsin/react-menu";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useLocation, useNavigate } from "react-router-dom";
|
||||
|
||||
import { RootTab, rootTabItems } from "@/Components/Feed/RootTabItems";
|
||||
import { rootTabItems } from "@/Components/Feed/RootTabItems";
|
||||
import Icon from "@/Components/Icons/Icon";
|
||||
import useLogin from "@/Hooks/useLogin";
|
||||
import { RootTabRoutePath } from "@/Pages/Root/RootTabRoutes";
|
||||
|
||||
export function RootTabs({ base = "/" }: { base: string }) {
|
||||
const navigate = useNavigate();
|
||||
@ -23,11 +24,16 @@ export function RootTabs({ base = "/" }: { base: string }) {
|
||||
|
||||
const menuItems = useMemo(() => rootTabItems(base, pubKey, tags), [base, pubKey, tags]);
|
||||
|
||||
const defaultTab = pubKey ? preferences.defaultRootTab ?? `${base}/notes` : `${base}/trending/notes`;
|
||||
let defaultTab: RootTabRoutePath;
|
||||
if (pubKey) {
|
||||
defaultTab = preferences.defaultRootTab ?? (CONFIG.features.forYouFeed ? "for-you" : "following");
|
||||
} else {
|
||||
defaultTab = `trending/notes`;
|
||||
}
|
||||
const initialPathname = location.pathname === "/" ? defaultTab : location.pathname;
|
||||
const initialRootType = menuItems.find(a => a.path === initialPathname)?.tab || "for-you";
|
||||
const initialRootType = menuItems.find(a => a.path === initialPathname)?.tab || defaultTab;
|
||||
|
||||
const [rootType, setRootType] = useState<RootTab>(initialRootType);
|
||||
const [rootType, setRootType] = useState<RootTabRoutePath>(initialRootType);
|
||||
|
||||
useEffect(() => {
|
||||
const currentTab = menuItems.find(a => a.path === location.pathname)?.tab;
|
||||
@ -45,7 +51,7 @@ export function RootTabs({ base = "/" }: { base: string }) {
|
||||
</>
|
||||
);
|
||||
}
|
||||
return menuItems.find(a => a.tab === rootType)?.element;
|
||||
return menuItems.find(a => a.tab === rootType)?.element ?? menuItems[0].element;
|
||||
}
|
||||
|
||||
return (
|
||||
|
Reference in New Issue
Block a user