From 2a0478fc16a88fbebb91770f0e83214c3807f765 Mon Sep 17 00:00:00 2001 From: 1xDed Date: Thu, 3 Dec 2026 09:45:50 +0300 Subject: [PATCH] fix(ui): match loading skeletons to real pages Measure the library grid instead of guessing from the viewport, reuse the card scroller for search and latest rows, mirror item/music page structure, and add skeleton sections to the home placeholder. --- .../homeSection/latestMediaSection.tsx | 2 +- src/components/skeleton/cards.tsx | 64 ++++----- src/components/skeleton/item.tsx | 123 ++++++------------ src/components/skeleton/libraryItems.tsx | 106 ++++++++------- src/components/skeleton/musicPage.tsx | 111 ++++++++++++++++ src/components/skeleton/seasonSelector.tsx | 78 +++++------ src/routes/_api/home/home.scss | 15 +++ src/routes/_api/home/index.tsx | 12 ++ src/routes/_api/library/$id.tsx | 22 ++-- src/routes/_api/library/library.scss | 3 +- src/routes/_api/music/album/$id.tsx | 17 +-- src/routes/_api/music/artist/$id.tsx | 17 +-- src/routes/_api/music/playlist/$id.tsx | 17 +-- src/routes/_api/search/index.tsx | 48 +++---- 14 files changed, 348 insertions(+), 287 deletions(-) create mode 100644 src/components/skeleton/musicPage.tsx diff --git a/src/components/layouts/homeSection/latestMediaSection.tsx b/src/components/layouts/homeSection/latestMediaSection.tsx index 83a05f0..a42bf40 100644 --- a/src/components/layouts/homeSection/latestMediaSection.tsx +++ b/src/components/layouts/homeSection/latestMediaSection.tsx @@ -26,7 +26,7 @@ export const LatestMediaSection = ({ getLibraryLatestQueryOptions(api, user?.Id, latestMediaLib.Id), ); if (data.isPending) { - return ; + return ; } if (data.isSuccess && (data.data?.length ?? 0) >= 1) { return ( diff --git a/src/components/skeleton/cards.tsx b/src/components/skeleton/cards.tsx index 4233e54..82d5f18 100644 --- a/src/components/skeleton/cards.tsx +++ b/src/components/skeleton/cards.tsx @@ -1,34 +1,38 @@ import Skeleton from "@mui/material/Skeleton"; -import Typography from "@mui/material/Typography"; import React from "react"; +import CardScroller from "@/components/cardScroller/cardScroller"; -export const CardsSkeleton = () => { - return ( -
- - - -
- {Array.from({ length: 12 }).map((_, index) => ( - - ))} -
+export const CardsSkeleton = ({ + title = "Загрузка", + displayCards = 7, +}: { + title?: string; + displayCards?: number; +}) => ( + + {Array.from({ length: displayCards }, (_, index) => ( + + ))} + +); + + +export const CardSkeleton = ({ + cardType = "portrait", +}: { + cardType?: "portrait" | "square" | "thumb"; +}) => ( +
+
+
- ); -}; + + +
+); diff --git a/src/components/skeleton/item.tsx b/src/components/skeleton/item.tsx index f9bc623..4319ef1 100644 --- a/src/components/skeleton/item.tsx +++ b/src/components/skeleton/item.tsx @@ -1,123 +1,76 @@ -import React from "react"; - import { Skeleton } from "@mui/material"; import { motion } from "motion/react"; +import React from "react"; + +import "@/components/itemDetail/itemDetail.scss"; +import "@/components/itemHeader/itemHeader.scss"; const ItemSkeleton = () => { return (
-
+
-
- - {/* */} - +
+
-
- - +
+ + +
- - - + + + +
-
+
diff --git a/src/components/skeleton/libraryItems.tsx b/src/components/skeleton/libraryItems.tsx index 6ef249f..fe227da 100644 --- a/src/components/skeleton/libraryItems.tsx +++ b/src/components/skeleton/libraryItems.tsx @@ -1,5 +1,5 @@ import { Skeleton } from "@mui/material"; -import React from "react"; +import React, { useLayoutEffect, useRef, useState } from "react"; type LibraryItemsSkeletonProps = { /** Square artwork (music, playlists, genres) instead of portrait posters. */ @@ -7,65 +7,77 @@ type LibraryItemsSkeletonProps = { }; /** - * Placeholder that matches the virtualized library grid: same card width, - * gap and text block. A mismatched skeleton was making the real cards resize - * when the first page of items arrived. + * Placeholder that matches the virtualized library grid: measured against the + * real grid container, the same gap and the same three rows of cards. Keeping + * the width measured instead of derived from the viewport means the mobile + * page margins cannot turn the two-column grid into one giant card. */ const LibraryItemsSkeleton = ({ square = false, }: LibraryItemsSkeletonProps) => { - const viewportWidth = - typeof window === "undefined" - ? 1200 - : document.documentElement.clientWidth || window.innerWidth; - // Same inset as `.library-items` (4em on each side) used by the real grid. - const width = Math.max(0, viewportWidth - 128); + const ref = useRef(null); + const [width, setWidth] = useState(0); + + useLayoutEffect(() => { + const element = ref.current; + if (!element) return; + + const update = () => setWidth(element.clientWidth); + update(); + const observer = new ResizeObserver(update); + observer.observe(element); + return () => observer.disconnect(); + }, []); + const minCardWidth = width < 700 ? 140 : 180; - const columns = Math.max(1, Math.floor(width / minCardWidth)); + const columns = width > 0 ? Math.max(1, Math.floor(width / minCardWidth)) : 0; const gap = 16; - const cardWidth = Math.max( - 1, - Math.floor((width - (columns - 1) * gap) / columns), - ); - const count = columns * 3; - const placeholders = Array.from({ length: count }, (_, index) => ({ + const cardWidth = + columns > 0 + ? Math.max(1, Math.floor((width - (columns - 1) * gap) / columns)) + : 0; + const placeholders = Array.from({ length: columns * 3 }, (_, index) => ({ id: `library-skeleton-${index}`, })); return ( -
- {placeholders.map((placeholder) => ( +
+ {columns > 0 && (
- - - + {placeholders.map((placeholder) => ( +
+ + + +
+ ))}
- ))} + )}
); }; diff --git a/src/components/skeleton/musicPage.tsx b/src/components/skeleton/musicPage.tsx new file mode 100644 index 0000000..9120fb3 --- /dev/null +++ b/src/components/skeleton/musicPage.tsx @@ -0,0 +1,111 @@ +import { Skeleton } from "@mui/material"; +import React from "react"; + +import "@/components/albumMusicTrack/albumMusicTrack.scss"; + +type MusicPageSkeletonProps = { + /** Artist pages open on a round portrait and a discography grid. */ + artist?: boolean; +}; + +const ALBUM_SKELETONS = ["one", "two", "three", "four", "five"]; +const TRACK_SKELETONS = [ + "one", + "two", + "three", + "four", + "five", + "six", + "seven", + "eight", +]; + +const AlbumCardSkeleton = () => ( +
+ + + +
+); + +const MusicPageSkeleton = ({ artist = false }: MusicPageSkeletonProps) => ( +
+
+
+ +
+
+ + + + +
+ + + +
+
+
+ + {artist ? ( + <> +
+ + + +
+
+ {ALBUM_SKELETONS.map((id) => ( + + ))} +
+ + ) : ( +
+
+ + + + +
+ {TRACK_SKELETONS.map((id) => ( +
+ +
+ + +
+ + +
+ ))} +
+ )} +
+); + +export default MusicPageSkeleton; diff --git a/src/components/skeleton/seasonSelector.tsx b/src/components/skeleton/seasonSelector.tsx index 8281165..b4f3eae 100644 --- a/src/components/skeleton/seasonSelector.tsx +++ b/src/components/skeleton/seasonSelector.tsx @@ -1,52 +1,44 @@ import Divider from "@mui/material/Divider"; -import Grid2 from "@mui/material/Grid"; import Skeleton from "@mui/material/Skeleton"; -import Typography from "@mui/material/Typography"; import React from "react"; import EpisodeSkeleton from "./episode"; -export const SeasonSelectorSkeleton = () => { - return ( - ( +
+
-
- - - - +
+ +
- -
-
- +
+ + +
- - ); -}; +
+ +
+ +
+
+); + +export default SeasonSelectorSkeleton; diff --git a/src/routes/_api/home/home.scss b/src/routes/_api/home/home.scss index b0307f1..1bc1e39 100644 --- a/src/routes/_api/home/home.scss +++ b/src/routes/_api/home/home.scss @@ -124,6 +124,7 @@ body.has-player-bar .home-sections { .home-skeleton-cards { display: flex; gap: 0.75rem; + overflow: hidden; } .home-skeleton-cards span { @@ -180,3 +181,17 @@ body.has-player-bar .home-sections { padding: 2rem 1.1rem calc(8rem + var(--safe-bottom)); } } + + +.home-skeleton-sections { + gap: 1.8em; +} + +.home-skeleton-row { + display: flex; + flex-direction: column; +} + +.home-skeleton-row .home-skeleton-heading { + margin-bottom: 0.9em; +} diff --git a/src/routes/_api/home/index.tsx b/src/routes/_api/home/index.tsx index 1be903b..ac78366 100644 --- a/src/routes/_api/home/index.tsx +++ b/src/routes/_api/home/index.tsx @@ -200,6 +200,18 @@ function HomeContent({ api, user }: { api: Api; user: UserDto }) {
+
+ {[0, 1, 2].map((row) => ( +
+ +
+ {[0, 1, 2, 3].map((card) => ( + + ))} +
+
+ ))} +
); } diff --git a/src/routes/_api/library/$id.tsx b/src/routes/_api/library/$id.tsx index 1faa2f8..1b137b8 100644 --- a/src/routes/_api/library/$id.tsx +++ b/src/routes/_api/library/$id.tsx @@ -109,16 +109,18 @@ function Library() { > +
+ +
} >
diff --git a/src/routes/_api/library/library.scss b/src/routes/_api/library/library.scss index d28d7cc..bda4dc1 100644 --- a/src/routes/_api/library/library.scss +++ b/src/routes/_api/library/library.scss @@ -227,7 +227,6 @@ } .library-items { - padding-top: 0.5rem !important; - padding-bottom: calc(7.5em + var(--safe-bottom)) !important; + padding: 0.5rem 0.75rem calc(7.5em + var(--safe-bottom)) !important; } } diff --git a/src/routes/_api/music/album/$id.tsx b/src/routes/_api/music/album/$id.tsx index 6924a44..f4431d4 100644 --- a/src/routes/_api/music/album/$id.tsx +++ b/src/routes/_api/music/album/$id.tsx @@ -1,7 +1,5 @@ import { BaseItemKind, SortOrder } from "@jellyfin/sdk/lib/generated-client"; import { getLibraryApi } from "@jellyfin/sdk/lib/utils/api/library-api"; -import Box from "@mui/material/Box"; -import CircularProgress from "@mui/material/CircularProgress"; import { useQuery } from "@tanstack/react-query"; import { createFileRoute, Link } from "@tanstack/react-router"; import React, { useLayoutEffect, useMemo } from "react"; @@ -13,6 +11,7 @@ import RatingControl from "@/components/buttons/ratingControl"; import { Card } from "@/components/card/card"; import CardScroller from "@/components/cardScroller/cardScroller"; import { ErrorNotice } from "@/components/notices/errorNotice/errorNotice"; +import MusicPageSkeleton from "@/components/skeleton/musicPage"; import ShowMoreText from "@/components/showMoreText"; import TagChip from "@/components/tagChip"; import { getTypeIcon } from "@/components/utils/iconsCollection"; @@ -130,19 +129,7 @@ function MusicAlbumTitlePage() { }, [item.isSuccess, item.data, setBackdrop]); if (item.isPending) { - return ( - - - - ); + return ; } if (item.isError) { diff --git a/src/routes/_api/music/artist/$id.tsx b/src/routes/_api/music/artist/$id.tsx index 3510d27..fa9f8d2 100644 --- a/src/routes/_api/music/artist/$id.tsx +++ b/src/routes/_api/music/artist/$id.tsx @@ -6,8 +6,6 @@ import { SortOrder, } from "@jellyfin/sdk/lib/generated-client"; import { getLibraryApi } from "@jellyfin/sdk/lib/utils/api/library-api"; -import Box from "@mui/material/Box"; -import CircularProgress from "@mui/material/CircularProgress"; import IconButton from "@mui/material/IconButton"; import Tooltip from "@mui/material/Tooltip"; import { useQuery } from "@tanstack/react-query"; @@ -21,6 +19,7 @@ import RatingControl from "@/components/buttons/ratingControl"; import { Card } from "@/components/card/card"; import IconLink from "@/components/iconLink"; import { ErrorNotice } from "@/components/notices/errorNotice/errorNotice"; +import MusicPageSkeleton from "@/components/skeleton/musicPage"; import ShowMoreText from "@/components/showMoreText"; import getImageUrlsApi from "@/utils/methods/getImageUrlsApi"; import { useBackdropStore } from "@/utils/store/backdrop"; @@ -195,19 +194,7 @@ function ArtistTitlePage() { ].filter(Boolean); if (item.isPending) { - return ( - - - - ); + return ; } if (item.isError) { diff --git a/src/routes/_api/music/playlist/$id.tsx b/src/routes/_api/music/playlist/$id.tsx index 4afb58e..6f23023 100644 --- a/src/routes/_api/music/playlist/$id.tsx +++ b/src/routes/_api/music/playlist/$id.tsx @@ -1,8 +1,6 @@ import { BaseItemKind } from "@jellyfin/sdk/lib/generated-client"; import { getLibraryApi } from "@jellyfin/sdk/lib/utils/api/library-api"; import { getPlaylistApi } from "@jellyfin/sdk/lib/utils/api/playlist-api"; -import Box from "@mui/material/Box"; -import CircularProgress from "@mui/material/CircularProgress"; import { useQuery } from "@tanstack/react-query"; import { createFileRoute } from "@tanstack/react-router"; import React, { useEffect } from "react"; @@ -13,6 +11,7 @@ import RatingControl from "@/components/buttons/ratingControl"; import { Card } from "@/components/card/card"; import CardScroller from "@/components/cardScroller/cardScroller"; import { ErrorNotice } from "@/components/notices/errorNotice/errorNotice"; +import MusicPageSkeleton from "@/components/skeleton/musicPage"; import ShowMoreText from "@/components/showMoreText"; import TagChip from "@/components/tagChip"; import { getTypeIcon } from "@/components/utils/iconsCollection"; @@ -100,19 +99,7 @@ function PlaylistTitlePage() { }, [item.isSuccess, setAppBackdrop]); if (item.isPending) { - return ( - - - - ); + return ; } if (item.isError) { diff --git a/src/routes/_api/search/index.tsx b/src/routes/_api/search/index.tsx index 265925b..0cfaccf 100644 --- a/src/routes/_api/search/index.tsx +++ b/src/routes/_api/search/index.tsx @@ -6,6 +6,7 @@ import { useQuery } from "@tanstack/react-query"; import React, { useEffect, useMemo, useState } from "react"; import { Card } from "@/components/card/card"; import CardScroller from "@/components/cardScroller/cardScroller"; +import { CardSkeleton } from "@/components/skeleton/cards"; import { useBackdropStore } from "@/utils/store/backdrop"; import "./search.scss"; import { @@ -424,7 +425,7 @@ function CategorySection({ category, query, api, user, onResult }: any) { } }, [data, isLoading, onResult]); - if (isLoading) return ; + if (isLoading) return ; if (!data?.items || data.items.length === 0) return null; // ... (Card mapping logic same as before) ... @@ -477,31 +478,30 @@ function CategorySection({ category, query, api, user, onResult }: any) { ); } -function CategorySkeleton() { +function CategorySkeleton({ category }: { category: any }) { + const displayCards = category.value === "Episode" ? 4 : 7; + const cardType = + category.value === "Episode" + ? "thumb" + : ["MusicAlbum", "MusicArtist", "Person"].includes(category.value) + ? "square" + : "portrait"; + return ( - - - - {[1, 2, 3, 4, 5, 6].map((i) => ( - + + {Array.from({ length: displayCards }, (_, index) => ( + ))} - - + +
); }