import { useLocation, useNavigate } from "react-router-dom"; import React, { useCallback, useEffect, useMemo, useState } from "react"; import classNames from "classnames"; import { LogoHeader } from "@/Pages/Layout/LogoHeader"; import { rootTabItems, RootTabs } from "@/Element/Feed/RootTabs"; import NotificationsHeader from "@/Pages/Layout/NotificationsHeader"; import { NostrLink, NostrPrefix, parseNostrLink } from "@snort/system"; import { bech32ToHex } from "@/SnortUtils"; import { useEventFeed } from "@snort/system-react"; import { FormattedMessage } from "react-intl"; import DisplayName from "@/Element/User/DisplayName"; import useLogin from "@/Hooks/useLogin"; import Icon from "@/Icons/Icon"; export function Header() { const navigate = useNavigate(); const location = useLocation(); const pageName = location.pathname.split("/")[1]; const [nostrLink, setNostrLink] = useState(); const { publicKey, tags } = useLogin(); const isRootTab = useMemo(() => { return location.pathname === "/" || rootTabItems("", publicKey, tags).some(item => item.path === location.pathname); }, [location.pathname, publicKey, tags]); const scrollUp = useCallback(() => { window.scrollTo({ top: 0, behavior: "instant" }); }, []); useEffect(() => { try { setNostrLink(parseNostrLink(pageName)); } catch (e) { setNostrLink(undefined); } }, [pageName]); const handleBackButtonClick = () => { const idx = window.history.state?.idx; if (idx === undefined || idx > 0) { navigate(-1); } else { navigate("/"); } }; const showBackButton = location.pathname !== "/" && !isRootTab; let title: React.ReactNode = {pageName}; if (location.pathname.startsWith("/search/")) { const searchTerm = location.pathname.split("/search/")[1]; title = ( <> : {searchTerm} ); } else if (nostrLink) { if (nostrLink.type === NostrPrefix.Event || nostrLink.type === NostrPrefix.Note) { title = ; } else if (nostrLink.type === NostrPrefix.PublicKey || nostrLink.type === NostrPrefix.Profile) { try { title = ; } catch (e) { console.error(e); } } } else if (location.pathname.startsWith("/t/")) { title = #{location.pathname.split("/").slice(-1)}; } return (
{!showBackButton && (
)} {isRootTab && } {!isRootTab && (
{title}
)}
); } function NoteTitle({ link }: { link: NostrLink }) { const ev = useEventFeed(link); if (!ev.data?.pubkey) { return ; } return ( <> }} /> ); }