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,5 +1,7 @@
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:immich_mobile/constants/enums.dart';
|
||||
import 'package:immich_mobile/domain/models/album/album.model.dart'
|
||||
show AlbumAssetOrder, RemoteAlbum;
|
||||
import 'package:immich_mobile/entities/album.entity.dart';
|
||||
import 'package:immich_mobile/entities/asset.entity.dart';
|
||||
import 'package:immich_mobile/infrastructure/entities/user.entity.dart'
|
||||
@@ -50,6 +52,25 @@ class AlbumApiRepository extends ApiRepository {
|
||||
return _toAlbum(responseDto);
|
||||
}
|
||||
|
||||
// TODO: Change name after removing old method
|
||||
Future<RemoteAlbum> createDriftAlbum(
|
||||
String name, {
|
||||
required Iterable<String> assetIds,
|
||||
String? description,
|
||||
}) async {
|
||||
final responseDto = await checkNull(
|
||||
_api.createAlbum(
|
||||
CreateAlbumDto(
|
||||
albumName: name,
|
||||
description: description,
|
||||
assetIds: assetIds.toList(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return _toRemoteAlbum(responseDto);
|
||||
}
|
||||
|
||||
Future<Album> update(
|
||||
String albumId, {
|
||||
String? name,
|
||||
@@ -170,4 +191,22 @@ class AlbumApiRepository extends ApiRepository {
|
||||
|
||||
return album;
|
||||
}
|
||||
|
||||
static RemoteAlbum _toRemoteAlbum(AlbumResponseDto dto) {
|
||||
return RemoteAlbum(
|
||||
id: dto.id,
|
||||
name: dto.albumName,
|
||||
ownerId: dto.owner.id,
|
||||
description: dto.description,
|
||||
createdAt: dto.createdAt,
|
||||
updatedAt: dto.updatedAt,
|
||||
thumbnailAssetId: dto.albumThumbnailAssetId,
|
||||
isActivityEnabled: dto.isActivityEnabled,
|
||||
order: dto.order == AssetOrder.asc
|
||||
? AlbumAssetOrder.asc
|
||||
: AlbumAssetOrder.desc,
|
||||
assetCount: dto.assetCount,
|
||||
ownerName: dto.owner.name,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:immich_mobile/domain/models/album/album.model.dart';
|
||||
import 'package:immich_mobile/providers/api.provider.dart';
|
||||
import 'package:immich_mobile/repositories/api.repository.dart';
|
||||
// ignore: import_rule_openapi
|
||||
import 'package:openapi/api.dart';
|
||||
|
||||
final driftAlbumApiRepositoryProvider = Provider(
|
||||
(ref) => DriftAlbumApiRepository(ref.watch(apiServiceProvider).albumsApi),
|
||||
);
|
||||
|
||||
class DriftAlbumApiRepository extends ApiRepository {
|
||||
final AlbumsApi _api;
|
||||
|
||||
DriftAlbumApiRepository(this._api);
|
||||
|
||||
Future<RemoteAlbum> createDriftAlbum(
|
||||
String name, {
|
||||
required Iterable<String> assetIds,
|
||||
String? description,
|
||||
}) async {
|
||||
final responseDto = await checkNull(
|
||||
_api.createAlbum(
|
||||
CreateAlbumDto(
|
||||
albumName: name,
|
||||
description: description,
|
||||
assetIds: assetIds.toList(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return responseDto.toRemoteAlbum();
|
||||
}
|
||||
}
|
||||
|
||||
extension on AlbumResponseDto {
|
||||
RemoteAlbum toRemoteAlbum() {
|
||||
return RemoteAlbum(
|
||||
id: id,
|
||||
name: albumName,
|
||||
ownerId: owner.id,
|
||||
description: description,
|
||||
createdAt: createdAt,
|
||||
updatedAt: updatedAt,
|
||||
thumbnailAssetId: albumThumbnailAssetId,
|
||||
isActivityEnabled: isActivityEnabled,
|
||||
order:
|
||||
order == AssetOrder.asc ? AlbumAssetOrder.asc : AlbumAssetOrder.desc,
|
||||
assetCount: assetCount,
|
||||
ownerName: owner.name,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user