199 lines
4.7 KiB
React
199 lines
4.7 KiB
React
/** @format */
|
|
import PropTypes from "prop-types";
|
|
|
|
import { useQueryClient, useQuery, QueryClient } from "@tanstack/react-query";
|
|
import { getLibraryApi } from "@jellyfin/sdk/lib/utils/api/library-api";
|
|
|
|
import { useNavigate } from "react-router-dom";
|
|
|
|
import { theme } from "../../theme";
|
|
|
|
import { styled } from "@mui/material/styles";
|
|
import Skeleton from "@mui/material/Skeleton";
|
|
import Tooltip from "@mui/material/Tooltip";
|
|
import List from "@mui/material/List";
|
|
import ListItem from "@mui/material/ListItem";
|
|
import ListItemText from "@mui/material/ListItemText";
|
|
import ListItemIcon from "@mui/material/ListItemIcon";
|
|
import ListItemButton from "@mui/material/ListItemButton";
|
|
import IconButton from "@mui/material/IconButton";
|
|
import Divider from "@mui/material/Divider";
|
|
import MuiDrawer from "@mui/material/Drawer";
|
|
|
|
import { MdiMenu } from "../icons/mdiMenu";
|
|
import { MdiLogoutVariant } from "../icons/mdiLogoutVariant";
|
|
|
|
import { MediaCollectionTypeIconCollection } from "../../components/utils/iconsCollection.jsx";
|
|
|
|
import { useSelector } from "react-redux";
|
|
|
|
const drawerWidth = 320;
|
|
|
|
const DrawerHeader = styled("div")(({ theme }) => ({
|
|
display: "flex",
|
|
alignItems: "center",
|
|
justifyContent: "flex-end",
|
|
padding: theme.spacing(0, 1),
|
|
// necessary for content to be below app bar
|
|
...theme.mixins.toolbar,
|
|
}));
|
|
|
|
const MiniDrawer = styled(MuiDrawer, {
|
|
shouldForwardProp: (prop) => prop !== "open",
|
|
})(({ theme }) => ({
|
|
flexShrink: 0,
|
|
whiteSpace: "nowrap",
|
|
boxSizing: "border-box",
|
|
backgroundColor: theme.palette.primary.background.dark,
|
|
overflowX: "hidden",
|
|
// width: `calc(${theme.spacing(7)} + 10px)`,
|
|
}));
|
|
|
|
export const SideMenu = ({}) => {
|
|
const queryClient = useQueryClient();
|
|
const visible = useSelector((state) => state.sidebar.visible);
|
|
const navigate = useNavigate();
|
|
let libraries = useQuery({
|
|
queryKey: ["sidemenu", "libraries"],
|
|
queryFn: async () => {
|
|
let libs = await getLibraryApi(window.api).getMediaFolders();
|
|
return libs.data;
|
|
},
|
|
});
|
|
const handleDrawerOpen = () => {};
|
|
|
|
const handleLogout = async () => {
|
|
await window.api.logout();
|
|
navigate("/login");
|
|
console.log("logged out user");
|
|
};
|
|
|
|
return (
|
|
<MiniDrawer
|
|
variant="permanent"
|
|
open={false}
|
|
PaperProps={{
|
|
sx: {
|
|
backgroundColor: "inherit",
|
|
border: "none",
|
|
width: visible
|
|
? `calc(${theme.spacing(7)} + 10px)`
|
|
: 0,
|
|
height: "100vh",
|
|
// display: visible ? "block" : "none",
|
|
},
|
|
}}
|
|
sx={{
|
|
width: visible ? `calc(${theme.spacing(7)} + 10px)` : 0,
|
|
}}
|
|
>
|
|
<DrawerHeader
|
|
className="Mui-DrawerHeader"
|
|
sx={{
|
|
justifyContent: "center",
|
|
}}
|
|
>
|
|
{/* <div>
|
|
<Avatar src={""}/>
|
|
<Typography variant="h3">
|
|
{user["Name"]}
|
|
</Typography>
|
|
</div> */}
|
|
<IconButton
|
|
color="inherit"
|
|
aria-label="open drawer"
|
|
onClick={handleDrawerOpen}
|
|
>
|
|
<MdiMenu />
|
|
</IconButton>
|
|
</DrawerHeader>
|
|
<Divider />
|
|
{libraries.isLoading ? (
|
|
<>
|
|
<Skeleton
|
|
height="100%"
|
|
variant="rounded"
|
|
width="calc(100% - 10px )"
|
|
sx={{ margin: "5px" }}
|
|
></Skeleton>
|
|
</>
|
|
) : (
|
|
<>
|
|
<List sx={{ border: "none" }}>
|
|
{libraries.data.Items.map((library, index) => {
|
|
return (
|
|
<Tooltip
|
|
title={library.Name}
|
|
placement="right"
|
|
arrow
|
|
followCursor
|
|
key={index}
|
|
>
|
|
<ListItem disablePadding>
|
|
<ListItemButton
|
|
sx={{
|
|
minHeight: 48,
|
|
justifyContent:
|
|
"center",
|
|
px: 2.5,
|
|
}}
|
|
>
|
|
<ListItemIcon
|
|
sx={{
|
|
minWidth: 0,
|
|
justifyContent:
|
|
"center",
|
|
}}
|
|
>
|
|
{
|
|
MediaCollectionTypeIconCollection[
|
|
library
|
|
.CollectionType
|
|
]
|
|
}
|
|
</ListItemIcon>
|
|
</ListItemButton>
|
|
</ListItem>
|
|
</Tooltip>
|
|
);
|
|
})}
|
|
</List>
|
|
<List sx={{ marginTop: "auto" }}>
|
|
<Tooltip
|
|
title="Logout"
|
|
placement="right"
|
|
followCursor
|
|
arrow
|
|
>
|
|
<ListItem disablePadding>
|
|
<ListItemButton
|
|
sx={{
|
|
minHeight: 48,
|
|
justifyContent: "center",
|
|
px: 2.5,
|
|
}}
|
|
onClick={handleLogout}
|
|
>
|
|
<ListItemIcon
|
|
sx={{
|
|
minWidth: 0,
|
|
justifyContent: "center",
|
|
}}
|
|
>
|
|
<MdiLogoutVariant></MdiLogoutVariant>
|
|
</ListItemIcon>
|
|
</ListItemButton>
|
|
</ListItem>
|
|
</Tooltip>
|
|
</List>
|
|
</>
|
|
)}
|
|
</MiniDrawer>
|
|
);
|
|
};
|
|
|
|
// SideMenu.propTypes = {
|
|
// skeleton: PropTypes.bool.isRequired,
|
|
// data: PropTypes.array.isRequired,
|
|
// };
|