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 CircularProgress from "@mui/material/CircularProgress";
|
||||||
import Divider from "@mui/material/Divider";
|
import Divider from "@mui/material/Divider";
|
||||||
import Chip from "@mui/material/Chip";
|
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 { 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";
|
||||||
|
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 { Card } from "../../components/card/card";
|
||||||
|
import { EmptyNotice } from "../../components/emptyNotice/emptyNoticee";
|
||||||
|
|
||||||
const LibraryView = () => {
|
const LibraryView = () => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
@@ -35,13 +45,6 @@ const LibraryView = () => {
|
|||||||
dispatch(showAppBar());
|
dispatch(showAppBar());
|
||||||
}
|
}
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
const [scrollTarget, setScrollTarget] = useState(undefined);
|
|
||||||
|
|
||||||
const trigger = useScrollTrigger({
|
|
||||||
disableHysteresis: true,
|
|
||||||
threshold: 0,
|
|
||||||
target: scrollTarget,
|
|
||||||
});
|
|
||||||
|
|
||||||
const user = useQuery({
|
const user = useQuery({
|
||||||
queryKey: ["libraryView", "user"],
|
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 fetchLib = async (libraryId) => {
|
||||||
const result = await getItemsApi(window.api).getItems({
|
const result = await getItemsApi(window.api).getItems({
|
||||||
userId: user.data.Id,
|
userId: user.data.Id,
|
||||||
@@ -67,7 +61,6 @@ const LibraryView = () => {
|
|||||||
});
|
});
|
||||||
return result.data;
|
return result.data;
|
||||||
};
|
};
|
||||||
|
|
||||||
const currentLib = useQuery({
|
const currentLib = useQuery({
|
||||||
queryKey: ["libraryView", "currentLib", id],
|
queryKey: ["libraryView", "currentLib", id],
|
||||||
queryFn: () => fetchLib(id),
|
queryFn: () => fetchLib(id),
|
||||||
@@ -79,19 +72,94 @@ const LibraryView = () => {
|
|||||||
dispatch(showBackButton());
|
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({
|
const items = useQuery({
|
||||||
queryKey: ["libraryView", "currentLibItems", id],
|
queryKey: ["libraryView", "currentLibItems", id, currentViewType],
|
||||||
queryFn: () => fetchLibItems(id),
|
queryFn: () => fetchLibItems(id),
|
||||||
enabled: !!user.data,
|
enabled: !!user.data,
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
dispatch(setBackdrop(true));
|
||||||
dispatch(setBackdrop(true));
|
|
||||||
}, [trigger]);
|
|
||||||
|
|
||||||
// if (currentLib.isLoading || items.isLoading) {
|
const handleCurrentViewType = (e) => {
|
||||||
// return <h1>Loading...</h1>;
|
setCurrentViewType(e.target.value);
|
||||||
// }
|
console.log(e.target.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (viewType.length != 0) setCurrentViewType(viewType[0].value);
|
||||||
|
}, [viewType]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
@@ -109,11 +177,6 @@ const LibraryView = () => {
|
|||||||
pb: 3,
|
pb: 3,
|
||||||
position: "relative",
|
position: "relative",
|
||||||
}}
|
}}
|
||||||
ref={(node) => {
|
|
||||||
if (node) {
|
|
||||||
setScrollTarget(node);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<AppBar
|
<AppBar
|
||||||
position="fixed"
|
position="fixed"
|
||||||
@@ -125,7 +188,11 @@ const LibraryView = () => {
|
|||||||
>
|
>
|
||||||
<Divider />
|
<Divider />
|
||||||
<Toolbar>
|
<Toolbar>
|
||||||
<Typography variant="h5" sx={{ mr: 2 }}>
|
<Typography
|
||||||
|
variant="h5"
|
||||||
|
sx={{ mr: 2, flexShrink: 0 }}
|
||||||
|
noWrap
|
||||||
|
>
|
||||||
{currentLib.isLoading ? (
|
{currentLib.isLoading ? (
|
||||||
<CircularProgress sx={{ p: 1 }} />
|
<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>
|
</Toolbar>
|
||||||
</AppBar>
|
</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.TotalRecordCount == 0 ? (
|
||||||
return (
|
<EmptyNotice />
|
||||||
<Grid2 key={index} xs={1} sm={1} md={1}>
|
) : (
|
||||||
<Card
|
items.data.Items.map((item, index) => {
|
||||||
itemName={item.Name}
|
return (
|
||||||
itemId={item.Id}
|
<Grid2
|
||||||
imageTags={!!item.ImageTags}
|
key={index}
|
||||||
subText={item.ProductionYear}
|
xs={1}
|
||||||
iconType={item.Type}
|
sm={1}
|
||||||
playedPercent={
|
md={1}
|
||||||
item.UserData
|
>
|
||||||
.PlayedPercentage
|
<Card
|
||||||
}
|
itemName={item.Name}
|
||||||
cardOrientation={
|
itemId={item.Id}
|
||||||
item.Type ==
|
imageTags={
|
||||||
"MusicArtist"
|
!!item.ImageTags
|
||||||
? "square"
|
.Primary
|
||||||
: "portait"
|
}
|
||||||
}
|
subText={
|
||||||
></Card>
|
item.ProductionYear
|
||||||
</Grid2>
|
}
|
||||||
);
|
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>
|
</Grid2>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
Reference in new issue
Block a user