feat: add new favorites page

This commit is contained in:
--remove-section committed 2026-01-27 21:02:02 +05:30
1 parent 72ca2fb4f3
commit 0131a23dc2
2 files changed
+362 -140

No files matched your search

+140
View File
@@ -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;
}
}
}
}
+222 -140
View File
@@ -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 { Card } from "@/components/card/card"; import {
import CardScroller from "@/components/cardScroller/cardScroller"; type BaseItemDto,
import { useCentralStore } from "@/utils/store/central"; BaseItemKind,
import { BaseItemKind } from "@jellyfin/sdk/lib/generated-client"; } from "@jellyfin/sdk/lib/generated-client";
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api"; 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 { createFileRoute } from "@tanstack/react-router";
import { useShallow } from "zustand/react/shallow";
import { Card } from "@/components/card/card";
import CardScroller from "@/components/cardScroller/cardScroller";
import { useCentralStore } from "@/utils/store/central";
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,141 +128,216 @@ 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]);
const handleTabChange = (_event: SyntheticEvent, newValue: string) => {
setTabValue(newValue);
};
const sections = [
{
id: "movies",
title: "Movies",
query: movies,
renderCard: (item: BaseItemDto) => (
<Card
key={item.Id}
item={item}
cardTitle={item.Name}
imageType={"Primary"}
cardCaption={item.ProductionYear}
cardType="portrait"
queryKey={["favorite", "movies"]}
userId={user?.Id}
/>
),
},
{
id: "series",
title: "TV Shows",
query: series,
renderCard: (item: BaseItemDto) => (
<Card
key={item.Id}
item={item}
cardTitle={item.Name}
imageType={"Primary"}
cardCaption={`${item.ProductionYear} - ${item.EndDate ? new Date(item.EndDate).getFullYear() : "Present"}`}
cardType="portrait"
queryKey={["favorite", "series"]}
userId={user?.Id}
/>
),
},
{
id: "albums",
title: "Albums",
query: musicAlbum,
renderCard: (item: BaseItemDto) => (
<Card
key={item.Id}
item={item}
seriesId={item.SeriesId}
cardTitle={item.Name}
imageType={"Primary"}
cardCaption={item.AlbumArtist}
cardType={"square"}
queryKey={["favorite", "musicAlbum"]}
userId={user?.Id}
/>
),
},
{
id: "artists",
title: "Artists",
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
key={item.Id}
item={item}
cardTitle={item.Name}
imageType={"Primary"}
cardCaption={item.ProductionYear}
disableOverlay
cardType={"portrait"}
queryKey={["favorite", "book"]}
userId={user?.Id}
/>
),
},
{
id: "person",
title: "People",
query: person,
renderCard: (item: BaseItemDto) => (
<Card
key={item.Id}
item={item}
cardTitle={item.Name}
imageType={"Primary"}
disableOverlay
cardType={"square"}
queryKey={["favorite", "person"]}
userId={user?.Id}
/>
),
},
];
const availableSections = sections.filter(
(s) => s.query.isSuccess && (s.query.data?.Items?.length ?? 0) > 0,
);
return ( return (
<div <div className="favorite-page scrollY">
className="scrollY" <div className="favorite-header">
style={{ <div className="header-content">
display: "flex", <Typography variant="h1" component="h1">
flexDirection: "column", Your Favorites
gap: "0.5em", </Typography>
paddingBottom: "2em", </div>
paddingTop: "4.2em", <Tabs
}} value={tabValue}
> onChange={handleTabChange}
{movies.isSuccess && (movies.data?.Items?.length ?? 0) > 0 && ( variant="scrollable"
<CardScroller displayCards={8} title="Movies"> scrollButtons="auto"
{movies.data?.Items?.map((item) => ( aria-label="favorite sections"
<Card >
key={item.Id} <Tab label="Overview" value="overview" />
item={item} {availableSections.map((section) => (
cardTitle={item.Name} <Tab key={section.id} label={section.title} value={section.id} />
imageType={"Primary"}
cardCaption={item.ProductionYear}
cardType="portrait"
queryKey={["favorite", "movies"]}
userId={user?.Id}
/>
))} ))}
</CardScroller> </Tabs>
)} </div>
{series.isSuccess && (series.data?.Items?.length ?? 0) > 0 && (
<CardScroller title="TV Shows" displayCards={8} disableDecoration> <div className="favorite-content">
{series.data?.Items?.map((item) => ( {tabValue === "overview" && (
<Card <Fade in={tabValue === "overview"}>
key={item.Id} <div className="overview-section">
item={item} {availableSections.map((section) => (
cardTitle={item.Name} <CardScroller
imageType={"Primary"} key={section.id}
cardCaption={`${item.ProductionYear} - ${ title={section.title}
item.EndDate displayCards={7}
? new Date(item.EndDate).toLocaleString([], { disableDecoration
year: "numeric", >
}) {section.query.data?.Items?.map(section.renderCard)}
: "Present" </CardScroller>
}`} ))}
cardType="portrait" {availableSections.length === 0 && (
queryKey={["favorite", "series"]} <div className="empty-state">
userId={user?.Id} <Typography variant="h5">No favorites yet</Typography>
/> <Typography variant="body1">
))} Mark items as favorite to see them here.
</CardScroller> </Typography>
)} </div>
{audio.isSuccess && (audio.data?.Items?.length ?? 0) > 0 && ( )}
<CardScroller title="Audio" displayCards={8} disableDecoration> </div>
{audio.data?.Items?.map((item) => ( </Fade>
<Card
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
key={item.Id}
item={item}
seriesId={item.SeriesId}
cardTitle={item.Name}
imageType={"Primary"}
cardCaption={item.AlbumArtist}
cardType={"square"}
queryKey={["favorite", "musicAlbum"]}
userId={user?.Id}
/>
))}
</CardScroller>
)}
{book.isSuccess && (book.data?.Items?.length ?? 0) > 0 && (
<CardScroller title="Books" displayCards={8} disableDecoration>
{book.data?.Items?.map((item) => (
<Card
key={item.Id}
item={item}
cardTitle={item.Name}
imageType={"Primary"}
cardCaption={item.ProductionYear}
disableOverlay
cardType={"portrait"}
queryKey={["favorite", "book"]}
userId={user?.Id}
/>
))}
</CardScroller>
)}
{musicArtists.isSuccess &&
(musicArtists.data?.Items?.length ?? 0) > 0 && (
<CardScroller title="Artists" displayCards={8} disableDecoration>
{musicArtists.data?.Items?.map((item) => (
<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> {availableSections.map(
{person.data?.Items?.map((item) => ( (section) =>
<Card tabValue === section.id && (
key={item.Id} <Fade key={section.id} in={tabValue === section.id}>
item={item} <div
cardTitle={item.Name} className={`grid-section ${["movies", "series", "books"].includes(section.id) ? "grid-landscape" : ""}`}
imageType={"Primary"} >
disableOverlay {section.query.data?.Items?.map(section.renderCard)}
cardType={"square"} </div>
queryKey={["favorite", "person"]} </Fade>
userId={user?.Id} ),
/> )}
))} </div>
</CardScroller>
)}
</div> </div>
); );
} }