feat(library,home): lay libraries out as a mosaic, with favourites per category
The library overview and the home shortcut strip showed artwork of three different shapes — square music covers, 16:9 library backdrops, 2:3 posters — in grids that pick one box and crop everything to it. The home strip said so in a comment: it forced `aspect="video"` on music libraries so the row would line up, which lined it up by cutting the covers down. Both surfaces are now justified mosaics: rows share one height and each tile is as wide as its own artwork. `layoutMosaic` is a pure module — it packs tiles until the height needed to fill the container drops to the target, justifies the row by absorbing the rounding remainder into its widest tile, and deliberately leaves the last row unstretched so one leftover tile does not inflate into a banner. The component supplies only what the DOM knows: the measured container width, and the artwork's *decoded* aspect ratio (via a new `onNaturalSize` on CachedImage), committed in one debounced batch so the grid does not reshuffle once per image as artwork lands. Favourites gain a tile per category beside the library it belongs to, alongside the existing cross-library entry. Which collection type maps to which category is Jellyfin vocabulary, so it is derived in Rust — `SearchScope::for_collection_type`, stamped onto every `Library` by a new constructor and carried over as an optional `favoritesScope`. Deriving it in Svelte would have rebuilt the exact leak `SearchScope::item_types` was extracted to close. A category shows one tile however many libraries share it, and a library kind favourites do not carve up (Live TV, channels, books) gets none. Also corrects the requirements-count test, which the UR-074 commit left one behind. Spec: docs/specs/library-mosaic.md TRACES: UR-075, UR-067 | DR-163, DR-164 | UT-158..UT-162
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import type { Library } from "$lib/api/types";
|
||||
import { buildLibraryMosaic, assumedLibraryRatio } from "./libraryMosaic";
|
||||
|
||||
function lib(
|
||||
id: string,
|
||||
name: string,
|
||||
collectionType: string,
|
||||
favoritesScope?: Library["favoritesScope"],
|
||||
): Library {
|
||||
return { id, name, collectionType, favoritesScope } as Library;
|
||||
}
|
||||
|
||||
const MOVIES = lib("1", "Movies", "movies", "movies");
|
||||
const SHOWS = lib("2", "Shows", "tvshows", "tv");
|
||||
const MUSIC = lib("3", "Music", "music", "music");
|
||||
const LIVETV = lib("4", "Live TV", "livetv");
|
||||
|
||||
describe("buildLibraryMosaic", () => {
|
||||
it("leads with the cross-library favourites entry", () => {
|
||||
const entries = buildLibraryMosaic([MOVIES]);
|
||||
expect(entries[0]).toMatchObject({
|
||||
kind: "favorites",
|
||||
scope: "all",
|
||||
label: "Favourites",
|
||||
href: "/library/favorites",
|
||||
});
|
||||
});
|
||||
|
||||
it("puts each library's own favourites tile right after it", () => {
|
||||
const entries = buildLibraryMosaic([MOVIES, MUSIC]);
|
||||
|
||||
expect(entries.map((e) => e.label)).toEqual([
|
||||
"Favourites",
|
||||
"Movies",
|
||||
"Favourite Movies",
|
||||
"Music",
|
||||
"Favourite Music",
|
||||
]);
|
||||
});
|
||||
|
||||
it("links a category tile to that category's favourites tab", () => {
|
||||
const entries = buildLibraryMosaic([SHOWS]);
|
||||
const tile = entries.find((e) => e.label === "Favourite Shows");
|
||||
expect(tile).toMatchObject({ kind: "favorites", scope: "tv", href: "/library/favorites?scope=tv" });
|
||||
});
|
||||
|
||||
it("offers a category's favourites once, however many libraries share it", () => {
|
||||
const entries = buildLibraryMosaic([MOVIES, lib("5", "Kids Films", "movies", "movies")]);
|
||||
|
||||
expect(entries.filter((e) => e.kind === "favorites" && e.scope === "movies")).toHaveLength(1);
|
||||
expect(entries.map((e) => e.label)).toEqual([
|
||||
"Favourites",
|
||||
"Movies",
|
||||
"Favourite Movies",
|
||||
"Kids Films",
|
||||
]);
|
||||
});
|
||||
|
||||
it("gives no favourites tile to a library kind favourites do not carve up", () => {
|
||||
const entries = buildLibraryMosaic([LIVETV]);
|
||||
expect(entries.map((e) => e.label)).toEqual(["Favourites", "Live TV"]);
|
||||
});
|
||||
|
||||
it("ignores a scope the favourites page does not offer as a tab", () => {
|
||||
const odd = lib("6", "Books", "books", "books" as Library["favoritesScope"]);
|
||||
const entries = buildLibraryMosaic([odd]);
|
||||
expect(entries.map((e) => e.label)).toEqual(["Favourites", "Books"]);
|
||||
});
|
||||
|
||||
it("keeps every library, and keys tiles uniquely", () => {
|
||||
const entries = buildLibraryMosaic([MOVIES, SHOWS, MUSIC, LIVETV]);
|
||||
|
||||
expect(entries.filter((e) => e.kind === "library")).toHaveLength(4);
|
||||
expect(new Set(entries.map((e) => e.key)).size).toBe(entries.length);
|
||||
});
|
||||
|
||||
it("has nothing but the favourites entry when there are no libraries", () => {
|
||||
expect(buildLibraryMosaic([]).map((e) => e.key)).toEqual(["favorites:all"]);
|
||||
});
|
||||
|
||||
it("gives a category tile the shape of the library it follows", () => {
|
||||
const entries = buildLibraryMosaic([MUSIC, MOVIES]);
|
||||
const musicFavorites = entries.find((e) => e.label === "Favourite Music")!;
|
||||
const movieFavorites = entries.find((e) => e.label === "Favourite Movies")!;
|
||||
|
||||
expect(musicFavorites.ratio).toBe(assumedLibraryRatio(MUSIC));
|
||||
expect(movieFavorites.ratio).toBe(assumedLibraryRatio(MOVIES));
|
||||
});
|
||||
});
|
||||
|
||||
describe("assumedLibraryRatio", () => {
|
||||
it("assumes a square cover for music and a wide backdrop otherwise", () => {
|
||||
expect(assumedLibraryRatio(MUSIC)).toBe(1);
|
||||
expect(assumedLibraryRatio(MOVIES)).toBeCloseTo(16 / 9);
|
||||
expect(assumedLibraryRatio(LIVETV)).toBeCloseTo(16 / 9);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user