Display actors, albums, items, artist etc in libView #9
This commit is contained in:
3 files changed
+203
-53
No files matched your search
@@ -0,0 +1,24 @@
|
||||
/** @format */
|
||||
|
||||
import Box from "@mui/material/Box";
|
||||
import { MdiEmoticonCryOutline } from "../icons/mdiEmoticonCryOutline";
|
||||
import Typography from "@mui/material/Typography";
|
||||
|
||||
export const EmptyNotice = () => {
|
||||
return (
|
||||
<Box
|
||||
sx={{
|
||||
width: "100%",
|
||||
height: "100%",
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
flexFlow: "column",
|
||||
opacity: 0.4,
|
||||
}}
|
||||
>
|
||||
<MdiEmoticonCryOutline sx={{ fontSize: 200 }} />
|
||||
<Typography variant="h3">Nothing found</Typography>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
/** @format */
|
||||
import SvgIcon from "@mui/material/SvgIcon";
|
||||
|
||||
import { mdiEmoticonCryOutline } from "@mdi/js";
|
||||
|
||||
export const MdiEmoticonCryOutline = (props) => {
|
||||
return (
|
||||
<SvgIcon {...props}>
|
||||
<path d={mdiEmoticonCryOutline}></path>
|
||||
</SvgIcon>
|
||||
);
|
||||
};
|
||||
+167
-53
@@ -19,13 +19,23 @@ 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 FormControl from "@mui/material/FormControl";
|
||||
import TextField from "@mui/material/TextField";
|
||||
import Select from "@mui/material/Select";
|
||||
import MenuItem from "@mui/material/MenuItem";
|
||||
|
||||
import { theme } from "../../theme";
|
||||
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api";
|
||||
import { getArtistsApi } from "@jellyfin/sdk/lib/utils/api/artists-api";
|
||||
import { getGenresApi } from "@jellyfin/sdk/lib/utils/api/genres-api";
|
||||
import { getMusicGenresApi } from "@jellyfin/sdk/lib/utils/api/music-genres-api";
|
||||
import { getStudiosApi } from "@jellyfin/sdk/lib/utils/api/studios-api";
|
||||
import { getPersonsApi } from "@jellyfin/sdk/lib/utils/api/persons-api";
|
||||
|
||||
import { Card } from "../../components/card/card";
|
||||
import { EmptyNotice } from "../../components/emptyNotice/emptyNoticee";
|
||||
|
||||
const LibraryView = () => {
|
||||
const dispatch = useDispatch();
|
||||
@@ -35,13 +45,6 @@ const LibraryView = () => {
|
||||
dispatch(showAppBar());
|
||||
}
|
||||
const { id } = useParams();
|
||||
const [scrollTarget, setScrollTarget] = useState(undefined);
|
||||
|
||||
const trigger = useScrollTrigger({
|
||||
disableHysteresis: true,
|
||||
threshold: 0,
|
||||
target: scrollTarget,
|
||||
});
|
||||
|
||||
const user = useQuery({
|
||||
queryKey: ["libraryView", "user"],
|
||||
@@ -51,15 +54,6 @@ const LibraryView = () => {
|
||||
},
|
||||
});
|
||||
|
||||
const fetchLibItems = async (libraryId) => {
|
||||
console.log(libraryId);
|
||||
const result = await getItemsApi(window.api).getItems({
|
||||
userId: user.data.Id,
|
||||
parentId: libraryId,
|
||||
});
|
||||
return result.data;
|
||||
};
|
||||
|
||||
const fetchLib = async (libraryId) => {
|
||||
const result = await getItemsApi(window.api).getItems({
|
||||
userId: user.data.Id,
|
||||
@@ -67,7 +61,6 @@ const LibraryView = () => {
|
||||
});
|
||||
return result.data;
|
||||
};
|
||||
|
||||
const currentLib = useQuery({
|
||||
queryKey: ["libraryView", "currentLib", id],
|
||||
queryFn: () => fetchLib(id),
|
||||
@@ -79,19 +72,94 @@ const LibraryView = () => {
|
||||
dispatch(showBackButton());
|
||||
}
|
||||
|
||||
const [currentViewType, setCurrentViewType] = useState(undefined);
|
||||
const [viewType, setViewType] = useState([]);
|
||||
useEffect(() => {
|
||||
if (currentLib.isSuccess) {
|
||||
if (currentLib.data.Items[0].CollectionType == "movies") {
|
||||
setViewType([
|
||||
{ title: "movies", value: "Movie" },
|
||||
{ title: "collections", value: "BoxSet" },
|
||||
{ title: "actors", value: "Person" },
|
||||
{ title: "genres", value: "Genre" },
|
||||
{ title: "studios", value: "Studio" },
|
||||
]);
|
||||
} else if (currentLib.data.Items[0].CollectionType == "music") {
|
||||
setViewType([
|
||||
{ title: "albums", value: "MusicAlbum" },
|
||||
{ title: "artists", value: "MusicArtist" },
|
||||
{ title: "genres", value: "MusicGenre" },
|
||||
]);
|
||||
} else if (
|
||||
currentLib.data.Items[0].CollectionType == "tvshows"
|
||||
) {
|
||||
setViewType([
|
||||
{ title: "series", value: "Series" },
|
||||
{ title: "actors", value: "Person" },
|
||||
{ title: "genres", value: "Genre" },
|
||||
{ title: "networks", value: "Studio" },
|
||||
]);
|
||||
} else {
|
||||
setViewType([]);
|
||||
}
|
||||
}
|
||||
}, [currentLib.isSuccess]);
|
||||
|
||||
const fetchLibItems = async (libraryId) => {
|
||||
console.log(libraryId);
|
||||
let result;
|
||||
if (currentViewType == "MusicArtist") {
|
||||
result = await getArtistsApi(window.api).getAlbumArtists({
|
||||
userId: user.data.Id,
|
||||
parentId: libraryId,
|
||||
});
|
||||
} else if (currentViewType == "Person") {
|
||||
result = await getPersonsApi(window.api).getPersons({
|
||||
userId: user.data.Id,
|
||||
personTypes: ["Actor"],
|
||||
});
|
||||
} else if (currentViewType == "Genre") {
|
||||
result = await getGenresApi(window.api).getGenres({
|
||||
userId: user.data.Id,
|
||||
parentId: libraryId,
|
||||
});
|
||||
} else if (currentViewType == "MusicGenre") {
|
||||
result = await getMusicGenresApi(window.api).getMusicGenres({
|
||||
userId: user.data.Id,
|
||||
parentId: libraryId,
|
||||
});
|
||||
} else if (currentViewType == "Studio") {
|
||||
result = await getStudiosApi(window.api).getStudios({
|
||||
userId: user.data.Id,
|
||||
parentId: libraryId,
|
||||
});
|
||||
} else {
|
||||
result = await getItemsApi(window.api).getItems({
|
||||
userId: user.data.Id,
|
||||
parentId: libraryId,
|
||||
recursive: true,
|
||||
includeItemTypes: [currentViewType],
|
||||
});
|
||||
}
|
||||
return result.data;
|
||||
};
|
||||
|
||||
const items = useQuery({
|
||||
queryKey: ["libraryView", "currentLibItems", id],
|
||||
queryKey: ["libraryView", "currentLibItems", id, currentViewType],
|
||||
queryFn: () => fetchLibItems(id),
|
||||
enabled: !!user.data,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(setBackdrop(true));
|
||||
}, [trigger]);
|
||||
dispatch(setBackdrop(true));
|
||||
|
||||
// if (currentLib.isLoading || items.isLoading) {
|
||||
// return <h1>Loading...</h1>;
|
||||
// }
|
||||
const handleCurrentViewType = (e) => {
|
||||
setCurrentViewType(e.target.value);
|
||||
console.log(e.target.value);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (viewType.length != 0) setCurrentViewType(viewType[0].value);
|
||||
}, [viewType]);
|
||||
|
||||
return (
|
||||
<Box
|
||||
@@ -109,11 +177,6 @@ const LibraryView = () => {
|
||||
pb: 3,
|
||||
position: "relative",
|
||||
}}
|
||||
ref={(node) => {
|
||||
if (node) {
|
||||
setScrollTarget(node);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<AppBar
|
||||
position="fixed"
|
||||
@@ -125,7 +188,11 @@ const LibraryView = () => {
|
||||
>
|
||||
<Divider />
|
||||
<Toolbar>
|
||||
<Typography variant="h5" sx={{ mr: 2 }}>
|
||||
<Typography
|
||||
variant="h5"
|
||||
sx={{ mr: 2, flexShrink: 0 }}
|
||||
noWrap
|
||||
>
|
||||
{currentLib.isLoading ? (
|
||||
<CircularProgress sx={{ p: 1 }} />
|
||||
) : (
|
||||
@@ -141,33 +208,80 @@ const LibraryView = () => {
|
||||
)
|
||||
}
|
||||
/>
|
||||
|
||||
{/* <InputLabel id="demo-simple-select-label">
|
||||
Age
|
||||
</InputLabel> */}
|
||||
{viewType.length != 0 && (
|
||||
<TextField
|
||||
select
|
||||
hiddenLabel
|
||||
defaultValue={viewType[0].value}
|
||||
size="small"
|
||||
variant="filled"
|
||||
fullWidth
|
||||
sx={{ ml: "75%" }}
|
||||
onChange={handleCurrentViewType}
|
||||
>
|
||||
{viewType.map((item, index) => {
|
||||
return (
|
||||
<MenuItem
|
||||
key={item.value}
|
||||
value={item.value}
|
||||
>
|
||||
{item.title}
|
||||
</MenuItem>
|
||||
);
|
||||
})}
|
||||
</TextField>
|
||||
)}
|
||||
</Toolbar>
|
||||
</AppBar>
|
||||
<Grid2 container columns={{ xs: 3, sm: 5, md: 8 }}>
|
||||
{items.isSuccess &&
|
||||
items.data.Items.map((item, index) => {
|
||||
return (
|
||||
<Grid2 key={index} xs={1} sm={1} md={1}>
|
||||
<Card
|
||||
itemName={item.Name}
|
||||
itemId={item.Id}
|
||||
imageTags={!!item.ImageTags}
|
||||
subText={item.ProductionYear}
|
||||
iconType={item.Type}
|
||||
playedPercent={
|
||||
item.UserData
|
||||
.PlayedPercentage
|
||||
}
|
||||
cardOrientation={
|
||||
item.Type ==
|
||||
"MusicArtist"
|
||||
? "square"
|
||||
: "portait"
|
||||
}
|
||||
></Card>
|
||||
</Grid2>
|
||||
);
|
||||
})}
|
||||
(items.data.TotalRecordCount == 0 ? (
|
||||
<EmptyNotice />
|
||||
) : (
|
||||
items.data.Items.map((item, index) => {
|
||||
return (
|
||||
<Grid2
|
||||
key={index}
|
||||
xs={1}
|
||||
sm={1}
|
||||
md={1}
|
||||
>
|
||||
<Card
|
||||
itemName={item.Name}
|
||||
itemId={item.Id}
|
||||
imageTags={
|
||||
!!item.ImageTags
|
||||
.Primary
|
||||
}
|
||||
subText={
|
||||
item.ProductionYear
|
||||
}
|
||||
iconType={item.Type}
|
||||
playedPercent={
|
||||
!!item.UserData
|
||||
? item.UserData
|
||||
.PlayedPercentage
|
||||
: 0
|
||||
}
|
||||
cardOrientation={
|
||||
item.Type ==
|
||||
"MusicArtist" ||
|
||||
item.Type ==
|
||||
"MusicAlbum" ||
|
||||
item.Type ==
|
||||
"MusicGenre"
|
||||
? "square"
|
||||
: "portait"
|
||||
}
|
||||
></Card>
|
||||
</Grid2>
|
||||
);
|
||||
})
|
||||
))}
|
||||
</Grid2>
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
Reference in new issue
Block a user