fix: group mobile library dropdown by server

This commit is contained in:
edde746
2026-05-01 07:55:15 +02:00
parent d5a12c404a
commit f03c84e8dc
3 changed files with 136 additions and 68 deletions
+20
View File
@@ -0,0 +1,20 @@
import '../media/media_library.dart';
typedef LibraryServerGroups = ({List<String> serverOrder, Map<String, List<MediaLibrary>> byServer});
/// Groups libraries by server while preserving each server's first appearance in
/// the provided list. Libraries without a server id are placed in the empty-key
/// bucket at their first occurrence.
LibraryServerGroups groupLibrariesByFirstAppearance(List<MediaLibrary> libraries) {
final order = <String>[];
final byServer = <String, List<MediaLibrary>>{};
for (final lib in libraries) {
final key = lib.serverId ?? '';
if (!byServer.containsKey(key)) {
order.add(key);
byServer[key] = [];
}
byServer[key]!.add(lib);
}
return (serverOrder: order, byServer: byServer);
}