Add bar to libview #9

This commit is contained in:
prayag17 committed 2023-04-05 14:24:26 +05:30
1 parent 7cba5a39f6
commit 628f90ef57
4 files changed
+78 -33

No files matched your search

+20 -18
View File
@@ -7,14 +7,14 @@ import IconButton from "@mui/material/IconButton";
import Toolbar from "@mui/material/Toolbar"; import Toolbar from "@mui/material/Toolbar";
import Avatar from "@mui/material/Avatar"; import Avatar from "@mui/material/Avatar";
import Box from "@mui/material/Box"; import Box from "@mui/material/Box";
import Typography from "@mui/material/Typography"; import Zoom from "@mui/material/Zoom";
import { MdiMagnify } from "../icons/mdiMagnify"; import { MdiMagnify } from "../icons/mdiMagnify";
import { theme } from "../../theme"; import { theme } from "../../theme";
import { useDispatch, useSelector } from "react-redux"; import { useDispatch, useSelector } from "react-redux";
import { useLocation, useNavigate } from "react-router-dom"; import { useLocation, useNavigate } from "react-router-dom";
import { removePage } from "../../utils/slice/appBar"; import { hideBackButton } from "../../utils/slice/appBar";
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
import { useQueryClient, useQuery } from "@tanstack/react-query"; import { useQueryClient, useQuery } from "@tanstack/react-query";
@@ -29,7 +29,9 @@ export const AppBar = () => {
const navigate = useNavigate(); const navigate = useNavigate();
const visible = useSelector((state) => state.appBar.visible); const visible = useSelector((state) => state.appBar.visible);
const page = useSelector((state) => state.appBar.page); const backButtonVisible = useSelector(
(state) => state.appBar.backButtonVisible,
);
const backdropVisible = useSelector((state) => state.appBar.backdrop); const backdropVisible = useSelector((state) => state.appBar.backdrop);
const location = useLocation(); const location = useLocation();
@@ -44,7 +46,7 @@ export const AppBar = () => {
useEffect(() => { useEffect(() => {
if (location.pathname == "/home") { if (location.pathname == "/home") {
dispatch(removePage()); dispatch(hideBackButton());
} }
}); });
@@ -52,8 +54,8 @@ export const AppBar = () => {
visible && ( visible && (
<MuiAppBar <MuiAppBar
sx={{ sx={{
width: `calc(100vw - ${theme.spacing(7)} - 20px)`, width: `calc(100vw - ${theme.spacing(7)} - 10px)`,
mr: "10px", // mr: "10px",
background: "transparent", background: "transparent",
}} }}
className={ className={
@@ -69,18 +71,18 @@ export const AppBar = () => {
alignItems: "center", alignItems: "center",
}} }}
> >
{page != undefined && ( <IconButton
<> onClick={() => navigate(-1)}
<IconButton sx={{
onClick={() => navigate(-1)} transition: "transform 0.2s",
> transform: backButtonVisible
<MdiArrowLeft /> ? "scale(1)"
</IconButton> : "scale(0)",
<Typography sx={{ mr: 3 }} variant="h5"> transformOrigin: "left",
{page} }}
</Typography> >
</> <MdiArrowLeft />
)} </IconButton>
<TextField <TextField
variant="outlined" variant="outlined"
+43 -8
View File
@@ -4,8 +4,7 @@ import { useDispatch, useSelector } from "react-redux";
import { import {
showAppBar, showAppBar,
setBackdrop, setBackdrop,
setPage, showBackButton,
removePage,
} from "../../utils/slice/appBar"; } from "../../utils/slice/appBar";
import { useParams } from "react-router-dom"; import { useParams } from "react-router-dom";
@@ -14,6 +13,14 @@ import { useQuery } from "@tanstack/react-query";
import Box from "@mui/material/Box"; import Box from "@mui/material/Box";
import Grid2 from "@mui/material/Unstable_Grid2"; import Grid2 from "@mui/material/Unstable_Grid2";
import useScrollTrigger from "@mui/material/useScrollTrigger"; import useScrollTrigger from "@mui/material/useScrollTrigger";
import AppBar from "@mui/material/AppBar";
import Toolbar from "@mui/material/Toolbar";
import Typography from "@mui/material/Typography";
import CircularProgress from "@mui/material/CircularProgress";
import Divider from "@mui/material/Divider";
import Chip from "@mui/material/Chip";
import { theme } from "../../theme";
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api"; import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api";
@@ -69,7 +76,7 @@ const LibraryView = () => {
if (currentLib.isSuccess) { if (currentLib.isSuccess) {
// console.log(currentLib.data.) // console.log(currentLib.data.)
dispatch(setPage(currentLib.data.Items[0].Name)); dispatch(showBackButton());
} }
const items = useQuery({ const items = useQuery({
@@ -79,12 +86,12 @@ const LibraryView = () => {
}); });
useEffect(() => { useEffect(() => {
dispatch(setBackdrop(trigger)); dispatch(setBackdrop(true));
}, [trigger]); }, [trigger]);
if (currentLib.isLoading || items.isLoading) { // if (currentLib.isLoading || items.isLoading) {
return <h1>Loading...</h1>; // return <h1>Loading...</h1>;
} // }
return ( return (
<Box <Box
@@ -97,7 +104,7 @@ const LibraryView = () => {
className="scrollY" className="scrollY"
sx={{ sx={{
flexGrow: 1, flexGrow: 1,
pt: 11, pt: 19,
px: 3, px: 3,
pb: 3, pb: 3,
position: "relative", position: "relative",
@@ -108,6 +115,34 @@ const LibraryView = () => {
} }
}} }}
> >
<AppBar
position="fixed"
elevation={0}
sx={{
width: `calc(100vw - ${theme.spacing(7)} - 10px)`,
mt: 8,
}}
>
<Divider />
<Toolbar>
<Typography variant="h5" sx={{ mr: 2 }}>
{currentLib.isLoading ? (
<CircularProgress sx={{ p: 1 }} />
) : (
currentLib.data.Items[0].Name
)}
</Typography>
<Chip
label={
items.isLoading ? (
<CircularProgress sx={{ p: 1 }} />
) : (
items.data.TotalRecordCount
)
}
/>
</Toolbar>
</AppBar>
<Grid2 container columns={{ xs: 3, sm: 5, md: 8 }}> <Grid2 container columns={{ xs: 3, sm: 5, md: 8 }}>
{items.isSuccess && {items.isSuccess &&
items.data.Items.map((item, index) => { items.data.Items.map((item, index) => {
+3
View File
@@ -1,15 +1,18 @@
/** @format */ /** @format */
::-webkit-scrollbar { ::-webkit-scrollbar {
z-index: 10000;
width: 10px; width: 10px;
background: $clr-background-dark; background: $clr-background-dark;
} }
::-webkit-scrollbar-track { ::-webkit-scrollbar-track {
z-index: 10000;
background-color: transparent; background-color: transparent;
&:hover { &:hover {
background: rgb(255 255 255 / 0.25); background: rgb(255 255 255 / 0.25);
} }
} }
::-webkit-scrollbar-thumb { ::-webkit-scrollbar-thumb {
z-index: 10000;
background: rgb(255 255 255 / 0.25); background: rgb(255 255 255 / 0.25);
} }
+12 -7
View File
@@ -6,7 +6,7 @@ export const appBarSlice = createSlice({
initialState: { initialState: {
visible: false, visible: false,
backdrop: false, backdrop: false,
page: undefined, backButtonVisible: false,
}, },
reducers: { reducers: {
showAppBar: (state) => { showAppBar: (state) => {
@@ -18,15 +18,20 @@ export const appBarSlice = createSlice({
setBackdrop: (state, action) => { setBackdrop: (state, action) => {
state.backdrop = action.payload; state.backdrop = action.payload;
}, },
setPage: (state, action) => { showBackButton: (state, action) => {
state.page = action.payload; state.backButtonVisible = true;
}, },
removePage: (state) => { hideBackButton: (state) => {
state.page = undefined; state.backButtonVisible = false;
}, },
}, },
}); });
export const { showAppBar, hideAppBar, setBackdrop, setPage, removePage } = export const {
appBarSlice.actions; showAppBar,
hideAppBar,
setBackdrop,
showBackButton,
hideBackButton,
} = appBarSlice.actions;
export default appBarSlice.reducer; export default appBarSlice.reducer;