Update LibraryView #9
This commit is contained in:
5 files changed
+98
-16
No files matched your search
@@ -1,18 +1,20 @@
|
|||||||
/** @format */
|
/** @format */
|
||||||
|
import { useEffect } from "react";
|
||||||
|
|
||||||
import MuiAppBar from "@mui/material/AppBar";
|
import MuiAppBar from "@mui/material/AppBar";
|
||||||
import TextField from "@mui/material/TextField";
|
import TextField from "@mui/material/TextField";
|
||||||
import IconButton from "@mui/material/IconButton";
|
import IconButton from "@mui/material/IconButton";
|
||||||
import InputAdornment from "@mui/material/InputAdornment";
|
|
||||||
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 { MdiMagnify } from "../icons/mdiMagnify";
|
import { MdiMagnify } from "../icons/mdiMagnify";
|
||||||
import { theme } from "../../theme";
|
import { theme } from "../../theme";
|
||||||
|
|
||||||
import { useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import { useLocation } from "react-router-dom";
|
import { useLocation, useNavigate } from "react-router-dom";
|
||||||
|
import { removePage } 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";
|
||||||
@@ -20,13 +22,17 @@ import { useQueryClient, useQuery } from "@tanstack/react-query";
|
|||||||
import "./appBar.module.scss";
|
import "./appBar.module.scss";
|
||||||
import { MdiAccount } from "../icons/mdiAccount";
|
import { MdiAccount } from "../icons/mdiAccount";
|
||||||
import { MdiHeartOutline } from "../icons/mdiHeartOutline";
|
import { MdiHeartOutline } from "../icons/mdiHeartOutline";
|
||||||
|
import { MdiArrowLeft } from "../icons/mdiArrowLeft";
|
||||||
|
|
||||||
export const AppBar = () => {
|
export const AppBar = () => {
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
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 backdropVisible = useSelector((state) => state.appBar.backdrop);
|
const backdropVisible = useSelector((state) => state.appBar.backdrop);
|
||||||
|
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
console.log(location);
|
|
||||||
|
|
||||||
const user = useQuery({
|
const user = useQuery({
|
||||||
queryKey: ["appBar", "user"],
|
queryKey: ["appBar", "user"],
|
||||||
@@ -36,6 +42,12 @@ export const AppBar = () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (location.pathname == "/home") {
|
||||||
|
dispatch(removePage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
visible && (
|
visible && (
|
||||||
<MuiAppBar
|
<MuiAppBar
|
||||||
@@ -50,7 +62,26 @@ export const AppBar = () => {
|
|||||||
elevation={backdropVisible ? 6 : 0}
|
elevation={backdropVisible ? 6 : 0}
|
||||||
>
|
>
|
||||||
<Toolbar sx={{ justifyContent: "space-between" }}>
|
<Toolbar sx={{ justifyContent: "space-between" }}>
|
||||||
<Box sx={{ display: "flex", gap: 1 }}>
|
<Box
|
||||||
|
sx={{
|
||||||
|
display: "flex",
|
||||||
|
gap: 1,
|
||||||
|
alignItems: "center",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{page != undefined && (
|
||||||
|
<>
|
||||||
|
<IconButton
|
||||||
|
onClick={() => navigate(-1)}
|
||||||
|
>
|
||||||
|
<MdiArrowLeft />
|
||||||
|
</IconButton>
|
||||||
|
<Typography sx={{ mr: 3 }} variant="h5">
|
||||||
|
{page}
|
||||||
|
</Typography>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
<TextField
|
<TextField
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
placeholder="Search..."
|
placeholder="Search..."
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ export const Card = ({
|
|||||||
playedPercent,
|
playedPercent,
|
||||||
cardOrientation,
|
cardOrientation,
|
||||||
props,
|
props,
|
||||||
|
onClickEvent,
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<MuiCard
|
<MuiCard
|
||||||
@@ -40,7 +41,9 @@ export const Card = ({
|
|||||||
elevation={0}
|
elevation={0}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
<CardActionArea>
|
<CardActionArea
|
||||||
|
onClick={!!onClickEvent ? onClickEvent : () => {}}
|
||||||
|
>
|
||||||
<Box
|
<Box
|
||||||
className="card-media-container"
|
className="card-media-container"
|
||||||
sx={{
|
sx={{
|
||||||
@@ -172,4 +175,5 @@ Card.propTypes = {
|
|||||||
subText: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
subText: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||||
playedPercent: PropTypes.number,
|
playedPercent: PropTypes.number,
|
||||||
cardOrientation: PropTypes.string.isRequired,
|
cardOrientation: PropTypes.string.isRequired,
|
||||||
|
onClickEvent: PropTypes.func,
|
||||||
};
|
};
|
||||||
@@ -49,7 +49,7 @@ import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api"
|
|||||||
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api";
|
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api";
|
||||||
import { getTvShowsApi } from "@jellyfin/sdk/lib/utils/api/tv-shows-api";
|
import { getTvShowsApi } from "@jellyfin/sdk/lib/utils/api/tv-shows-api";
|
||||||
|
|
||||||
import { useNavigate, useLocation } from "react-router-dom";
|
import { useNavigate, useLocation, Link } from "react-router-dom";
|
||||||
|
|
||||||
import { formateDate } from "../../utils/date/formateDate";
|
import { formateDate } from "../../utils/date/formateDate";
|
||||||
import { getRuntime } from "../../utils/date/time";
|
import { getRuntime } from "../../utils/date/time";
|
||||||
@@ -497,12 +497,13 @@ const Home = () => {
|
|||||||
})
|
})
|
||||||
)}
|
)}
|
||||||
</Carousel>
|
</Carousel>
|
||||||
<CardScroller displayCards={4} title="Libraries">
|
|
||||||
{libraries.isLoading ? (
|
{libraries.isLoading ? (
|
||||||
<CardsSkeleton />
|
<CardsSkeleton />
|
||||||
) : (
|
) : (
|
||||||
libraries.status == "success" &&
|
<CardScroller displayCards={4} title="Libraries">
|
||||||
libraries.data.Items.map((item, index) => {
|
{libraries.status == "success" &&
|
||||||
|
libraries.data.Items.map(
|
||||||
|
(item, index) => {
|
||||||
return (
|
return (
|
||||||
<Card
|
<Card
|
||||||
key={index}
|
key={index}
|
||||||
@@ -510,16 +511,26 @@ const Home = () => {
|
|||||||
itemId={item.Id}
|
itemId={item.Id}
|
||||||
// imageTags={false}
|
// imageTags={false}
|
||||||
imageTags={
|
imageTags={
|
||||||
!!item.ImageTags.Primary
|
!!item
|
||||||
|
.ImageTags
|
||||||
|
.Primary
|
||||||
}
|
}
|
||||||
cardType="lib"
|
cardType="lib"
|
||||||
cardOrientation="landscape"
|
cardOrientation="landscape"
|
||||||
iconType={item.CollectionType}
|
iconType={
|
||||||
|
item.CollectionType
|
||||||
|
}
|
||||||
|
onClickEvent={() => {
|
||||||
|
navigate(
|
||||||
|
`/library/${item.Id}`,
|
||||||
|
);
|
||||||
|
}}
|
||||||
></Card>
|
></Card>
|
||||||
);
|
);
|
||||||
})
|
},
|
||||||
)}
|
)}
|
||||||
</CardScroller>
|
</CardScroller>
|
||||||
|
)}
|
||||||
{upNextItems.isLoading ? (
|
{upNextItems.isLoading ? (
|
||||||
<CardsSkeleton />
|
<CardsSkeleton />
|
||||||
) : upNextItems.isSuccess &&
|
) : upNextItems.isSuccess &&
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
/** @format */
|
/** @format */
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import { showAppBar, setBackdrop } from "../../utils/slice/appBar";
|
import {
|
||||||
|
showAppBar,
|
||||||
|
setBackdrop,
|
||||||
|
setPage,
|
||||||
|
removePage,
|
||||||
|
} from "../../utils/slice/appBar";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
|
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
@@ -48,8 +53,27 @@ const LibraryView = () => {
|
|||||||
return result.data;
|
return result.data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const fetchLib = async (libraryId) => {
|
||||||
|
const result = await getItemsApi(window.api).getItems({
|
||||||
|
userId: user.data.Id,
|
||||||
|
ids: [libraryId],
|
||||||
|
});
|
||||||
|
return result.data;
|
||||||
|
};
|
||||||
|
|
||||||
|
const currentLib = useQuery({
|
||||||
|
queryKey: ["libraryView", "currentLib", id],
|
||||||
|
queryFn: () => fetchLib(id),
|
||||||
|
enabled: !!user.data,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (currentLib.isSuccess) {
|
||||||
|
// console.log(currentLib.data.)
|
||||||
|
dispatch(setPage(currentLib.data.Items[0].Name));
|
||||||
|
}
|
||||||
|
|
||||||
const items = useQuery({
|
const items = useQuery({
|
||||||
queryKey: ["libraryView", id],
|
queryKey: ["libraryView", "currentLibItems", id],
|
||||||
queryFn: () => fetchLibItems(id),
|
queryFn: () => fetchLibItems(id),
|
||||||
enabled: !!user.data,
|
enabled: !!user.data,
|
||||||
});
|
});
|
||||||
@@ -58,6 +82,10 @@ const LibraryView = () => {
|
|||||||
dispatch(setBackdrop(trigger));
|
dispatch(setBackdrop(trigger));
|
||||||
}, [trigger]);
|
}, [trigger]);
|
||||||
|
|
||||||
|
if (currentLib.isLoading || items.isLoading) {
|
||||||
|
return <h1>Loading...</h1>;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ export const appBarSlice = createSlice({
|
|||||||
initialState: {
|
initialState: {
|
||||||
visible: false,
|
visible: false,
|
||||||
backdrop: false,
|
backdrop: false,
|
||||||
|
page: undefined,
|
||||||
},
|
},
|
||||||
reducers: {
|
reducers: {
|
||||||
showAppBar: (state) => {
|
showAppBar: (state) => {
|
||||||
@@ -17,8 +18,15 @@ export const appBarSlice = createSlice({
|
|||||||
setBackdrop: (state, action) => {
|
setBackdrop: (state, action) => {
|
||||||
state.backdrop = action.payload;
|
state.backdrop = action.payload;
|
||||||
},
|
},
|
||||||
|
setPage: (state, action) => {
|
||||||
|
state.page = action.payload;
|
||||||
|
},
|
||||||
|
removePage: (state) => {
|
||||||
|
state.page = undefined;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const { showAppBar, hideAppBar, setBackdrop } = appBarSlice.actions;
|
export const { showAppBar, hideAppBar, setBackdrop, setPage, removePage } =
|
||||||
|
appBarSlice.actions;
|
||||||
export default appBarSlice.reducer;
|
export default appBarSlice.reducer;
|
||||||
Reference in new issue
Block a user