Continuous Integration / build_web (push) Failing after 0s
Continuous Integration / build (macos-latest) (push) Skipped
Continuous Integration / build (ubuntu-22.04) (push) Skipped
Continuous Integration / build (windows-11-arm) (push) Skipped
Continuous Integration / build (windows-latest) (push) Skipped
Continuous Integration / nightly_release (push) Skipped
185 lines
4.9 KiB
TypeScript
185 lines
4.9 KiB
TypeScript
import { IconButton, Tooltip, useScrollTrigger } from "@mui/material";
|
|
import { Link, useLocation, useNavigate } from "@tanstack/react-router";
|
|
import React, { useEffect, useLayoutEffect, useRef } from "react";
|
|
import { useShallow } from "zustand/shallow";
|
|
import { AppStatusIndicator } from "@/components/appStatus";
|
|
import BackButton from "@/components/buttons/backButton";
|
|
import CastButton from "@/components/buttons/castButton";
|
|
import { UserAvatarMenu } from "@/components/userAvatarMenu";
|
|
import WindowControls from "@/components/windowControls";
|
|
import {
|
|
getLocalMediaTransfer,
|
|
useCurrentMediaItem,
|
|
} from "@/utils/methods/localTransfer";
|
|
import useSearchStore from "@/utils/store/search";
|
|
import { shouldShowTitlebar } from "./routeVisibility";
|
|
import { type AppNavItem, useAppNavigation } from "./useAppNavigation";
|
|
|
|
import "./appTitlebar.scss";
|
|
|
|
const BlinkMark = () => (
|
|
<svg
|
|
className="app-titlebar-brand-mark"
|
|
viewBox="0 0 40 32"
|
|
fill="none"
|
|
aria-hidden="true"
|
|
>
|
|
<g
|
|
stroke="currentColor"
|
|
strokeWidth="2.2"
|
|
strokeLinecap="round"
|
|
strokeLinejoin="round"
|
|
>
|
|
<path d="M8.5 7.6 4.7 4.2" />
|
|
<path d="M14.2 5.4 13.4 1.4" />
|
|
<path d="M20.4 5.2 21.1 1.3" />
|
|
<path d="M5.2 18.4c3.7-5.9 10.5-8.3 16.6-5.7 4.2 1.8 7.6 5 9.8 8.2-4.8 4.7-12.4 6.1-18.2 3.5-3.7-1.7-6.4-3.7-8.2-6Z" />
|
|
<path
|
|
d="M18.7 18.5a2.9 2.9 0 1 0 0-5.8 2.9 2.9 0 0 0 0 5.8Z"
|
|
fill="currentColor"
|
|
stroke="none"
|
|
/>
|
|
</g>
|
|
</svg>
|
|
);
|
|
|
|
const isItemActive = (item: AppNavItem, pathname: string) =>
|
|
item.kind === "home"
|
|
? pathname === "/home"
|
|
: pathname === `/library/${item.libraryId}` ||
|
|
(item.key === "music" && pathname.startsWith("/music/"));
|
|
|
|
const NavItem = ({ item, active }: { item: AppNavItem; active: boolean }) => {
|
|
const className = `app-titlebar-nav-link${active ? " is-active" : ""}`;
|
|
if (item.kind === "home") {
|
|
return (
|
|
<Link
|
|
to="/home"
|
|
className={className}
|
|
aria-current={active ? "page" : undefined}
|
|
>
|
|
{item.label}
|
|
</Link>
|
|
);
|
|
}
|
|
return (
|
|
<Link
|
|
to="/library/$id"
|
|
params={{ id: item.libraryId }}
|
|
className={className}
|
|
aria-current={active ? "page" : undefined}
|
|
>
|
|
{item.label}
|
|
</Link>
|
|
);
|
|
};
|
|
|
|
export const AppTitlebar = () => {
|
|
const { pathname } = useLocation();
|
|
const navigate = useNavigate();
|
|
const visible = shouldShowTitlebar(pathname);
|
|
const isHome = pathname === "/home";
|
|
const scrolled = useScrollTrigger({
|
|
disableHysteresis: true,
|
|
threshold: 20,
|
|
});
|
|
const navigation = useAppNavigation(visible);
|
|
const navRef = useRef<HTMLElement | null>(null);
|
|
const currentMedia = useCurrentMediaItem();
|
|
|
|
const toggleSearchDialog = useSearchStore(
|
|
useShallow((s) => s.toggleSearchDialog),
|
|
);
|
|
|
|
useLayoutEffect(() => {
|
|
document.documentElement.classList.toggle("has-app-titlebar", visible);
|
|
}, [visible]);
|
|
|
|
useEffect(() => {
|
|
const active = navRef.current?.querySelector<HTMLElement>(
|
|
".app-titlebar-nav-link.is-active",
|
|
);
|
|
active?.scrollIntoView({
|
|
behavior: "smooth",
|
|
block: "nearest",
|
|
inline: "center",
|
|
});
|
|
}, [pathname, navigation.length]);
|
|
|
|
if (!visible) return null;
|
|
|
|
const overlay = isHome && !scrolled;
|
|
|
|
return (
|
|
<>
|
|
<header
|
|
className={`app-titlebar${overlay ? " app-titlebar--overlay" : ""}`}
|
|
data-tauri-drag-region
|
|
>
|
|
<div className="app-titlebar-top">
|
|
<div className="app-titlebar-start" data-tauri-drag-region>
|
|
<BackButton />
|
|
<Link
|
|
to="/home"
|
|
className="app-titlebar-brand"
|
|
aria-label="Blink — на главную"
|
|
>
|
|
<BlinkMark />
|
|
<span>Blink</span>
|
|
</Link>
|
|
</div>
|
|
|
|
<div className="app-titlebar-actions" data-tauri-drag-region>
|
|
<AppStatusIndicator />
|
|
<span className="app-titlebar-cast">
|
|
<CastButton
|
|
item={currentMedia}
|
|
getTransfer={getLocalMediaTransfer}
|
|
/>
|
|
</span>
|
|
<Tooltip title="Поиск">
|
|
<IconButton onClick={toggleSearchDialog} aria-label="Поиск">
|
|
<span className="material-symbols-rounded">search</span>
|
|
</IconButton>
|
|
</Tooltip>
|
|
<Tooltip title="Загрузки">
|
|
<IconButton
|
|
className="app-titlebar-downloads"
|
|
onClick={() => navigate({ to: "/downloads" })}
|
|
aria-label="Загрузки"
|
|
>
|
|
<span className="material-symbols-rounded">download</span>
|
|
</IconButton>
|
|
</Tooltip>
|
|
<Tooltip title="Настройки">
|
|
<Link
|
|
to="/settings/preferences"
|
|
className="app-titlebar-icon-link"
|
|
aria-label="Настройки"
|
|
>
|
|
<span className="material-symbols-rounded">settings</span>
|
|
</Link>
|
|
</Tooltip>
|
|
<UserAvatarMenu />
|
|
<WindowControls />
|
|
</div>
|
|
</div>
|
|
|
|
<nav
|
|
ref={navRef}
|
|
className="app-titlebar-nav"
|
|
aria-label="Основная навигация"
|
|
>
|
|
{navigation.map((item) => (
|
|
<NavItem
|
|
key={item.key}
|
|
item={item}
|
|
active={isItemActive(item, pathname)}
|
|
/>
|
|
))}
|
|
</nav>
|
|
</header>
|
|
</>
|
|
);
|
|
};
|