Add Sort functions
This commit is contained in:
6 files changed
+220
-59
No files matched your search
@@ -9,6 +9,7 @@ import CardMedia from "@mui/material/CardMedia";
|
||||
import CardActionArea from "@mui/material/CardActionArea";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import LinearProgress from "@mui/material/LinearProgress";
|
||||
import Chip from "@mui/material/Chip";
|
||||
|
||||
import {
|
||||
MediaCollectionTypeIconCollectionCard,
|
||||
@@ -17,6 +18,7 @@ import {
|
||||
|
||||
import { borderRadiusDefault } from "../../palette.module.scss";
|
||||
import "./card.module.scss";
|
||||
import { MdiCheck } from "../icons/mdiCheck";
|
||||
|
||||
export const Card = ({
|
||||
itemName,
|
||||
@@ -29,6 +31,8 @@ export const Card = ({
|
||||
cardOrientation,
|
||||
props,
|
||||
onClickEvent,
|
||||
watchedStatus,
|
||||
watchedCount,
|
||||
}) => {
|
||||
return (
|
||||
<MuiCard
|
||||
@@ -57,6 +61,18 @@ export const Card = ({
|
||||
: "1",
|
||||
}}
|
||||
>
|
||||
{watchedStatus && (
|
||||
<Chip
|
||||
className="card-indicator"
|
||||
label={<MdiCheck />}
|
||||
/>
|
||||
)}
|
||||
{!!watchedCount && (
|
||||
<Chip
|
||||
className="card-indicator card-indicator-text"
|
||||
label={watchedCount}
|
||||
></Chip>
|
||||
)}
|
||||
{imageTags &&
|
||||
(cardType == "thumb" ? (
|
||||
<CardMedia
|
||||
@@ -77,6 +93,8 @@ export const Card = ({
|
||||
"portait"
|
||||
? "0.666"
|
||||
: "1",
|
||||
borderRadius: borderRadiusDefault,
|
||||
overflow: "hidden",
|
||||
}}
|
||||
className="card-image"
|
||||
></CardMedia>
|
||||
@@ -176,4 +194,6 @@ Card.propTypes = {
|
||||
playedPercent: PropTypes.number,
|
||||
cardOrientation: PropTypes.string.isRequired,
|
||||
onClickEvent: PropTypes.func,
|
||||
watchedStatus: PropTypes.bool,
|
||||
watchedCount: PropTypes.number,
|
||||
};
|
||||
@@ -37,4 +37,18 @@
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
&-indicator {
|
||||
position: absolute;
|
||||
right: 5px;
|
||||
top: 5px;
|
||||
// padding: 2px 10px;
|
||||
z-index: 10;
|
||||
// border-radius: 100px;
|
||||
background: $clr-gradient-default;
|
||||
box-shadow: 0 0 5px rgb(0 0 0 / 0.4);
|
||||
&-text {
|
||||
aspect-ratio: 1;
|
||||
padding: 5px !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
/** @format */
|
||||
|
||||
import SvgIcon from "@mui/material/SvgIcon";
|
||||
|
||||
import { mdiCheck } from "@mdi/js";
|
||||
|
||||
export const MdiCheck = (props) => {
|
||||
return (
|
||||
<SvgIcon {...props}>
|
||||
<path d={mdiCheck}></path>
|
||||
</SvgIcon>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
/** @format */
|
||||
import SvgIcon from "@mui/material/SvgIcon";
|
||||
|
||||
import { mdiSortAscending } from "@mdi/js";
|
||||
|
||||
export const MdiSortAscending = (props) => {
|
||||
return (
|
||||
<SvgIcon {...props}>
|
||||
<path d={mdiSortAscending}></path>
|
||||
</SvgIcon>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
/** @format */
|
||||
import SvgIcon from "@mui/material/SvgIcon";
|
||||
|
||||
import { mdiSortDescending } from "@mdi/js";
|
||||
|
||||
export const MdiSortDescending = (props) => {
|
||||
return (
|
||||
<SvgIcon {...props}>
|
||||
<path d={mdiSortDescending}></path>
|
||||
</SvgIcon>
|
||||
);
|
||||
};
|
||||
+149
-59
@@ -12,16 +12,16 @@ 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 Stack from "@mui/material/Stack";
|
||||
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 FormControl from "@mui/material/FormControl";
|
||||
import IconButton from "@mui/material/IconButton";
|
||||
import TextField from "@mui/material/TextField";
|
||||
import Select from "@mui/material/Select";
|
||||
import Checkbox from "@mui/material/Checkbox";
|
||||
import MenuItem from "@mui/material/MenuItem";
|
||||
|
||||
import { theme } from "../../theme";
|
||||
@@ -36,6 +36,8 @@ import { getPersonsApi } from "@jellyfin/sdk/lib/utils/api/persons-api";
|
||||
|
||||
import { Card } from "../../components/card/card";
|
||||
import { EmptyNotice } from "../../components/emptyNotice/emptyNoticee";
|
||||
import { MdiSortDescending } from "../../components/icons/mdiSortDescending";
|
||||
import { MdiSortAscending } from "../../components/icons/mdiSortAscending";
|
||||
|
||||
const LibraryView = () => {
|
||||
const dispatch = useDispatch();
|
||||
@@ -54,6 +56,20 @@ const LibraryView = () => {
|
||||
},
|
||||
});
|
||||
|
||||
const [sortAscending, setSortAscending] = useState(false);
|
||||
const [sortBy, setSortBy] = useState("SortName");
|
||||
const [sortByData, setSortByData] = useState([
|
||||
{ title: "Name", value: "SortName" },
|
||||
{ title: "Rating", value: "CommunityRating" },
|
||||
{ title: "Release Date", value: "PremiereDate" },
|
||||
]);
|
||||
const handleSortChange = (e) => {
|
||||
setSortAscending(e.target.checked);
|
||||
};
|
||||
const handleSortBy = (e) => {
|
||||
setSortBy(e.target.value);
|
||||
};
|
||||
|
||||
const fetchLib = async (libraryId) => {
|
||||
const result = await getItemsApi(window.api).getItems({
|
||||
userId: user.data.Id,
|
||||
@@ -78,26 +94,26 @@ const LibraryView = () => {
|
||||
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" },
|
||||
{ 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" },
|
||||
{ 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" },
|
||||
{ title: "Series", value: "Series" },
|
||||
{ title: "Actors", value: "Person" },
|
||||
{ title: "Genres", value: "Genre" },
|
||||
{ title: "Networks", value: "Studio" },
|
||||
]);
|
||||
} else {
|
||||
setViewType([]);
|
||||
@@ -139,13 +155,20 @@ const LibraryView = () => {
|
||||
parentId: libraryId,
|
||||
recursive: true,
|
||||
includeItemTypes: [currentViewType],
|
||||
sortOrder: [sortAscending ? "Ascending" : "Descending"],
|
||||
sortBy: sortBy,
|
||||
});
|
||||
}
|
||||
return result.data;
|
||||
};
|
||||
|
||||
const items = useQuery({
|
||||
queryKey: ["libraryView", "currentLibItems", id, currentViewType],
|
||||
queryKey: [
|
||||
"libraryView",
|
||||
"currentLibItems",
|
||||
id,
|
||||
`${currentViewType} - ${sortAscending} - ${sortBy}`,
|
||||
],
|
||||
queryFn: () => fetchLibItems(id),
|
||||
enabled: !!user.data,
|
||||
});
|
||||
@@ -154,13 +177,14 @@ const LibraryView = () => {
|
||||
|
||||
const handleCurrentViewType = (e) => {
|
||||
setCurrentViewType(e.target.value);
|
||||
console.log(e.target.value);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (viewType.length != 0) setCurrentViewType(viewType[0].value);
|
||||
}, [viewType]);
|
||||
|
||||
const allowedSortViews = ["Movie", "Series", "MusicAlbum"];
|
||||
|
||||
return (
|
||||
<Box
|
||||
sx={{
|
||||
@@ -187,54 +211,109 @@ const LibraryView = () => {
|
||||
}}
|
||||
>
|
||||
<Divider />
|
||||
<Toolbar>
|
||||
<Typography
|
||||
variant="h5"
|
||||
sx={{ mr: 2, flexShrink: 0 }}
|
||||
noWrap
|
||||
>
|
||||
{currentLib.isLoading ? (
|
||||
<CircularProgress sx={{ p: 1 }} />
|
||||
) : (
|
||||
currentLib.data.Items[0].Name
|
||||
)}
|
||||
</Typography>
|
||||
<Chip
|
||||
label={
|
||||
items.isLoading ? (
|
||||
<Toolbar sx={{ justifyContent: "space-between" }}>
|
||||
<Stack alignItems="center" direction="row">
|
||||
<Typography
|
||||
variant="h5"
|
||||
sx={{ mr: 2, flexShrink: 0 }}
|
||||
noWrap
|
||||
>
|
||||
{currentLib.isLoading ? (
|
||||
<CircularProgress sx={{ p: 1 }} />
|
||||
) : (
|
||||
items.data.TotalRecordCount
|
||||
)
|
||||
}
|
||||
/>
|
||||
currentLib.data.Items[0].Name
|
||||
)}
|
||||
</Typography>
|
||||
<Chip
|
||||
label={
|
||||
items.isLoading ? (
|
||||
<CircularProgress
|
||||
sx={{ p: 1.5 }}
|
||||
/>
|
||||
) : (
|
||||
items.data.TotalRecordCount
|
||||
)
|
||||
}
|
||||
/>
|
||||
</Stack>
|
||||
|
||||
{/* <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>
|
||||
)}
|
||||
<Stack
|
||||
direction="row"
|
||||
spacing={2}
|
||||
divider={
|
||||
<Divider
|
||||
orientation="vertical"
|
||||
flexItem
|
||||
/>
|
||||
}
|
||||
>
|
||||
{allowedSortViews.includes(
|
||||
currentViewType,
|
||||
) && (
|
||||
<>
|
||||
<Checkbox
|
||||
icon={<MdiSortDescending />}
|
||||
checkedIcon={
|
||||
<MdiSortAscending />
|
||||
}
|
||||
color="white"
|
||||
onChange={handleSortChange}
|
||||
defaultValue={sortAscending}
|
||||
/>
|
||||
<TextField
|
||||
select
|
||||
hiddenLabel
|
||||
defaultValue={
|
||||
sortByData[0].value
|
||||
}
|
||||
size="small"
|
||||
variant="filled"
|
||||
onChange={handleSortBy}
|
||||
>
|
||||
{sortByData.map(
|
||||
(item, index) => {
|
||||
return (
|
||||
<MenuItem
|
||||
key={
|
||||
item.value
|
||||
}
|
||||
value={
|
||||
item.value
|
||||
}
|
||||
>
|
||||
{`By ${item.title}`}
|
||||
</MenuItem>
|
||||
);
|
||||
},
|
||||
)}
|
||||
</TextField>
|
||||
</>
|
||||
)}
|
||||
{viewType.length != 0 && (
|
||||
<TextField
|
||||
select
|
||||
hiddenLabel
|
||||
defaultValue={viewType[0].value}
|
||||
size="small"
|
||||
variant="filled"
|
||||
onChange={handleCurrentViewType}
|
||||
>
|
||||
{viewType.map((item, index) => {
|
||||
return (
|
||||
<MenuItem
|
||||
key={item.value}
|
||||
value={item.value}
|
||||
>
|
||||
{item.title}
|
||||
</MenuItem>
|
||||
);
|
||||
})}
|
||||
</TextField>
|
||||
)}
|
||||
</Stack>
|
||||
</Toolbar>
|
||||
</AppBar>
|
||||
<Grid2 container columns={{ xs: 3, sm: 5, md: 8 }}>
|
||||
@@ -277,6 +356,17 @@ const LibraryView = () => {
|
||||
? "square"
|
||||
: "portait"
|
||||
}
|
||||
watchedStatus={
|
||||
!!item.UserData
|
||||
? item.UserData
|
||||
.Played
|
||||
: false
|
||||
}
|
||||
watchedCount={
|
||||
!!item.UserData &&
|
||||
item.UserData
|
||||
.UnplayedItemCount
|
||||
}
|
||||
></Card>
|
||||
</Grid2>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user