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:
@@ -990,14 +990,13 @@ impl OfflineRepository {
|
||||
|
||||
self.db_service
|
||||
.query_many(query, |row| {
|
||||
Ok(Library {
|
||||
id: row.get(0)?,
|
||||
name: row.get(1)?,
|
||||
collection_type: row
|
||||
.get::<_, Option<String>>(2)?
|
||||
Ok(Library::new(
|
||||
row.get(0)?,
|
||||
row.get(1)?,
|
||||
row.get::<_, Option<String>>(2)?
|
||||
.unwrap_or_else(|| "unknown".to_string()),
|
||||
image_tag: row.get(3)?,
|
||||
})
|
||||
row.get(3)?,
|
||||
))
|
||||
})
|
||||
.await
|
||||
.map_err(|e| RepoError::Database { message: e })
|
||||
@@ -1190,14 +1189,13 @@ impl MediaRepository for OfflineRepository {
|
||||
|
||||
self.db_service
|
||||
.query_many(query, |row| {
|
||||
Ok(Library {
|
||||
id: row.get(0)?,
|
||||
name: row.get(1)?,
|
||||
collection_type: row
|
||||
.get::<_, Option<String>>(2)?
|
||||
Ok(Library::new(
|
||||
row.get(0)?,
|
||||
row.get(1)?,
|
||||
row.get::<_, Option<String>>(2)?
|
||||
.unwrap_or_else(|| "unknown".to_string()),
|
||||
image_tag: row.get(3)?,
|
||||
})
|
||||
row.get(3)?,
|
||||
))
|
||||
})
|
||||
.await
|
||||
.map_err(|e| RepoError::Database { message: e })
|
||||
@@ -3441,18 +3439,13 @@ mod tests {
|
||||
|
||||
// Simulate the online path persisting the server's library list.
|
||||
let server_libs = vec![
|
||||
Library {
|
||||
id: "music".into(),
|
||||
name: "Music".into(),
|
||||
collection_type: "music".into(),
|
||||
image_tag: None,
|
||||
},
|
||||
Library {
|
||||
id: "movies".into(),
|
||||
name: "Movies".into(),
|
||||
collection_type: "movies".into(),
|
||||
image_tag: Some("tag".into()),
|
||||
},
|
||||
Library::new("music".into(), "Music".into(), "music".into(), None),
|
||||
Library::new(
|
||||
"movies".into(),
|
||||
"Movies".into(),
|
||||
"movies".into(),
|
||||
Some("tag".into()),
|
||||
),
|
||||
];
|
||||
let saved = repo.save_libraries_to_cache(&server_libs).await.unwrap();
|
||||
assert_eq!(saved, 2);
|
||||
|
||||
@@ -946,11 +946,13 @@ impl MediaRepository for OnlineRepository {
|
||||
Ok(response
|
||||
.items
|
||||
.into_iter()
|
||||
.map(|lib| Library {
|
||||
id: lib.id,
|
||||
name: lib.name,
|
||||
collection_type: lib.collection_type.unwrap_or_else(|| "unknown".to_string()),
|
||||
image_tag: lib.image_tags.and_then(|tags| tags.primary()),
|
||||
.map(|lib| {
|
||||
Library::new(
|
||||
lib.id,
|
||||
lib.name,
|
||||
lib.collection_type.unwrap_or_else(|| "unknown".to_string()),
|
||||
lib.image_tags.and_then(|tags| tags.primary()),
|
||||
)
|
||||
})
|
||||
.collect())
|
||||
}
|
||||
|
||||
@@ -36,6 +36,38 @@ pub struct Library {
|
||||
pub collection_type: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub image_tag: Option<String>,
|
||||
/// The favourites scope this library's contents fall under, or `None` for a
|
||||
/// library kind favourites does not carve up (Live TV, channels, books…).
|
||||
///
|
||||
/// Derived here rather than in the UI: which collection type maps to which
|
||||
/// scope is Jellyfin vocabulary, and the frontend must not hold a
|
||||
/// collection-type → category table any more than an item-type one. See
|
||||
/// `SearchScope::for_collection_type`.
|
||||
///
|
||||
/// TRACES: UR-075 | DR-164
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub favorites_scope: Option<SearchScope>,
|
||||
}
|
||||
|
||||
impl Library {
|
||||
/// Build a library, deriving everything that follows from its collection
|
||||
/// type. Prefer this over the struct literal so a new derived field cannot
|
||||
/// be forgotten at one of the construction sites.
|
||||
pub fn new(
|
||||
id: String,
|
||||
name: String,
|
||||
collection_type: String,
|
||||
image_tag: Option<String>,
|
||||
) -> Self {
|
||||
let favorites_scope = SearchScope::for_collection_type(&collection_type);
|
||||
Self {
|
||||
id,
|
||||
name,
|
||||
collection_type,
|
||||
image_tag,
|
||||
favorites_scope,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// User-specific data for an item (playback state, favorites, etc.)
|
||||
@@ -345,6 +377,27 @@ impl SearchScope {
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
/// The scope a library of this Jellyfin `CollectionType` belongs to, or
|
||||
/// `None` when its contents are not something favourites are browsed by.
|
||||
///
|
||||
/// Same reasoning as `item_types`: this table is Jellyfin vocabulary and
|
||||
/// changes when Jellyfin renames a collection type, not when the library
|
||||
/// page is redesigned — so it lives here rather than in the UI that renders
|
||||
/// a per-library favourites tile.
|
||||
///
|
||||
/// `All` is never returned: it is the *absence* of a category, offered
|
||||
/// alongside the libraries rather than derived from one.
|
||||
///
|
||||
/// TRACES: UR-075 | DR-164 | UT-161
|
||||
pub fn for_collection_type(collection_type: &str) -> Option<SearchScope> {
|
||||
match collection_type {
|
||||
"movies" => Some(SearchScope::Movies),
|
||||
"tvshows" => Some(SearchScope::Tv),
|
||||
"music" => Some(SearchScope::Music),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Options for search queries
|
||||
@@ -653,6 +706,54 @@ mod search_scope_tests {
|
||||
let all: SearchOptions = serde_json::from_str(r#"{"scope": "all"}"#).unwrap();
|
||||
assert!(matches!(all.scope, Some(SearchScope::All)));
|
||||
}
|
||||
|
||||
/// TRACES: DR-164 | UT-161
|
||||
#[test]
|
||||
fn test_collection_type_maps_to_its_favorites_scope() {
|
||||
assert_eq!(
|
||||
SearchScope::for_collection_type("movies"),
|
||||
Some(SearchScope::Movies)
|
||||
);
|
||||
assert_eq!(
|
||||
SearchScope::for_collection_type("tvshows"),
|
||||
Some(SearchScope::Tv)
|
||||
);
|
||||
assert_eq!(
|
||||
SearchScope::for_collection_type("music"),
|
||||
Some(SearchScope::Music)
|
||||
);
|
||||
}
|
||||
|
||||
/// A library kind favourites are not browsed by gets no tile at all, rather
|
||||
/// than one that opens an unfiltered list. `All` is never derived from a
|
||||
/// library — it is the cross-library entry offered beside them.
|
||||
///
|
||||
/// TRACES: DR-164 | UT-161
|
||||
#[test]
|
||||
fn test_uncategorised_collection_types_have_no_favorites_scope() {
|
||||
for collection_type in ["livetv", "channels", "boxsets", "books", "unknown", ""] {
|
||||
assert_eq!(
|
||||
SearchScope::for_collection_type(collection_type),
|
||||
None,
|
||||
"{collection_type} should not carry a favourites scope"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// TRACES: DR-164 | UT-161
|
||||
#[test]
|
||||
fn test_library_carries_its_favorites_scope_to_the_frontend() {
|
||||
let music = Library::new("1".into(), "Music".into(), "music".into(), None);
|
||||
assert_eq!(music.favorites_scope, Some(SearchScope::Music));
|
||||
|
||||
let json = serde_json::to_value(&music).unwrap();
|
||||
assert_eq!(json["favoritesScope"], "music");
|
||||
|
||||
// A library with no scope omits the field rather than sending null.
|
||||
let livetv = Library::new("2".into(), "Live TV".into(), "livetv".into(), None);
|
||||
let json = serde_json::to_value(&livetv).unwrap();
|
||||
assert!(json.get("favoritesScope").is_none());
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user