Update Appbar

This commit is contained in:
Prayag Prajapati committed 2024-01-04 12:40:33 +05:30
1 parent 73ac8a529e
commit 87f9eaf8b6
5 files changed
+253 -77

No files matched your search

+1 -2
View File
@@ -474,8 +474,7 @@ function App() {
element={
<Navigate to={initialRoute} />
}
// element={<></>}
/>
></Route>
<Route
path="/error"
element={
+182 -66
View File
@@ -12,7 +12,10 @@ 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 Button from "@mui/material/Button";
import Popper from "@mui/material/Popper";
import Paper from "@mui/material/Paper";
import Grow from "@mui/material/Grow";
import { red } from "@mui/material/colors";
@@ -43,6 +46,23 @@ import { getTypeIcon } from "../../components/utils/iconsCollection";
import logo from "../../assets/icon.svg";
const forwardRefNavLink = React.forwardRef({
displayName: "NavLink",
render: (props, ref) => (
<NavLink
ref={ref}
to={props.to}
className={({ isActive }) =>
`${props.className} ${
isActive ? props.activeClassName : ""
}`
}
>
{props.children}
</NavLink>
),
});
export const AppBar = () => {
const [api] = useApi((state) => [state.api]);
const navigate = useNavigate();
@@ -110,16 +130,15 @@ export const AppBar = () => {
navigate("/login/index");
};
const [librariesPopover, setLibrariesPopover] = useState(false);
const [librariesPopper, setLibrariesPopper] = useState(false);
const librariesText = useRef(null);
const popoverEnter = (event) => {
if (anchorEl !== event.currentTarget) {
setLibrariesPopover(event.currentTarget);
}
};
const popoverLeave = () => {
setLibrariesPopover(null);
const handlePopper = (event) => {
if (librariesPopper) {
setLibrariesPopper(null);
} else {
setLibrariesPopper(event.currentTarget);
}
};
const [isBrowsingLibrary, setIsBrowsingLibrary] = useState(false);
@@ -190,16 +209,70 @@ export const AppBar = () => {
gap: "2.6em",
}}
>
<NavLink to="/home" className="appBar-text">
<NavLink to="/home">
{({ isActive }) =>
isActive ? (
<Button
style={{
textTransform: "none",
}}
size="large"
>
<Typography
className="appBar-text active"
variant="subtitle1"
fontWeight={600}
>
Home
</Typography>
</Button>
) : (
<Button
style={{
textTransform: "none",
}}
// className="appBar-text "
color="white"
>
<Typography
className="appBar-text "
variant="subtitle1"
fontWeight={600}
>
Home
</Typography>
</Button>
)
}
</NavLink>
<Button
variant="text"
// disableRipple
disableElevation
onClick={handlePopper}
style={{ textTransform: "none" }}
size="large"
disableFocusRipple={false}
color={
isBrowsingLibrary ? "primary" : "white"
}
// ref={librariesText}
>
<Typography
variant="subtitle1"
fontWeight={600}
className={
isBrowsingLibrary
? "appBar-text active"
: "appBar-text"
}
>
Home
Libraries
</Typography>
</NavLink>
<Typography
ref={librariesText}
</Button>
{/* <Typography
variant="subtitle1"
fontWeight={600}
onMouseEnter={popoverEnter}
@@ -211,61 +284,104 @@ export const AppBar = () => {
: "appBar-text"
}
// onMouseLeave={popoverLeave}
>
Libraries
</Typography>
></Typography> */}
<Menu
open={Boolean(librariesPopover)}
anchorEl={librariesPopover}
anchorOrigin={{
horizontal: "center",
vertical: "bottom",
}}
transformOrigin={{
horizontal: "center",
vertical: "top",
}}
sx={{
mt: 3,
maxHeight: "72em",
}}
onClose={popoverLeave}
MenuListProps={{
onMouseLeave: popoverLeave,
}}
disableScrollLock
hideBackdrop
<Popper
open={Boolean(librariesPopper)}
anchorEl={librariesPopper}
placement="bottom"
disablePortal
modifiers={[
{
name: "flip",
enabled: true,
options: {
altBoundary: true,
rootBoundary: "document",
padding: 8,
},
},
{
name: "preventOverflow",
enabled: true,
options: {
altAxis: true,
altBoundary: true,
tether: true,
rootBoundary: "document",
padding: 8,
},
},
]}
transition
>
{libraries.isPending
? "loading..."
: libraries.data.Items.map(
(library) => (
<MenuItem
component={NavLink}
to={
"/library/" +
library.Id
}
key={library.Id}
// onClick={() =>
// navigate(
// `/library/${library.Id}`,
// )
// }
tabIndex={0}
className="appBar-library"
>
<ListItemIcon>
{getTypeIcon(
library.CollectionType,
)}
</ListItemIcon>
{library.Name}
</MenuItem>
),
)}
</Menu>
{({ TransitionProps }) => (
<Grow
{...TransitionProps}
style={{
transformOrigin: "50% 0 0",
}}
timeout={250}
>
<Paper
sx={{
mt: "1.1em",
maxHeight: "72em",
}}
style={{
boxShadow:
"0px 5px 5px -3px rgba(0,0,0,0.2), 0px 8px 10px 1px rgba(0,0,0,0.14), 0px 3px 14px 2px rgba(0,0,0,0.12)",
overflow: "hidden",
borderRadius: "25px",
}}
>
<div className="appBar-library-scrollContainer">
{libraries.isPending
? "loading..."
: libraries.data.Items.map(
(
library,
) => (
<NavLink
key={
library.Id
}
className="appBar-library"
to={`library/${library.Id}`}
style={{
borderRadius:
"10px",
}}
>
{Object.keys(
library.ImageTags,
).includes(
"Primary",
) ? (
<img
src={`${api.basePath}/Items/${library.Id}/Images/Primary?quality=90&fillHeight=226&fillWidth=127`}
/>
) : (
<div className="appBar-library-icon">
{" "}
{getTypeIcon(
library.CollectionType,
)}{" "}
<Typography variant="h6">
{
library.Name
}
</Typography>
</div>
)}
</NavLink>
),
)}
</div>
</Paper>
</Grow>
)}
</Popper>
</div>
<div
+69 -3
View File
@@ -15,7 +15,6 @@
}
}
&-text {
cursor: default;
opacity: 0.7;
transition: opacity $transition-time-fast;
position: relative;
@@ -53,9 +52,76 @@
}
}
&-library {
transition: all 0.2s;
position: relative;
width: 20rem;
text-decoration: none;
&::after {
content: "";
position: absolute;
inset: 5px;
background: rgb(0 0 0 / 0.3);
opacity: 0;
transition: opacity $transition-time-fast;
border-radius: 5px;
}
> img {
border: 0px solid white;
width: inherit;
object-fit: cover;
height: 100%;
border-radius: 10px;
transition: border $transition-time-fast;
}
&-icon {
height: 100%;
width: inherit;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
color: white !important;
background: rgb(255 255 255 / 0.1);
border: 0px solid white;
border-radius: 10px;
transition: border $transition-time-fast;
.material-symbols-rounded {
font-size: 3em;
}
}
&.active {
background: $clr-gradient-default;
&::after {
opacity: 1;
}
> img {
border: 5px solid white;
}
.material-symbols-rounded {
font-variation-settings: "FILL" 1, "wght" 300, "GRAD" 25,
"opsz" 40;
}
.appBar-library-icon {
border: 5px solid white;
}
}
&-scrollContainer {
display: flex;
max-width: 35vw;
overflow: auto;
gap: 1em;
height: inherit;
padding: 15px;
// Magic scrollbar
&::-webkit-scrollbar {
&-thumb {
width: 150px;
}
&-track {
margin-left: 25px;
margin-right: 25px;
background: transparent !important;
}
}
}
}
}
+1 -6
View File
@@ -35,18 +35,13 @@ const jellyfin = new Jellyfin({
* @typedef {import("@jellyfin/sdk").Api} Api
*/
export const useApi = create((set) => ({
export const useApi = create(() => ({
/**
* @type {Api}
*/
api: null,
deviceId: localStorage.getItem("deviceId"),
jellyfin: jellyfin,
createApi: (serverAddress, accessToken) =>
set((state) => ({
...state,
api: jellyfin.createApi(serverAddress, accessToken, axiosClient),
})),
}));
/**