feat: add new favorites page
This commit is contained in:
2 files changed
+310
-88
No files matched your search
@@ -0,0 +1,140 @@
|
|||||||
|
@use "@/styles/variables.scss" as *;
|
||||||
|
|
||||||
|
.favorite-page {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
overflow-y: auto;
|
||||||
|
padding-bottom: 2em;
|
||||||
|
|
||||||
|
.favorite-header {
|
||||||
|
padding: 2em 2em 0 2em;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.5em;
|
||||||
|
position: relative;
|
||||||
|
z-index: 2;
|
||||||
|
|
||||||
|
.header-content {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-end;
|
||||||
|
justify-content: space-between;
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 2.2rem;
|
||||||
|
font-weight: 600;
|
||||||
|
margin: 0;
|
||||||
|
color: rgba(255, 255, 255, 0.95);
|
||||||
|
letter-spacing: -0.02em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.MuiTabs-root {
|
||||||
|
min-height: 40px;
|
||||||
|
margin-left: -12px;
|
||||||
|
margin-top: 1em;
|
||||||
|
|
||||||
|
.MuiTabs-indicator {
|
||||||
|
display: none; // Hide default indicator
|
||||||
|
}
|
||||||
|
|
||||||
|
.MuiTabs-scroller {
|
||||||
|
overflow: visible !important; // Allow shadows/glows to show
|
||||||
|
}
|
||||||
|
|
||||||
|
.MuiTab-root {
|
||||||
|
text-transform: none;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
font-weight: 500;
|
||||||
|
color: rgba(255, 255, 255, 0.6);
|
||||||
|
padding: 8px 20px;
|
||||||
|
min-height: 36px;
|
||||||
|
min-width: fit-content;
|
||||||
|
border-radius: 100px;
|
||||||
|
margin-right: 8px;
|
||||||
|
transition: all $transition-time-fast ease;
|
||||||
|
background-color: transparent;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||||
|
|
||||||
|
&:first-of-type {
|
||||||
|
margin-left: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
color: rgba(255, 255, 255, 0.9);
|
||||||
|
background-color: rgba(255, 255, 255, 0.05);
|
||||||
|
border-color: rgba(255, 255, 255, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
&.Mui-selected {
|
||||||
|
color: #fff;
|
||||||
|
font-weight: 600;
|
||||||
|
background-color: $clr-accent-default;
|
||||||
|
border-color: $clr-accent-default;
|
||||||
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.favorite-content {
|
||||||
|
padding: 0.5em 0;
|
||||||
|
flex: 1;
|
||||||
|
|
||||||
|
// For Overview (Scrollers)
|
||||||
|
.overview-section {
|
||||||
|
padding: 0 2em; // Align with header
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1.5em;
|
||||||
|
|
||||||
|
// Override card scroller buttons to fit the new padding
|
||||||
|
.card-scroller-button {
|
||||||
|
width: 2em !important;
|
||||||
|
|
||||||
|
&.left {
|
||||||
|
left: -2em !important;
|
||||||
|
border-radius: 4px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.right {
|
||||||
|
right: -2em !important;
|
||||||
|
border-radius: 4px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.material-symbols-rounded {
|
||||||
|
font-size: 2em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// For Grid Views
|
||||||
|
.grid-section {
|
||||||
|
padding: 1em 2em;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
|
||||||
|
gap: 1em;
|
||||||
|
|
||||||
|
// Adjust for different card types if needed
|
||||||
|
&.grid-landscape {
|
||||||
|
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-state {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
height: 300px;
|
||||||
|
color: rgba(255, 255, 255, 0.4);
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
margin-top: 1em;
|
||||||
|
font-weight: 400;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +1,19 @@
|
|||||||
import React, { useEffect } from "react";
|
|
||||||
|
|
||||||
import { useBackdropStore } from "@/utils/store/backdrop";
|
|
||||||
|
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import React, { type SyntheticEvent, useEffect, useState } from "react";
|
||||||
|
import { useBackdropStore } from "@/utils/store/backdrop";
|
||||||
import "./favorite.scss";
|
import "./favorite.scss";
|
||||||
|
|
||||||
|
import {
|
||||||
|
type BaseItemDto,
|
||||||
|
BaseItemKind,
|
||||||
|
} from "@jellyfin/sdk/lib/generated-client";
|
||||||
|
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api";
|
||||||
|
import { Fade, Tab, Tabs, Typography } from "@mui/material";
|
||||||
|
import { createFileRoute } from "@tanstack/react-router";
|
||||||
|
import { useShallow } from "zustand/react/shallow";
|
||||||
import { Card } from "@/components/card/card";
|
import { Card } from "@/components/card/card";
|
||||||
import CardScroller from "@/components/cardScroller/cardScroller";
|
import CardScroller from "@/components/cardScroller/cardScroller";
|
||||||
import { useCentralStore } from "@/utils/store/central";
|
import { useCentralStore } from "@/utils/store/central";
|
||||||
import { BaseItemKind } from "@jellyfin/sdk/lib/generated-client";
|
|
||||||
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api";
|
|
||||||
import { createFileRoute } from "@tanstack/react-router";
|
|
||||||
|
|
||||||
export const Route = createFileRoute("/_api/favorite/")({
|
export const Route = createFileRoute("/_api/favorite/")({
|
||||||
component: FavoritePage,
|
component: FavoritePage,
|
||||||
@@ -18,7 +21,10 @@ export const Route = createFileRoute("/_api/favorite/")({
|
|||||||
|
|
||||||
function FavoritePage() {
|
function FavoritePage() {
|
||||||
const api = Route.useRouteContext().api;
|
const api = Route.useRouteContext().api;
|
||||||
const [setBackdrop] = useBackdropStore((state) => [state.setBackdrop]);
|
const [setBackdrop] = useBackdropStore(
|
||||||
|
useShallow((state) => [state.setBackdrop]),
|
||||||
|
);
|
||||||
|
const [tabValue, setTabValue] = useState("overview");
|
||||||
|
|
||||||
const user = useCentralStore((s) => s.currentUser);
|
const user = useCentralStore((s) => s.currentUser);
|
||||||
|
|
||||||
@@ -30,6 +36,7 @@ function FavoritePage() {
|
|||||||
userId: user?.Id,
|
userId: user?.Id,
|
||||||
isFavorite: true,
|
isFavorite: true,
|
||||||
includeItemTypes: [BaseItemKind.Movie],
|
includeItemTypes: [BaseItemKind.Movie],
|
||||||
|
enableImages: true,
|
||||||
recursive: true,
|
recursive: true,
|
||||||
});
|
});
|
||||||
return result.data;
|
return result.data;
|
||||||
@@ -121,23 +128,33 @@ function FavoritePage() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setBackdrop("", "");
|
// Set a backdrop from one of the favorites if available?
|
||||||
});
|
// For now, clear it or maybe pick random from movies
|
||||||
|
if (movies.data?.Items && movies.data.Items.length > 0) {
|
||||||
|
const randomMovie =
|
||||||
|
movies.data.Items[Math.floor(Math.random() * movies.data.Items.length)];
|
||||||
|
if (randomMovie.BackdropImageTags?.[0]) {
|
||||||
|
setBackdrop(
|
||||||
|
randomMovie.ImageBlurHashes?.Backdrop?.[
|
||||||
|
randomMovie.BackdropImageTags[0]
|
||||||
|
] || "",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setBackdrop("");
|
||||||
|
}
|
||||||
|
}, [movies.data, setBackdrop]);
|
||||||
|
|
||||||
return (
|
const handleTabChange = (_event: SyntheticEvent, newValue: string) => {
|
||||||
<div
|
setTabValue(newValue);
|
||||||
className="scrollY"
|
};
|
||||||
style={{
|
|
||||||
display: "flex",
|
const sections = [
|
||||||
flexDirection: "column",
|
{
|
||||||
gap: "0.5em",
|
id: "movies",
|
||||||
paddingBottom: "2em",
|
title: "Movies",
|
||||||
paddingTop: "4.2em",
|
query: movies,
|
||||||
}}
|
renderCard: (item: BaseItemDto) => (
|
||||||
>
|
|
||||||
{movies.isSuccess && (movies.data?.Items?.length ?? 0) > 0 && (
|
|
||||||
<CardScroller displayCards={8} title="Movies">
|
|
||||||
{movies.data?.Items?.map((item) => (
|
|
||||||
<Card
|
<Card
|
||||||
key={item.Id}
|
key={item.Id}
|
||||||
item={item}
|
item={item}
|
||||||
@@ -148,50 +165,30 @@ function FavoritePage() {
|
|||||||
queryKey={["favorite", "movies"]}
|
queryKey={["favorite", "movies"]}
|
||||||
userId={user?.Id}
|
userId={user?.Id}
|
||||||
/>
|
/>
|
||||||
))}
|
),
|
||||||
</CardScroller>
|
},
|
||||||
)}
|
{
|
||||||
{series.isSuccess && (series.data?.Items?.length ?? 0) > 0 && (
|
id: "series",
|
||||||
<CardScroller title="TV Shows" displayCards={8} disableDecoration>
|
title: "TV Shows",
|
||||||
{series.data?.Items?.map((item) => (
|
query: series,
|
||||||
|
renderCard: (item: BaseItemDto) => (
|
||||||
<Card
|
<Card
|
||||||
key={item.Id}
|
key={item.Id}
|
||||||
item={item}
|
item={item}
|
||||||
cardTitle={item.Name}
|
cardTitle={item.Name}
|
||||||
imageType={"Primary"}
|
imageType={"Primary"}
|
||||||
cardCaption={`${item.ProductionYear} - ${
|
cardCaption={`${item.ProductionYear} - ${item.EndDate ? new Date(item.EndDate).getFullYear() : "Present"}`}
|
||||||
item.EndDate
|
|
||||||
? new Date(item.EndDate).toLocaleString([], {
|
|
||||||
year: "numeric",
|
|
||||||
})
|
|
||||||
: "Present"
|
|
||||||
}`}
|
|
||||||
cardType="portrait"
|
cardType="portrait"
|
||||||
queryKey={["favorite", "series"]}
|
queryKey={["favorite", "series"]}
|
||||||
userId={user?.Id}
|
userId={user?.Id}
|
||||||
/>
|
/>
|
||||||
))}
|
),
|
||||||
</CardScroller>
|
},
|
||||||
)}
|
{
|
||||||
{audio.isSuccess && (audio.data?.Items?.length ?? 0) > 0 && (
|
id: "albums",
|
||||||
<CardScroller title="Audio" displayCards={8} disableDecoration>
|
title: "Albums",
|
||||||
{audio.data?.Items?.map((item) => (
|
query: musicAlbum,
|
||||||
<Card
|
renderCard: (item: BaseItemDto) => (
|
||||||
key={item.Id}
|
|
||||||
item={item}
|
|
||||||
cardTitle={item.Name}
|
|
||||||
imageType={"Primary"}
|
|
||||||
cardCaption={item.ProductionYear}
|
|
||||||
cardType="square"
|
|
||||||
queryKey={["favorite", "audio"]}
|
|
||||||
userId={user?.Id}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</CardScroller>
|
|
||||||
)}
|
|
||||||
{musicAlbum.isSuccess && (musicAlbum.data?.Items?.length ?? 0) > 0 && (
|
|
||||||
<CardScroller title="Albums" displayCards={8} disableDecoration>
|
|
||||||
{musicAlbum.data?.Items?.map((item) => (
|
|
||||||
<Card
|
<Card
|
||||||
key={item.Id}
|
key={item.Id}
|
||||||
item={item}
|
item={item}
|
||||||
@@ -203,12 +200,47 @@ function FavoritePage() {
|
|||||||
queryKey={["favorite", "musicAlbum"]}
|
queryKey={["favorite", "musicAlbum"]}
|
||||||
userId={user?.Id}
|
userId={user?.Id}
|
||||||
/>
|
/>
|
||||||
))}
|
),
|
||||||
</CardScroller>
|
},
|
||||||
)}
|
{
|
||||||
{book.isSuccess && (book.data?.Items?.length ?? 0) > 0 && (
|
id: "artists",
|
||||||
<CardScroller title="Books" displayCards={8} disableDecoration>
|
title: "Artists",
|
||||||
{book.data?.Items?.map((item) => (
|
query: musicArtists,
|
||||||
|
renderCard: (item: BaseItemDto) => (
|
||||||
|
<Card
|
||||||
|
key={item.Id}
|
||||||
|
item={item}
|
||||||
|
cardTitle={item.Name}
|
||||||
|
imageType={"Primary"}
|
||||||
|
disableOverlay
|
||||||
|
cardType={"square"}
|
||||||
|
queryKey={["favorite", "musicArtist"]}
|
||||||
|
userId={user?.Id}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "audio",
|
||||||
|
title: "Songs",
|
||||||
|
query: audio,
|
||||||
|
renderCard: (item: BaseItemDto) => (
|
||||||
|
<Card
|
||||||
|
key={item.Id}
|
||||||
|
item={item}
|
||||||
|
cardTitle={item.Name}
|
||||||
|
imageType={"Primary"}
|
||||||
|
cardCaption={item.ProductionYear}
|
||||||
|
cardType="square"
|
||||||
|
queryKey={["favorite", "audio"]}
|
||||||
|
userId={user?.Id}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "books",
|
||||||
|
title: "Books",
|
||||||
|
query: book,
|
||||||
|
renderCard: (item: BaseItemDto) => (
|
||||||
<Card
|
<Card
|
||||||
key={item.Id}
|
key={item.Id}
|
||||||
item={item}
|
item={item}
|
||||||
@@ -220,29 +252,13 @@ function FavoritePage() {
|
|||||||
queryKey={["favorite", "book"]}
|
queryKey={["favorite", "book"]}
|
||||||
userId={user?.Id}
|
userId={user?.Id}
|
||||||
/>
|
/>
|
||||||
))}
|
),
|
||||||
</CardScroller>
|
},
|
||||||
)}
|
{
|
||||||
{musicArtists.isSuccess &&
|
id: "person",
|
||||||
(musicArtists.data?.Items?.length ?? 0) > 0 && (
|
title: "People",
|
||||||
<CardScroller title="Artists" displayCards={8} disableDecoration>
|
query: person,
|
||||||
{musicArtists.data?.Items?.map((item) => (
|
renderCard: (item: BaseItemDto) => (
|
||||||
<Card
|
|
||||||
key={item.Id}
|
|
||||||
item={item}
|
|
||||||
cardTitle={item.Name}
|
|
||||||
imageType={"Primary"}
|
|
||||||
disableOverlay
|
|
||||||
cardType={"square"}
|
|
||||||
queryKey={["favorite", "musicArtist"]}
|
|
||||||
userId={user?.Id}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</CardScroller>
|
|
||||||
)}
|
|
||||||
{person.isSuccess && (person.data?.Items?.length ?? 0) > 0 && (
|
|
||||||
<CardScroller title="People" displayCards={8} disableDecoration>
|
|
||||||
{person.data?.Items?.map((item) => (
|
|
||||||
<Card
|
<Card
|
||||||
key={item.Id}
|
key={item.Id}
|
||||||
item={item}
|
item={item}
|
||||||
@@ -253,10 +269,76 @@ function FavoritePage() {
|
|||||||
queryKey={["favorite", "person"]}
|
queryKey={["favorite", "person"]}
|
||||||
userId={user?.Id}
|
userId={user?.Id}
|
||||||
/>
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const availableSections = sections.filter(
|
||||||
|
(s) => s.query.isSuccess && (s.query.data?.Items?.length ?? 0) > 0,
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="favorite-page scrollY">
|
||||||
|
<div className="favorite-header">
|
||||||
|
<div className="header-content">
|
||||||
|
<Typography variant="h1" component="h1">
|
||||||
|
Your Favorites
|
||||||
|
</Typography>
|
||||||
|
</div>
|
||||||
|
<Tabs
|
||||||
|
value={tabValue}
|
||||||
|
onChange={handleTabChange}
|
||||||
|
variant="scrollable"
|
||||||
|
scrollButtons="auto"
|
||||||
|
aria-label="favorite sections"
|
||||||
|
>
|
||||||
|
<Tab label="Overview" value="overview" />
|
||||||
|
{availableSections.map((section) => (
|
||||||
|
<Tab key={section.id} label={section.title} value={section.id} />
|
||||||
))}
|
))}
|
||||||
|
</Tabs>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="favorite-content">
|
||||||
|
{tabValue === "overview" && (
|
||||||
|
<Fade in={tabValue === "overview"}>
|
||||||
|
<div className="overview-section">
|
||||||
|
{availableSections.map((section) => (
|
||||||
|
<CardScroller
|
||||||
|
key={section.id}
|
||||||
|
title={section.title}
|
||||||
|
displayCards={7}
|
||||||
|
disableDecoration
|
||||||
|
>
|
||||||
|
{section.query.data?.Items?.map(section.renderCard)}
|
||||||
</CardScroller>
|
</CardScroller>
|
||||||
|
))}
|
||||||
|
{availableSections.length === 0 && (
|
||||||
|
<div className="empty-state">
|
||||||
|
<Typography variant="h5">No favorites yet</Typography>
|
||||||
|
<Typography variant="body1">
|
||||||
|
Mark items as favorite to see them here.
|
||||||
|
</Typography>
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
</Fade>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{availableSections.map(
|
||||||
|
(section) =>
|
||||||
|
tabValue === section.id && (
|
||||||
|
<Fade key={section.id} in={tabValue === section.id}>
|
||||||
|
<div
|
||||||
|
className={`grid-section ${["movies", "series", "books"].includes(section.id) ? "grid-landscape" : ""}`}
|
||||||
|
>
|
||||||
|
{section.query.data?.Items?.map(section.renderCard)}
|
||||||
|
</div>
|
||||||
|
</Fade>
|
||||||
|
),
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user