import classNames from "classnames"; import { useCallback, useEffect, useMemo, useState } from "react"; import { useHistory } 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/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 history = useHistory(); const goTo = (href: string) => { if (href.startsWith("http")) window.open(href, "_blank"); else history.push(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 [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 (
{props.children}
{deviceName && bufferSeed ? ( {decryptData(deviceName, bufferSeed)} ) : ( Sync to cloud )} Settings About us HELP MEEE {deviceName ? ( Log out ) : null}
); }