From 51647cdd0de6fc06297ec96296c58036c37d546a Mon Sep 17 00:00:00 2001 From: prayag17 Date: Wed, 5 Apr 2023 17:30:17 +0530 Subject: [PATCH] Display actors, albums, items, artist etc in libView #9 --- src/components/emptyNotice/emptyNoticee.jsx | 24 ++ .../icons/mdiEmoticonCryOutline.jsx | 12 + src/routes/library/root.jsx | 220 +++++++++++++----- 3 files changed, 203 insertions(+), 53 deletions(-) create mode 100644 src/components/emptyNotice/emptyNoticee.jsx create mode 100644 src/components/icons/mdiEmoticonCryOutline.jsx diff --git a/src/components/emptyNotice/emptyNoticee.jsx b/src/components/emptyNotice/emptyNoticee.jsx new file mode 100644 index 0000000..2c59946 --- /dev/null +++ b/src/components/emptyNotice/emptyNoticee.jsx @@ -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 ( + + + Nothing found + + ); +}; diff --git a/src/components/icons/mdiEmoticonCryOutline.jsx b/src/components/icons/mdiEmoticonCryOutline.jsx new file mode 100644 index 0000000..b2f1d4c --- /dev/null +++ b/src/components/icons/mdiEmoticonCryOutline.jsx @@ -0,0 +1,12 @@ +/** @format */ +import SvgIcon from "@mui/material/SvgIcon"; + +import { mdiEmoticonCryOutline } from "@mdi/js"; + +export const MdiEmoticonCryOutline = (props) => { + return ( + + + + ); +}; diff --git a/src/routes/library/root.jsx b/src/routes/library/root.jsx index 02e1e90..116b3d5 100644 --- a/src/routes/library/root.jsx +++ b/src/routes/library/root.jsx @@ -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

Loading...

; - // } + const handleCurrentViewType = (e) => { + setCurrentViewType(e.target.value); + console.log(e.target.value); + }; + + useEffect(() => { + if (viewType.length != 0) setCurrentViewType(viewType[0].value); + }, [viewType]); return ( { pb: 3, position: "relative", }} - ref={(node) => { - if (node) { - setScrollTarget(node); - } - }} > { > - + {currentLib.isLoading ? ( ) : ( @@ -141,33 +208,80 @@ const LibraryView = () => { ) } /> + + {/* + Age + */} + {viewType.length != 0 && ( + + {viewType.map((item, index) => { + return ( + + {item.title} + + ); + })} + + )} {items.isSuccess && - items.data.Items.map((item, index) => { - return ( - - - - ); - })} + (items.data.TotalRecordCount == 0 ? ( + + ) : ( + items.data.Items.map((item, index) => { + return ( + + + + ); + }) + ))}