import "./Root.css"; import { useEffect, useState } from "react"; import { useSelector } from "react-redux"; import { Link } from "react-router-dom"; import { useIntl, FormattedMessage } from "react-intl"; import Tabs, { Tab } from "Element/Tabs"; import { RootState } from "State/Store"; import Timeline from "Element/Timeline"; import { System } from "@snort/nostr"; import { TimelineSubject } from "Feed/TimelineFeed"; import messages from "./messages"; import { debounce } from "Util"; export default function RootPage() { const { formatMessage } = useIntl(); const { loggedOut, publicKey: pubKey, follows, tags, relays } = useSelector((s: RootState) => s.login); const RootTab: Record = { Posts: { text: formatMessage(messages.Posts), value: 0, }, PostsAndReplies: { text: formatMessage(messages.Conversations), value: 1, }, Global: { text: formatMessage(messages.Global), value: 2, }, }; const [tab, setTab] = useState(RootTab.Posts); const [relay, setRelay] = useState(); const [globalRelays, setGlobalRelays] = useState([]); const tagTabs = tags.map((t, idx) => { return { text: `#${t}`, value: idx + 3 }; }); const tabs = [RootTab.Posts, RootTab.PostsAndReplies, RootTab.Global, ...tagTabs]; function followHints() { if (follows?.length === 0 && pubKey && tab !== RootTab.Global) { return ( ), }} /> ); } } useEffect(() => { return debounce(1_000, () => { const ret: string[] = []; System.Sockets.forEach((v, k) => { if (v.Info?.limitation?.payment_required === true) { ret.push(k); } }); if (ret.length > 0 && !relay) { setRelay(ret[0]); } setGlobalRelays(ret); }); }, [relays, relay]); const isGlobal = loggedOut || tab.value === RootTab.Global.value; const timelineSubect: TimelineSubject = (() => { if (isGlobal) { return { type: "global", items: [], discriminator: "all" }; } if (tab.value >= 3) { const hashtag = tab.text.slice(1); return { type: "hashtag", items: [hashtag], discriminator: hashtag }; } return { type: "pubkey", items: follows, discriminator: "follows" }; })(); return ( <>
{pubKey && } {isGlobal && globalRelays.length > 0 && (
 
)}
{followHints()} ); }