Start working on new appBar
This commit is contained in:
9 files changed
+329
-115
No files matched your search
@@ -1,5 +1,5 @@
|
||||
/** @format */
|
||||
import React, { useEffect, useState } from "react";
|
||||
import React, { useEffect, useRef, useState } from "react";
|
||||
|
||||
import { relaunch } from "@tauri-apps/api/process";
|
||||
|
||||
@@ -11,12 +11,16 @@ import ListItemIcon from "@mui/material/ListItemIcon";
|
||||
import Menu from "@mui/material/Menu";
|
||||
import MenuItem from "@mui/material/MenuItem";
|
||||
import useScrollTrigger from "@mui/material/useScrollTrigger";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import Popper from "@mui/material/Popper";
|
||||
|
||||
import { red } from "@mui/material/colors";
|
||||
|
||||
import { useLocation, useNavigate } from "react-router-dom";
|
||||
import { useLocation, useNavigate, NavLink } from "react-router-dom";
|
||||
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import { getUserViewsApi } from "@jellyfin/sdk/lib/utils/api/user-views-api";
|
||||
|
||||
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import "./appBar.module.scss";
|
||||
@@ -35,6 +39,10 @@ import { MdiLogoutVariant } from "../icons/mdiLogoutVariant";
|
||||
import { EventEmitter as event } from "../../eventEmitter";
|
||||
import { useApi } from "../../utils/store/api";
|
||||
|
||||
import { getTypeIcon } from "../../components/utils/iconsCollection";
|
||||
|
||||
import logo from "../../assets/logo.svg";
|
||||
|
||||
export const AppBar = () => {
|
||||
const [api] = useApi((state) => [state.api]);
|
||||
const navigate = useNavigate();
|
||||
@@ -53,6 +61,17 @@ export const AppBar = () => {
|
||||
enabled: display,
|
||||
networkMode: "always",
|
||||
});
|
||||
let libraries = useQuery({
|
||||
queryKey: ["libraries"],
|
||||
queryFn: async () => {
|
||||
let libs = await getUserViewsApi(api).getUserViews({
|
||||
userId: user.data.Id,
|
||||
});
|
||||
return libs.data;
|
||||
},
|
||||
enabled: !!user.data,
|
||||
networkMode: "always",
|
||||
});
|
||||
useEffect(() => {
|
||||
if (user.isError) {
|
||||
console.error(user.error);
|
||||
@@ -91,6 +110,20 @@ export const AppBar = () => {
|
||||
navigate("/login/index");
|
||||
};
|
||||
|
||||
const [librariesPopover, setLibrariesPopover] = useState(false);
|
||||
const librariesText = useRef(null);
|
||||
const popoverEnter = (event) => {
|
||||
if (anchorEl !== event.currentTarget) {
|
||||
setLibrariesPopover(event.currentTarget);
|
||||
}
|
||||
};
|
||||
|
||||
const popoverLeave = () => {
|
||||
setLibrariesPopover(null);
|
||||
};
|
||||
|
||||
const [isBrowsingLibrary, setIsBrowsingLibrary] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
location.pathname.includes("login") ||
|
||||
@@ -104,14 +137,18 @@ export const AppBar = () => {
|
||||
} else {
|
||||
setDisplay(true);
|
||||
}
|
||||
}, [location]);
|
||||
|
||||
useEffect(() => {
|
||||
if (location.pathname == "/home") {
|
||||
setBackButtonVisible(false);
|
||||
} else {
|
||||
setBackButtonVisible(true);
|
||||
}
|
||||
|
||||
if (location.pathname.includes("library")) {
|
||||
setIsBrowsingLibrary(true);
|
||||
} else {
|
||||
setIsBrowsingLibrary(false);
|
||||
}
|
||||
}, [location]);
|
||||
|
||||
if (!display) {
|
||||
@@ -123,109 +160,211 @@ export const AppBar = () => {
|
||||
style={{
|
||||
backgroundColor: "transparent",
|
||||
paddingRight: "0 !important",
|
||||
width: "fit-content",
|
||||
}}
|
||||
className={trigger ? "appBar backdropVisible" : "appBar"}
|
||||
elevation={0}
|
||||
>
|
||||
<Toolbar
|
||||
sx={{
|
||||
justifyContent: "space-between",
|
||||
padding: "13px !important",
|
||||
display: "flex",
|
||||
gap: "1.2em",
|
||||
display: "grid",
|
||||
gap: "0.6em",
|
||||
gridTemplateColumns: "30% 1fr 30%",
|
||||
}}
|
||||
>
|
||||
<IconButton
|
||||
onClick={() => navigate(-1)}
|
||||
disabled={!backButtonVisible}
|
||||
<div
|
||||
className="flex flex-row flex-center"
|
||||
style={{
|
||||
gap: "1.2em",
|
||||
justifySelf: "start",
|
||||
}}
|
||||
>
|
||||
<div className="material-symbols-rounded">
|
||||
arrow_back
|
||||
</div>
|
||||
</IconButton>
|
||||
|
||||
<IconButton onClick={() => navigate("/search")}>
|
||||
<div className="material-symbols-rounded">
|
||||
search
|
||||
</div>
|
||||
</IconButton>
|
||||
<IconButton onClick={() => navigate("/favorite")}>
|
||||
<div className="material-symbols-rounded">
|
||||
favorite
|
||||
</div>
|
||||
</IconButton>
|
||||
<IconButton sx={{ p: 0 }} onClick={handleMenuOpen}>
|
||||
{user.isSuccess &&
|
||||
(user.data.PrimaryImageTag == undefined ? (
|
||||
<Avatar
|
||||
className="appBar-avatar"
|
||||
alt={user.data.Name}
|
||||
>
|
||||
<MdiAccount className="appBar-avatar-icon" />
|
||||
</Avatar>
|
||||
) : (
|
||||
<Avatar
|
||||
className="appBar-avatar"
|
||||
src={
|
||||
api.basePath +
|
||||
"/Users/" +
|
||||
user.data.Id +
|
||||
"/Images/Primary"
|
||||
}
|
||||
alt={user.data.Name}
|
||||
>
|
||||
<MdiAccount className="appBar-avatar-icon" />
|
||||
</Avatar>
|
||||
))}
|
||||
</IconButton>
|
||||
<Menu
|
||||
anchorEl={anchorEl}
|
||||
open={openMenu}
|
||||
onClose={handleMenuClose}
|
||||
sx={{ mt: 1 }}
|
||||
disableScrollLock
|
||||
>
|
||||
<MenuItem
|
||||
onClick={() => navigate("/settings")}
|
||||
disabled
|
||||
>
|
||||
<ListItemIcon>
|
||||
<div className="material-symbols-rounded">
|
||||
settings
|
||||
</div>
|
||||
</ListItemIcon>
|
||||
Settings
|
||||
</MenuItem>
|
||||
<MenuItem onClick={() => navigate("/about")}>
|
||||
<ListItemIcon>
|
||||
<div className="material-symbols-rounded">
|
||||
info
|
||||
</div>
|
||||
</ListItemIcon>
|
||||
About
|
||||
</MenuItem>
|
||||
<MenuItem onClick={handleLogout}>
|
||||
<ListItemIcon>
|
||||
<div className="material-symbols-rounded">
|
||||
logout
|
||||
</div>
|
||||
</ListItemIcon>
|
||||
Logout
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
onClick={async () => {
|
||||
navigate("/servers/list");
|
||||
<IconButton
|
||||
onClick={() => navigate(-1)}
|
||||
disabled={!backButtonVisible}
|
||||
style={{
|
||||
justifySelf: "left",
|
||||
}}
|
||||
>
|
||||
<ListItemIcon>
|
||||
<div className="material-symbols-rounded appBar-icon">
|
||||
dns
|
||||
</div>
|
||||
</ListItemIcon>
|
||||
Select Server
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
<div className="material-symbols-rounded">
|
||||
arrow_back
|
||||
</div>
|
||||
</IconButton>
|
||||
<img src={logo} className="appBar-logo" />
|
||||
</div>
|
||||
|
||||
<div
|
||||
className="flex flex-row flex-center"
|
||||
style={{
|
||||
gap: "2.6em",
|
||||
}}
|
||||
>
|
||||
<NavLink to="/home" className="appBar-text">
|
||||
<Typography variant="subtitle1">
|
||||
Home
|
||||
</Typography>
|
||||
</NavLink>
|
||||
<Typography
|
||||
ref={librariesText}
|
||||
variant="subtitle1"
|
||||
className={
|
||||
isBrowsingLibrary
|
||||
? "appBar-text active"
|
||||
: "appBar-text"
|
||||
}
|
||||
onMouseEnter={popoverEnter}
|
||||
// onMouseLeave={popoverLeave}
|
||||
>
|
||||
Libraries
|
||||
</Typography>
|
||||
<Menu
|
||||
open={Boolean(librariesPopover)}
|
||||
anchorEl={librariesPopover}
|
||||
// anchorOrigin={{
|
||||
// vertical: "bottom",
|
||||
// horizontal: "right",
|
||||
// }}
|
||||
// transformOrigin={{
|
||||
// vertical: "top",
|
||||
// horizontal: "left",
|
||||
// }}
|
||||
// slotProps={{
|
||||
// paper: {
|
||||
// onMouseEnter: popoverEnter,
|
||||
// onMouseLeave: popoverLeave,
|
||||
// },
|
||||
// }}
|
||||
anchorOrigin={{
|
||||
horizontal: "center",
|
||||
vertical: "bottom",
|
||||
}}
|
||||
transformOrigin={{
|
||||
horizontal: "center",
|
||||
vertical: "top",
|
||||
}}
|
||||
sx={{
|
||||
mt: 3,
|
||||
maxHeight: "72em",
|
||||
}}
|
||||
onClose={popoverLeave}
|
||||
MenuListProps={{
|
||||
onMouseLeave: popoverLeave,
|
||||
}}
|
||||
disableScrollLock
|
||||
>
|
||||
{libraries.isPending
|
||||
? "loading..."
|
||||
: libraries.data.Items.map(
|
||||
(library) => (
|
||||
<MenuItem
|
||||
key={library.Id}
|
||||
onClick={() =>
|
||||
navigate(
|
||||
`/library/${library.Id}`,
|
||||
)
|
||||
}
|
||||
>
|
||||
<ListItemIcon>
|
||||
{getTypeIcon(
|
||||
library.CollectionType,
|
||||
)}
|
||||
</ListItemIcon>
|
||||
{library.Name}
|
||||
</MenuItem>
|
||||
),
|
||||
)}
|
||||
</Menu>
|
||||
</div>
|
||||
|
||||
<div
|
||||
className="flex flex-row"
|
||||
style={{ justifySelf: "right", gap: "0.6em" }}
|
||||
>
|
||||
<IconButton onClick={() => navigate("/search")}>
|
||||
<div className="material-symbols-rounded">
|
||||
search
|
||||
</div>
|
||||
</IconButton>
|
||||
<IconButton onClick={() => navigate("/favorite")}>
|
||||
<div className="material-symbols-rounded">
|
||||
favorite
|
||||
</div>
|
||||
</IconButton>
|
||||
<IconButton
|
||||
sx={{ p: 0 }}
|
||||
onClick={handleMenuOpen}
|
||||
>
|
||||
{user.isSuccess &&
|
||||
(user.data.PrimaryImageTag ==
|
||||
undefined ? (
|
||||
<Avatar
|
||||
className="appBar-avatar"
|
||||
alt={user.data.Name}
|
||||
>
|
||||
<MdiAccount className="appBar-avatar-icon" />
|
||||
</Avatar>
|
||||
) : (
|
||||
<Avatar
|
||||
className="appBar-avatar"
|
||||
src={
|
||||
api.basePath +
|
||||
"/Users/" +
|
||||
user.data.Id +
|
||||
"/Images/Primary"
|
||||
}
|
||||
alt={user.data.Name}
|
||||
>
|
||||
<MdiAccount className="appBar-avatar-icon" />
|
||||
</Avatar>
|
||||
))}
|
||||
</IconButton>
|
||||
<Menu
|
||||
anchorEl={anchorEl}
|
||||
open={openMenu}
|
||||
onClose={handleMenuClose}
|
||||
sx={{ mt: 2 }}
|
||||
disableScrollLock
|
||||
>
|
||||
<MenuItem
|
||||
onClick={() => navigate("/settings")}
|
||||
disabled
|
||||
>
|
||||
<ListItemIcon>
|
||||
<div className="material-symbols-rounded">
|
||||
settings
|
||||
</div>
|
||||
</ListItemIcon>
|
||||
Settings
|
||||
</MenuItem>
|
||||
<MenuItem onClick={() => navigate("/about")}>
|
||||
<ListItemIcon>
|
||||
<div className="material-symbols-rounded">
|
||||
info
|
||||
</div>
|
||||
</ListItemIcon>
|
||||
About
|
||||
</MenuItem>
|
||||
<MenuItem onClick={handleLogout}>
|
||||
<ListItemIcon>
|
||||
<div className="material-symbols-rounded">
|
||||
logout
|
||||
</div>
|
||||
</ListItemIcon>
|
||||
Logout
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
onClick={async () => {
|
||||
navigate("/servers/list");
|
||||
}}
|
||||
>
|
||||
<ListItemIcon>
|
||||
<div className="material-symbols-rounded appBar-icon">
|
||||
dns
|
||||
</div>
|
||||
</ListItemIcon>
|
||||
Select Server
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
</div>
|
||||
</Toolbar>
|
||||
</MuiAppBar>
|
||||
);
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
/** @format */
|
||||
|
||||
.appBar {
|
||||
top: 8px !important;
|
||||
right: 8px !important;
|
||||
border-radius: 10000px;
|
||||
transition: background-color $transition-time-fast,
|
||||
backdrop-filter $transition-time-fast,
|
||||
box-shadow $transition-time-default !important;
|
||||
@@ -20,6 +17,49 @@
|
||||
&-logo {
|
||||
height: 1.8em !important;
|
||||
}
|
||||
&-text {
|
||||
cursor: default;
|
||||
opacity: 0.7;
|
||||
transition: opacity $transition-time-fast;
|
||||
position: relative;
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
&::after {
|
||||
content: "";
|
||||
width: 100%;
|
||||
height: 1.2px;
|
||||
background: white;
|
||||
opacity: 0.7;
|
||||
position: absolute;
|
||||
bottom: -2.6px;
|
||||
left: 0;
|
||||
transform: scaleX(0);
|
||||
transition: transform $transition-time-fast,
|
||||
background $transition-time-fast,
|
||||
opacity $transition-time-fast;
|
||||
}
|
||||
&:hover {
|
||||
opacity: 0.8;
|
||||
&::after {
|
||||
transform: scaleX(0.5);
|
||||
opacity: 0.8;
|
||||
}
|
||||
}
|
||||
&.active {
|
||||
opacity: 1;
|
||||
color: $clr-accent-default;
|
||||
&::after {
|
||||
transform: scaleX(0.75);
|
||||
opacity: 1;
|
||||
background: $clr-accent-default;
|
||||
}
|
||||
}
|
||||
}
|
||||
&-logo {
|
||||
width: 20em;
|
||||
object-fit: contain;
|
||||
object-position: center;
|
||||
}
|
||||
}
|
||||
|
||||
.appLoading {
|
||||
|
||||
Reference in new issue
Block a user