import classNames from "classnames"; import { useCallback, useEffect, useState } from "react"; import { useHistory } from "react-router-dom"; 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 userId = useAuthStore((s) => s.account?.userId); 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}
{userId ? ( {userId} ) : ( Sync to cloud )} Settings About us HELP MEEE {userId ? ( Log out ) : null}
); }