You've already forked immich
mirror of
https://github.com/immich-app/immich.git
synced 2025-08-07 23:03:36 +02:00
feat: new create album page (#19731)
* feat: new create album page * finished create album flow * refactor into stateful widgets * refactor * focus fix * lint * default sort * pr feedback
This commit is contained in:
@ -1,16 +1,17 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:immich_mobile/domain/models/album/album.model.dart';
|
||||
import 'package:immich_mobile/infrastructure/entities/remote_album.entity.drift.dart';
|
||||
import 'package:immich_mobile/infrastructure/entities/remote_album_asset.entity.drift.dart';
|
||||
import 'package:immich_mobile/infrastructure/repositories/db.repository.dart';
|
||||
|
||||
enum SortRemoteAlbumsBy { id }
|
||||
enum SortRemoteAlbumsBy { id, updatedAt }
|
||||
|
||||
class DriftRemoteAlbumRepository extends DriftDatabaseRepository {
|
||||
final Drift _db;
|
||||
const DriftRemoteAlbumRepository(this._db) : super(_db);
|
||||
|
||||
Future<List<RemoteAlbum>> getAll({
|
||||
Set<SortRemoteAlbumsBy> sortBy = const {},
|
||||
Set<SortRemoteAlbumsBy> sortBy = const {SortRemoteAlbumsBy.updatedAt},
|
||||
}) {
|
||||
final assetCount = _db.remoteAlbumAssetEntity.assetId.count();
|
||||
|
||||
@ -43,6 +44,8 @@ class DriftRemoteAlbumRepository extends DriftDatabaseRepository {
|
||||
orderings.add(
|
||||
switch (sort) {
|
||||
SortRemoteAlbumsBy.id => OrderingTerm.asc(_db.remoteAlbumEntity.id),
|
||||
SortRemoteAlbumsBy.updatedAt =>
|
||||
OrderingTerm.desc(_db.remoteAlbumEntity.updatedAt),
|
||||
},
|
||||
);
|
||||
}
|
||||
@ -58,6 +61,43 @@ class DriftRemoteAlbumRepository extends DriftDatabaseRepository {
|
||||
)
|
||||
.get();
|
||||
}
|
||||
|
||||
Future<void> create(
|
||||
RemoteAlbum album,
|
||||
List<String> assetIds,
|
||||
) async {
|
||||
await _db.transaction(() async {
|
||||
final entity = RemoteAlbumEntityCompanion(
|
||||
id: Value(album.id),
|
||||
name: Value(album.name),
|
||||
ownerId: Value(album.ownerId),
|
||||
createdAt: Value(album.createdAt),
|
||||
updatedAt: Value(album.updatedAt),
|
||||
description: Value(album.description),
|
||||
thumbnailAssetId: Value(album.thumbnailAssetId),
|
||||
isActivityEnabled: Value(album.isActivityEnabled),
|
||||
order: Value(album.order),
|
||||
);
|
||||
|
||||
await _db.remoteAlbumEntity.insertOne(entity);
|
||||
|
||||
if (assetIds.isNotEmpty) {
|
||||
final albumAssets = assetIds.map(
|
||||
(assetId) => RemoteAlbumAssetEntityCompanion(
|
||||
albumId: Value(album.id),
|
||||
assetId: Value(assetId),
|
||||
),
|
||||
);
|
||||
|
||||
await _db.batch((batch) {
|
||||
batch.insertAll(
|
||||
_db.remoteAlbumAssetEntity,
|
||||
albumAssets,
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
extension on RemoteAlbumEntityData {
|
||||
|
Reference in New Issue
Block a user