global tab fix, root tab routing
This commit is contained in:
parent
ce2218bc93
commit
4dff677809
@ -2,19 +2,9 @@ import { ReactNode } from "react";
|
|||||||
import { FormattedMessage } from "react-intl";
|
import { FormattedMessage } from "react-intl";
|
||||||
|
|
||||||
import Icon from "@/Components/Icons/Icon";
|
import Icon from "@/Components/Icons/Icon";
|
||||||
|
import { RootTabRoutePath } from "@/Pages/Root/RootTabRoutes";
|
||||||
import { Newest } from "@/Utils/Login";
|
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>>) {
|
export function rootTabItems(base: string, pubKey: string | undefined, tags: Newest<Array<string>>) {
|
||||||
const menuItems = [
|
const menuItems = [
|
||||||
{
|
{
|
||||||
@ -30,7 +20,7 @@ export function rootTabItems(base: string, pubKey: string | undefined, tags: New
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
tab: "following",
|
tab: "following",
|
||||||
path: `${base}/notes`,
|
path: `${base}/following`,
|
||||||
show: Boolean(pubKey),
|
show: Boolean(pubKey),
|
||||||
element: (
|
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`,
|
path: `${base}/trending/notes`,
|
||||||
show: true,
|
show: true,
|
||||||
element: (
|
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`,
|
path: `${base}/trending/hashtags`,
|
||||||
show: true,
|
show: true,
|
||||||
element: (
|
element: (
|
||||||
@ -117,7 +107,7 @@ export function rootTabItems(base: string, pubKey: string | undefined, tags: New
|
|||||||
),
|
),
|
||||||
},
|
},
|
||||||
] as Array<{
|
] as Array<{
|
||||||
tab: RootTab;
|
tab: RootTabRoutePath;
|
||||||
path: string;
|
path: string;
|
||||||
show: boolean;
|
show: boolean;
|
||||||
element: ReactNode;
|
element: ReactNode;
|
||||||
|
@ -4,9 +4,10 @@ import { Menu, MenuItem } from "@szhsin/react-menu";
|
|||||||
import { useEffect, useMemo, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import { useLocation, useNavigate } from "react-router-dom";
|
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 Icon from "@/Components/Icons/Icon";
|
||||||
import useLogin from "@/Hooks/useLogin";
|
import useLogin from "@/Hooks/useLogin";
|
||||||
|
import { RootTabRoutePath } from "@/Pages/Root/RootTabRoutes";
|
||||||
|
|
||||||
export function RootTabs({ base = "/" }: { base: string }) {
|
export function RootTabs({ base = "/" }: { base: string }) {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@ -23,11 +24,16 @@ export function RootTabs({ base = "/" }: { base: string }) {
|
|||||||
|
|
||||||
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`;
|
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 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(() => {
|
useEffect(() => {
|
||||||
const currentTab = menuItems.find(a => a.path === location.pathname)?.tab;
|
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 (
|
return (
|
||||||
|
@ -6,7 +6,7 @@ export const DefaultTab = () => {
|
|||||||
preferences: s.appData.item.preferences,
|
preferences: s.appData.item.preferences,
|
||||||
publicKey: s.publicKey,
|
publicKey: s.publicKey,
|
||||||
}));
|
}));
|
||||||
const tab = publicKey ? preferences.defaultRootTab ?? `for-you` : `trending/notes`;
|
const tab = publicKey ? preferences.defaultRootTab : `trending/notes`;
|
||||||
const elm = RootTabRoutes.find(a => a.path === tab)?.element;
|
const elm = RootTabRoutes.find(a => a.path === tab)?.element;
|
||||||
return elm;
|
return elm ?? RootTabRoutes.find(a => a.path === (CONFIG.features.forYouFeed ? "for-you" : "following"))?.element;
|
||||||
};
|
};
|
||||||
|
@ -83,10 +83,10 @@ export const GlobalTab = () => {
|
|||||||
() => ({
|
() => ({
|
||||||
type: "global",
|
type: "global",
|
||||||
items: [],
|
items: [],
|
||||||
relay: [relay.url],
|
relay: [relay?.url],
|
||||||
discriminator: `all-${sha256(relay.url)}`,
|
discriminator: `all-${sha256(relay?.url ?? "")}`,
|
||||||
}),
|
}),
|
||||||
[relay.url],
|
[relay?.url],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -12,7 +12,27 @@ import { NotesTab } from "@/Pages/Root/NotesTab";
|
|||||||
import { TagsTab } from "@/Pages/Root/TagsTab";
|
import { TagsTab } from "@/Pages/Root/TagsTab";
|
||||||
import { TopicsPage } from "@/Pages/TopicsPage";
|
import { TopicsPage } from "@/Pages/TopicsPage";
|
||||||
|
|
||||||
export const RootTabRoutes = [
|
export type RootTabRoutePath =
|
||||||
|
| ""
|
||||||
|
| "for-you"
|
||||||
|
| "global"
|
||||||
|
| "following"
|
||||||
|
| "followed-by-friends"
|
||||||
|
| "conversations"
|
||||||
|
| "discover"
|
||||||
|
| "tag/:tag"
|
||||||
|
| "trending/notes"
|
||||||
|
| "trending/hashtags"
|
||||||
|
| "suggested"
|
||||||
|
| "t/:tag"
|
||||||
|
| "topics";
|
||||||
|
|
||||||
|
export type RootTabRoute = {
|
||||||
|
path: RootTabRoutePath;
|
||||||
|
element: JSX.Element;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const RootTabRoutes: RootTabRoute[] = [
|
||||||
{
|
{
|
||||||
path: "",
|
path: "",
|
||||||
element: <DefaultTab />,
|
element: <DefaultTab />,
|
||||||
@ -26,7 +46,7 @@ export const RootTabRoutes = [
|
|||||||
element: <GlobalTab />,
|
element: <GlobalTab />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "notes",
|
path: "following",
|
||||||
element: <NotesTab />,
|
element: <NotesTab />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -89,7 +89,7 @@ const PreferencesPage = () => {
|
|||||||
<FormattedMessage defaultMessage="For you" id="xEjBS7" />
|
<FormattedMessage defaultMessage="For you" id="xEjBS7" />
|
||||||
</option>
|
</option>
|
||||||
)}
|
)}
|
||||||
<option value="notes">
|
<option value="following">
|
||||||
<FormattedMessage defaultMessage="Notes" id="7+Domh" />
|
<FormattedMessage defaultMessage="Notes" id="7+Domh" />
|
||||||
</option>
|
</option>
|
||||||
<option value="conversations">
|
<option value="conversations">
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { ImgProxySettings } from "@/Hooks/useImgProxy";
|
import { ImgProxySettings } from "@/Hooks/useImgProxy";
|
||||||
|
import { RootTabRoutePath } from "@/Pages/Root/RootTabRoutes";
|
||||||
import { DefaultImgProxy } from "@/Utils/Const";
|
import { DefaultImgProxy } from "@/Utils/Const";
|
||||||
|
|
||||||
export interface UserPreferences {
|
export interface UserPreferences {
|
||||||
@ -55,7 +56,7 @@ export interface UserPreferences {
|
|||||||
/**
|
/**
|
||||||
* Default page to select on load
|
* Default page to select on load
|
||||||
*/
|
*/
|
||||||
defaultRootTab: "for-you" | "notes" | "conversations" | "global";
|
defaultRootTab: RootTabRoutePath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default zap amount
|
* Default zap amount
|
||||||
@ -113,7 +114,7 @@ export const DefaultPreferences = {
|
|||||||
autoShowLatest: false,
|
autoShowLatest: false,
|
||||||
fileUploader: "void.cat",
|
fileUploader: "void.cat",
|
||||||
imgProxyConfig: DefaultImgProxy,
|
imgProxyConfig: DefaultImgProxy,
|
||||||
defaultRootTab: CONFIG.features.forYouFeed ? "for-you" : "notes",
|
defaultRootTab: CONFIG.features.forYouFeed ? "for-you" : "following",
|
||||||
defaultZapAmount: 50,
|
defaultZapAmount: 50,
|
||||||
autoZap: false,
|
autoZap: false,
|
||||||
telemetry: true,
|
telemetry: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user