import classNames from "classnames"; import { useCallback, useEffect, useMemo, useState } from "react"; import { useTranslation } from "react-i18next"; import { useNavigate } from "react-router-dom"; import { base64ToBuffer, decryptData } from "@/backend/accounts/crypto"; import { UserAvatar } from "@/components/Avatar"; import { Icon, Icons } from "@/components/Icon"; import { Transition } from "@/components/utils/Transition"; import { useAuth } from "@/hooks/auth/useAuth"; import { conf } from "@/setup/config"; import { useAuthStore } from "@/stores/auth"; function Divider() { return
; } function GoToLink(props: { children: React.ReactNode; href?: string; className?: string; onClick?: () => void; }) { const navigate = useNavigate(); const goTo = (href: string) => { if (href.startsWith("http")) window.open(href, "_blank"); else navigate(href); }; return ( { evt.preventDefault(); if (props.href) goTo(props.href); else props.onClick?.(); }} className={props.className} > {props.children} ); } function DropdownLink(props: { children: React.ReactNode; href?: string; icon?: Icons; highlight?: boolean; className?: string; onClick?: () => void; }) { return ( {props.icon ? : null} {props.children} ); } function CircleDropdownLink(props: { icon: Icons; href: string }) { return ( ); } export function LinksDropdown(props: { children: React.ReactNode }) { const { t } = useTranslation(); const [open, setOpen] = useState(false); const deviceName = useAuthStore((s) => s.account?.deviceName); const seed = useAuthStore((s) => s.account?.seed); const bufferSeed = useMemo( () => (seed ? base64ToBuffer(seed) : null), [seed], ); const { logout } = useAuth(); useEffect(() => { function onWindowClick(evt: MouseEvent) { if ((evt.target as HTMLElement).closest(".is-dropdown")) return; setOpen(false); } window.addEventListener("click", onWindowClick); return () => window.removeEventListener("click", onWindowClick); }, []); const toggleOpen = useCallback(() => { setOpen((s) => !s); }, []); return (
evt.key === "Enter" && toggleOpen()} > {props.children}
{deviceName && bufferSeed ? ( {decryptData(deviceName, bufferSeed)} ) : ( {t("navigation.menu.register")} )} {t("navigation.menu.settings")} {t("navigation.menu.about")} {t("navigation.menu.donation")} {deviceName ? ( {t("navigation.menu.logout")} ) : null}
); }