Skip to content

Commit 68db170

Browse files
authored
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
1 parent 1f50a00 commit 68db170

File tree

11 files changed

+730
-8
lines changed

11 files changed

+730
-8
lines changed

mobile/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 54;
6+
objectVersion = 77;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -117,8 +117,6 @@
117117
/* Begin PBXFileSystemSynchronizedRootGroup section */
118118
B2CF7F8C2DDE4EBB00744BF6 /* Sync */ = {
119119
isa = PBXFileSystemSynchronizedRootGroup;
120-
exceptions = (
121-
);
122120
path = Sync;
123121
sourceTree = "<group>";
124122
};
@@ -473,10 +471,14 @@
473471
inputFileListPaths = (
474472
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-input-files.xcfilelist",
475473
);
474+
inputPaths = (
475+
);
476476
name = "[CP] Copy Pods Resources";
477477
outputFileListPaths = (
478478
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-output-files.xcfilelist",
479479
);
480+
outputPaths = (
481+
);
480482
runOnlyForDeploymentPostprocessing = 0;
481483
shellPath = /bin/sh;
482484
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n";
@@ -505,10 +507,14 @@
505507
inputFileListPaths = (
506508
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist",
507509
);
510+
inputPaths = (
511+
);
508512
name = "[CP] Embed Pods Frameworks";
509513
outputFileListPaths = (
510514
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist",
511515
);
516+
outputPaths = (
517+
);
512518
runOnlyForDeploymentPostprocessing = 0;
513519
shellPath = /bin/sh;
514520
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";

mobile/lib/domain/services/remote_album.service.dart

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import 'package:immich_mobile/domain/models/album/album.model.dart';
22
import 'package:immich_mobile/infrastructure/repositories/remote_album.repository.dart';
33
import 'package:immich_mobile/models/albums/album_search.model.dart';
4+
import 'package:immich_mobile/repositories/drift_album_api_repository.dart';
45
import 'package:immich_mobile/utils/remote_album.utils.dart';
56

67
class RemoteAlbumService {
78
final DriftRemoteAlbumRepository _repository;
9+
final DriftAlbumApiRepository _albumApiRepository;
810

9-
const RemoteAlbumService(this._repository);
11+
const RemoteAlbumService(this._repository, this._albumApiRepository);
1012

1113
Future<List<RemoteAlbum>> getAll() {
1214
return _repository.getAll();
@@ -57,4 +59,20 @@ class RemoteAlbumService {
5759

5860
return filtered;
5961
}
62+
63+
Future<RemoteAlbum> createAlbum({
64+
required String title,
65+
required List<String> assetIds,
66+
String? description,
67+
}) async {
68+
final album = await _albumApiRepository.createDriftAlbum(
69+
title,
70+
description: description,
71+
assetIds: assetIds,
72+
);
73+
74+
await _repository.create(album, assetIds);
75+
76+
return album;
77+
}
6078
}

mobile/lib/infrastructure/repositories/remote_album.repository.dart

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import 'package:drift/drift.dart';
22
import 'package:immich_mobile/domain/models/album/album.model.dart';
33
import 'package:immich_mobile/infrastructure/entities/remote_album.entity.drift.dart';
4+
import 'package:immich_mobile/infrastructure/entities/remote_album_asset.entity.drift.dart';
45
import 'package:immich_mobile/infrastructure/repositories/db.repository.dart';
56

6-
enum SortRemoteAlbumsBy { id }
7+
enum SortRemoteAlbumsBy { id, updatedAt }
78

89
class DriftRemoteAlbumRepository extends DriftDatabaseRepository {
910
final Drift _db;
1011
const DriftRemoteAlbumRepository(this._db) : super(_db);
1112

1213
Future<List<RemoteAlbum>> getAll({
13-
Set<SortRemoteAlbumsBy> sortBy = const {},
14+
Set<SortRemoteAlbumsBy> sortBy = const {SortRemoteAlbumsBy.updatedAt},
1415
}) {
1516
final assetCount = _db.remoteAlbumAssetEntity.assetId.count();
1617

@@ -43,6 +44,8 @@ class DriftRemoteAlbumRepository extends DriftDatabaseRepository {
4344
orderings.add(
4445
switch (sort) {
4546
SortRemoteAlbumsBy.id => OrderingTerm.asc(_db.remoteAlbumEntity.id),
47+
SortRemoteAlbumsBy.updatedAt =>
48+
OrderingTerm.desc(_db.remoteAlbumEntity.updatedAt),
4649
},
4750
);
4851
}
@@ -58,6 +61,43 @@ class DriftRemoteAlbumRepository extends DriftDatabaseRepository {
5861
)
5962
.get();
6063
}
64+
65+
Future<void> create(
66+
RemoteAlbum album,
67+
List<String> assetIds,
68+
) async {
69+
await _db.transaction(() async {
70+
final entity = RemoteAlbumEntityCompanion(
71+
id: Value(album.id),
72+
name: Value(album.name),
73+
ownerId: Value(album.ownerId),
74+
createdAt: Value(album.createdAt),
75+
updatedAt: Value(album.updatedAt),
76+
description: Value(album.description),
77+
thumbnailAssetId: Value(album.thumbnailAssetId),
78+
isActivityEnabled: Value(album.isActivityEnabled),
79+
order: Value(album.order),
80+
);
81+
82+
await _db.remoteAlbumEntity.insertOne(entity);
83+
84+
if (assetIds.isNotEmpty) {
85+
final albumAssets = assetIds.map(
86+
(assetId) => RemoteAlbumAssetEntityCompanion(
87+
albumId: Value(album.id),
88+
assetId: Value(assetId),
89+
),
90+
);
91+
92+
await _db.batch((batch) {
93+
batch.insertAll(
94+
_db.remoteAlbumAssetEntity,
95+
albumAssets,
96+
);
97+
});
98+
}
99+
});
100+
}
61101
}
62102

63103
extension on RemoteAlbumEntityData {

mobile/lib/presentation/pages/drift_album.page.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,20 @@ class _DriftAlbumsPageState extends ConsumerState<DriftAlbumsPage> {
9797
onRefresh: onRefresh,
9898
child: CustomScrollView(
9999
slivers: [
100-
const ImmichSliverAppBar(),
100+
ImmichSliverAppBar(
101+
actions: [
102+
IconButton(
103+
icon: const Icon(
104+
Icons.add_rounded,
105+
size: 28,
106+
),
107+
onPressed: () => context.pushRoute(
108+
const DriftCreateAlbumRoute(),
109+
),
110+
),
111+
],
112+
showUploadButton: false,
113+
),
101114
_SearchBar(
102115
searchController: searchController,
103116
searchFocusNode: searchFocusNode,

0 commit comments

Comments
 (0)