feat(flutter): library screen with 5 tabs (Artists/Albums/History/Liked/Hidden)
Models: - history_event.dart (HistoryEvent + HistoryPage envelope) - quarantine_mine.dart (QuarantineMineRow for /api/quarantine/mine) - Renamed Page<T> -> Paged<T> to avoid collision with Material's Page Endpoints: - library_lists.dart: listArtists / listAlbums (paged) - me.dart: history + quarantineMine - likes.dart: extended with listTracks/Albums/Artists (paged) UI: - library_screen.dart: TabBar over 5 tabs - Artists tab: 3-col grid - Albums tab: 2-col grid - History tab: list with relative-time formatting (matches HistoryRow.svelte) - Liked tab: 3 stacked sections (artists scroll-row, albums scroll-row, tracks list) - Hidden tab: list of quarantined tracks with reason pill - /library route + library_music icon on home AppBar First page only for v1 (limit 50). Infinite scroll deferred.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import 'track.dart';
|
||||
|
||||
/// Mirrors web/src/lib/api/history.ts HistoryEvent. Server emits
|
||||
/// `{events, has_more}` rather than the standard `Page<T>` envelope —
|
||||
/// history is timestamp-keyed so total isn't meaningful, only "more
|
||||
/// pages exist below."
|
||||
class HistoryEvent {
|
||||
const HistoryEvent({
|
||||
required this.id,
|
||||
required this.playedAt,
|
||||
required this.track,
|
||||
});
|
||||
|
||||
final String id;
|
||||
/// RFC3339 timestamp; UI formats relative ("3h ago" / "Tue 14:32" /
|
||||
/// "May 1, 2025") via formatRelative helper.
|
||||
final String playedAt;
|
||||
final TrackRef track;
|
||||
|
||||
factory HistoryEvent.fromJson(Map<String, dynamic> j) => HistoryEvent(
|
||||
id: j['id'] as String? ?? '',
|
||||
playedAt: j['played_at'] as String? ?? '',
|
||||
track: TrackRef.fromJson(
|
||||
(j['track'] as Map?)?.cast<String, dynamic>() ?? const {},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class HistoryPage {
|
||||
const HistoryPage({required this.events, required this.hasMore});
|
||||
|
||||
final List<HistoryEvent> events;
|
||||
final bool hasMore;
|
||||
|
||||
factory HistoryPage.fromJson(Map<String, dynamic> j) {
|
||||
final raw = (j['events'] as List?) ?? const [];
|
||||
return HistoryPage(
|
||||
events: raw
|
||||
.map((e) => HistoryEvent.fromJson((e as Map).cast<String, dynamic>()))
|
||||
.toList(growable: false),
|
||||
hasMore: j['has_more'] as bool? ?? false,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
// Mirrors the server's Page<T> envelope used by paged endpoints
|
||||
// Mirrors the server's Page[T] envelope used by paged endpoints
|
||||
// (/api/search, /api/library/artists, /api/library/albums,
|
||||
// /api/library/history, /api/me/likes/*).
|
||||
// /api/likes/*). Class is named `Paged<T>` rather than `Page<T>`
|
||||
// to avoid ambiguous imports with Flutter Material's Navigator-2.0
|
||||
// `Page` class.
|
||||
//
|
||||
// Wire shape from internal/api/types.go Page[T]:
|
||||
// { items: T[], total: int, limit: int, offset: int }
|
||||
@@ -8,8 +10,8 @@
|
||||
// Dart generics can't auto-infer T from JSON, so callers pass an
|
||||
// itemFromJson function alongside the raw map. Parse logic stays in
|
||||
// each entity's own fromJson; this class only handles the envelope.
|
||||
class Page<T> {
|
||||
const Page({
|
||||
class Paged<T> {
|
||||
const Paged({
|
||||
required this.items,
|
||||
required this.total,
|
||||
required this.limit,
|
||||
@@ -21,12 +23,12 @@ class Page<T> {
|
||||
final int limit;
|
||||
final int offset;
|
||||
|
||||
factory Page.fromJson(
|
||||
factory Paged.fromJson(
|
||||
Map<String, dynamic> j,
|
||||
T Function(Map<String, dynamic>) itemFromJson,
|
||||
) {
|
||||
final raw = (j['items'] as List?) ?? const [];
|
||||
return Page<T>(
|
||||
return Paged<T>(
|
||||
items: raw
|
||||
.map((e) => itemFromJson((e as Map).cast<String, dynamic>()))
|
||||
.toList(growable: false),
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/// Mirrors web/src/lib/api/types.ts LidarrQuarantineMineRow. One row
|
||||
/// per quarantined track owned by the caller. Server returns a flat
|
||||
/// list (no Page envelope) at /api/quarantine/mine.
|
||||
class QuarantineMineRow {
|
||||
const QuarantineMineRow({
|
||||
required this.trackId,
|
||||
required this.reason,
|
||||
this.notes,
|
||||
required this.createdAt,
|
||||
required this.trackTitle,
|
||||
required this.trackDurationMs,
|
||||
required this.albumId,
|
||||
required this.albumTitle,
|
||||
this.albumCoverArtPath,
|
||||
required this.artistId,
|
||||
required this.artistName,
|
||||
});
|
||||
|
||||
final String trackId;
|
||||
/// One of: bad_rip / wrong_file / wrong_tags / duplicate / other.
|
||||
final String reason;
|
||||
final String? notes;
|
||||
final String createdAt;
|
||||
final String trackTitle;
|
||||
final int trackDurationMs;
|
||||
final String albumId;
|
||||
final String albumTitle;
|
||||
final String? albumCoverArtPath;
|
||||
final String artistId;
|
||||
final String artistName;
|
||||
|
||||
factory QuarantineMineRow.fromJson(Map<String, dynamic> j) =>
|
||||
QuarantineMineRow(
|
||||
trackId: j['track_id'] as String? ?? '',
|
||||
reason: j['reason'] as String? ?? 'other',
|
||||
notes: j['notes'] as String?,
|
||||
createdAt: j['created_at'] as String? ?? '',
|
||||
trackTitle: j['track_title'] as String? ?? '',
|
||||
trackDurationMs: (j['track_duration_ms'] as num?)?.toInt() ?? 0,
|
||||
albumId: j['album_id'] as String? ?? '',
|
||||
albumTitle: j['album_title'] as String? ?? '',
|
||||
albumCoverArtPath: j['album_cover_art_path'] as String?,
|
||||
artistId: j['artist_id'] as String? ?? '',
|
||||
artistName: j['artist_name'] as String? ?? '',
|
||||
);
|
||||
}
|
||||
@@ -14,20 +14,20 @@ class SearchResponse {
|
||||
required this.tracks,
|
||||
});
|
||||
|
||||
final Page<ArtistRef> artists;
|
||||
final Page<AlbumRef> albums;
|
||||
final Page<TrackRef> tracks;
|
||||
final Paged<ArtistRef> artists;
|
||||
final Paged<AlbumRef> albums;
|
||||
final Paged<TrackRef> tracks;
|
||||
|
||||
factory SearchResponse.fromJson(Map<String, dynamic> j) => SearchResponse(
|
||||
artists: Page.fromJson(
|
||||
artists: Paged.fromJson(
|
||||
(j['artists'] as Map?)?.cast<String, dynamic>() ?? const {},
|
||||
ArtistRef.fromJson,
|
||||
),
|
||||
albums: Page.fromJson(
|
||||
albums: Paged.fromJson(
|
||||
(j['albums'] as Map?)?.cast<String, dynamic>() ?? const {},
|
||||
AlbumRef.fromJson,
|
||||
),
|
||||
tracks: Page.fromJson(
|
||||
tracks: Paged.fromJson(
|
||||
(j['tracks'] as Map?)?.cast<String, dynamic>() ?? const {},
|
||||
TrackRef.fromJson,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user