Add Sort functions
This commit is contained in:
6 files changed
+182
-21
No files matched your search
@@ -9,6 +9,7 @@ import CardMedia from "@mui/material/CardMedia";
|
|||||||
import CardActionArea from "@mui/material/CardActionArea";
|
import CardActionArea from "@mui/material/CardActionArea";
|
||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
import LinearProgress from "@mui/material/LinearProgress";
|
import LinearProgress from "@mui/material/LinearProgress";
|
||||||
|
import Chip from "@mui/material/Chip";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
MediaCollectionTypeIconCollectionCard,
|
MediaCollectionTypeIconCollectionCard,
|
||||||
@@ -17,6 +18,7 @@ import {
|
|||||||
|
|
||||||
import { borderRadiusDefault } from "../../palette.module.scss";
|
import { borderRadiusDefault } from "../../palette.module.scss";
|
||||||
import "./card.module.scss";
|
import "./card.module.scss";
|
||||||
|
import { MdiCheck } from "../icons/mdiCheck";
|
||||||
|
|
||||||
export const Card = ({
|
export const Card = ({
|
||||||
itemName,
|
itemName,
|
||||||
@@ -29,6 +31,8 @@ export const Card = ({
|
|||||||
cardOrientation,
|
cardOrientation,
|
||||||
props,
|
props,
|
||||||
onClickEvent,
|
onClickEvent,
|
||||||
|
watchedStatus,
|
||||||
|
watchedCount,
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<MuiCard
|
<MuiCard
|
||||||
@@ -57,6 +61,18 @@ export const Card = ({
|
|||||||
: "1",
|
: "1",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
{watchedStatus && (
|
||||||
|
<Chip
|
||||||
|
className="card-indicator"
|
||||||
|
label={<MdiCheck />}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{!!watchedCount && (
|
||||||
|
<Chip
|
||||||
|
className="card-indicator card-indicator-text"
|
||||||
|
label={watchedCount}
|
||||||
|
></Chip>
|
||||||
|
)}
|
||||||
{imageTags &&
|
{imageTags &&
|
||||||
(cardType == "thumb" ? (
|
(cardType == "thumb" ? (
|
||||||
<CardMedia
|
<CardMedia
|
||||||
@@ -77,6 +93,8 @@ export const Card = ({
|
|||||||
"portait"
|
"portait"
|
||||||
? "0.666"
|
? "0.666"
|
||||||
: "1",
|
: "1",
|
||||||
|
borderRadius: borderRadiusDefault,
|
||||||
|
overflow: "hidden",
|
||||||
}}
|
}}
|
||||||
className="card-image"
|
className="card-image"
|
||||||
></CardMedia>
|
></CardMedia>
|
||||||
@@ -176,4 +194,6 @@ Card.propTypes = {
|
|||||||
playedPercent: PropTypes.number,
|
playedPercent: PropTypes.number,
|
||||||
cardOrientation: PropTypes.string.isRequired,
|
cardOrientation: PropTypes.string.isRequired,
|
||||||
onClickEvent: PropTypes.func,
|
onClickEvent: PropTypes.func,
|
||||||
|
watchedStatus: PropTypes.bool,
|
||||||
|
watchedCount: PropTypes.number,
|
||||||
};
|
};
|
||||||
@@ -37,4 +37,18 @@
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: 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>
|
||||||
|
);
|
||||||
|
};
|
||||||
+111
-21
@@ -12,16 +12,16 @@ import { useQuery } from "@tanstack/react-query";
|
|||||||
|
|
||||||
import Box from "@mui/material/Box";
|
import Box from "@mui/material/Box";
|
||||||
import Grid2 from "@mui/material/Unstable_Grid2";
|
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 AppBar from "@mui/material/AppBar";
|
||||||
import Toolbar from "@mui/material/Toolbar";
|
import Toolbar from "@mui/material/Toolbar";
|
||||||
import Typography from "@mui/material/Typography";
|
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 IconButton from "@mui/material/IconButton";
|
||||||
import TextField from "@mui/material/TextField";
|
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 MenuItem from "@mui/material/MenuItem";
|
||||||
|
|
||||||
import { theme } from "../../theme";
|
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 { Card } from "../../components/card/card";
|
||||||
import { EmptyNotice } from "../../components/emptyNotice/emptyNoticee";
|
import { EmptyNotice } from "../../components/emptyNotice/emptyNoticee";
|
||||||
|
import { MdiSortDescending } from "../../components/icons/mdiSortDescending";
|
||||||
|
import { MdiSortAscending } from "../../components/icons/mdiSortAscending";
|
||||||
|
|
||||||
const LibraryView = () => {
|
const LibraryView = () => {
|
||||||
const dispatch = useDispatch();
|
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 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,
|
||||||
@@ -78,26 +94,26 @@ const LibraryView = () => {
|
|||||||
if (currentLib.isSuccess) {
|
if (currentLib.isSuccess) {
|
||||||
if (currentLib.data.Items[0].CollectionType == "movies") {
|
if (currentLib.data.Items[0].CollectionType == "movies") {
|
||||||
setViewType([
|
setViewType([
|
||||||
{ title: "movies", value: "Movie" },
|
{ title: "Movies", value: "Movie" },
|
||||||
{ title: "collections", value: "BoxSet" },
|
{ title: "Collections", value: "BoxSet" },
|
||||||
{ title: "actors", value: "Person" },
|
{ title: "Actors", value: "Person" },
|
||||||
{ title: "genres", value: "Genre" },
|
{ title: "Genres", value: "Genre" },
|
||||||
{ title: "studios", value: "Studio" },
|
{ title: "Studios", value: "Studio" },
|
||||||
]);
|
]);
|
||||||
} else if (currentLib.data.Items[0].CollectionType == "music") {
|
} else if (currentLib.data.Items[0].CollectionType == "music") {
|
||||||
setViewType([
|
setViewType([
|
||||||
{ title: "albums", value: "MusicAlbum" },
|
{ title: "Albums", value: "MusicAlbum" },
|
||||||
{ title: "artists", value: "MusicArtist" },
|
{ title: "Artists", value: "MusicArtist" },
|
||||||
{ title: "genres", value: "MusicGenre" },
|
{ title: "Genres", value: "MusicGenre" },
|
||||||
]);
|
]);
|
||||||
} else if (
|
} else if (
|
||||||
currentLib.data.Items[0].CollectionType == "tvshows"
|
currentLib.data.Items[0].CollectionType == "tvshows"
|
||||||
) {
|
) {
|
||||||
setViewType([
|
setViewType([
|
||||||
{ title: "series", value: "Series" },
|
{ title: "Series", value: "Series" },
|
||||||
{ title: "actors", value: "Person" },
|
{ title: "Actors", value: "Person" },
|
||||||
{ title: "genres", value: "Genre" },
|
{ title: "Genres", value: "Genre" },
|
||||||
{ title: "networks", value: "Studio" },
|
{ title: "Networks", value: "Studio" },
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
setViewType([]);
|
setViewType([]);
|
||||||
@@ -139,13 +155,20 @@ const LibraryView = () => {
|
|||||||
parentId: libraryId,
|
parentId: libraryId,
|
||||||
recursive: true,
|
recursive: true,
|
||||||
includeItemTypes: [currentViewType],
|
includeItemTypes: [currentViewType],
|
||||||
|
sortOrder: [sortAscending ? "Ascending" : "Descending"],
|
||||||
|
sortBy: sortBy,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return result.data;
|
return result.data;
|
||||||
};
|
};
|
||||||
|
|
||||||
const items = useQuery({
|
const items = useQuery({
|
||||||
queryKey: ["libraryView", "currentLibItems", id, currentViewType],
|
queryKey: [
|
||||||
|
"libraryView",
|
||||||
|
"currentLibItems",
|
||||||
|
id,
|
||||||
|
`${currentViewType} - ${sortAscending} - ${sortBy}`,
|
||||||
|
],
|
||||||
queryFn: () => fetchLibItems(id),
|
queryFn: () => fetchLibItems(id),
|
||||||
enabled: !!user.data,
|
enabled: !!user.data,
|
||||||
});
|
});
|
||||||
@@ -154,13 +177,14 @@ const LibraryView = () => {
|
|||||||
|
|
||||||
const handleCurrentViewType = (e) => {
|
const handleCurrentViewType = (e) => {
|
||||||
setCurrentViewType(e.target.value);
|
setCurrentViewType(e.target.value);
|
||||||
console.log(e.target.value);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (viewType.length != 0) setCurrentViewType(viewType[0].value);
|
if (viewType.length != 0) setCurrentViewType(viewType[0].value);
|
||||||
}, [viewType]);
|
}, [viewType]);
|
||||||
|
|
||||||
|
const allowedSortViews = ["Movie", "Series", "MusicAlbum"];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
@@ -187,7 +211,8 @@ const LibraryView = () => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Divider />
|
<Divider />
|
||||||
<Toolbar>
|
<Toolbar sx={{ justifyContent: "space-between" }}>
|
||||||
|
<Stack alignItems="center" direction="row">
|
||||||
<Typography
|
<Typography
|
||||||
variant="h5"
|
variant="h5"
|
||||||
sx={{ mr: 2, flexShrink: 0 }}
|
sx={{ mr: 2, flexShrink: 0 }}
|
||||||
@@ -202,16 +227,71 @@ const LibraryView = () => {
|
|||||||
<Chip
|
<Chip
|
||||||
label={
|
label={
|
||||||
items.isLoading ? (
|
items.isLoading ? (
|
||||||
<CircularProgress sx={{ p: 1 }} />
|
<CircularProgress
|
||||||
|
sx={{ p: 1.5 }}
|
||||||
|
/>
|
||||||
) : (
|
) : (
|
||||||
items.data.TotalRecordCount
|
items.data.TotalRecordCount
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
</Stack>
|
||||||
|
|
||||||
{/* <InputLabel id="demo-simple-select-label">
|
{/* <InputLabel id="demo-simple-select-label">
|
||||||
Age
|
Age
|
||||||
</InputLabel> */}
|
</InputLabel> */}
|
||||||
|
<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 && (
|
{viewType.length != 0 && (
|
||||||
<TextField
|
<TextField
|
||||||
select
|
select
|
||||||
@@ -219,8 +299,6 @@ const LibraryView = () => {
|
|||||||
defaultValue={viewType[0].value}
|
defaultValue={viewType[0].value}
|
||||||
size="small"
|
size="small"
|
||||||
variant="filled"
|
variant="filled"
|
||||||
fullWidth
|
|
||||||
sx={{ ml: "75%" }}
|
|
||||||
onChange={handleCurrentViewType}
|
onChange={handleCurrentViewType}
|
||||||
>
|
>
|
||||||
{viewType.map((item, index) => {
|
{viewType.map((item, index) => {
|
||||||
@@ -235,6 +313,7 @@ const LibraryView = () => {
|
|||||||
})}
|
})}
|
||||||
</TextField>
|
</TextField>
|
||||||
)}
|
)}
|
||||||
|
</Stack>
|
||||||
</Toolbar>
|
</Toolbar>
|
||||||
</AppBar>
|
</AppBar>
|
||||||
<Grid2 container columns={{ xs: 3, sm: 5, md: 8 }}>
|
<Grid2 container columns={{ xs: 3, sm: 5, md: 8 }}>
|
||||||
@@ -277,6 +356,17 @@ const LibraryView = () => {
|
|||||||
? "square"
|
? "square"
|
||||||
: "portait"
|
: "portait"
|
||||||
}
|
}
|
||||||
|
watchedStatus={
|
||||||
|
!!item.UserData
|
||||||
|
? item.UserData
|
||||||
|
.Played
|
||||||
|
: false
|
||||||
|
}
|
||||||
|
watchedCount={
|
||||||
|
!!item.UserData &&
|
||||||
|
item.UserData
|
||||||
|
.UnplayedItemCount
|
||||||
|
}
|
||||||
></Card>
|
></Card>
|
||||||
</Grid2>
|
</Grid2>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in new issue
Block a user