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