mirror of
https://github.com/KevinMidboe/immich.git
synced 2025-10-29 17:40:28 +00:00
Refactor mobile to use OpenApi generated SDK (#336)
This commit is contained in:
@@ -13,4 +13,5 @@ class AlbumTitleNotifier extends StateNotifier<String> {
|
||||
}
|
||||
|
||||
final albumTitleProvider = StateNotifierProvider<AlbumTitleNotifier, String>(
|
||||
(ref) => AlbumTitleNotifier());
|
||||
(ref) => AlbumTitleNotifier(),
|
||||
);
|
||||
|
||||
@@ -30,7 +30,10 @@ class AlbumViewerNotifier extends StateNotifier<AlbumViewerPageState> {
|
||||
}
|
||||
|
||||
Future<bool> changeAlbumTitle(
|
||||
String albumId, String ownerId, String newAlbumTitle) async {
|
||||
String albumId,
|
||||
String ownerId,
|
||||
String newAlbumTitle,
|
||||
) async {
|
||||
SharedAlbumService service = ref.watch(sharedAlbumServiceProvider);
|
||||
|
||||
bool isSuccess =
|
||||
|
||||
@@ -1,41 +1,46 @@
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:immich_mobile/modules/sharing/models/asset_selection_state.model.dart';
|
||||
|
||||
import 'package:immich_mobile/shared/models/immich_asset.model.dart';
|
||||
import 'package:openapi/api.dart';
|
||||
|
||||
class AssetSelectionNotifier extends StateNotifier<AssetSelectionState> {
|
||||
AssetSelectionNotifier()
|
||||
: super(AssetSelectionState(
|
||||
selectedNewAssetsForAlbum: {},
|
||||
selectedMonths: {},
|
||||
selectedAdditionalAssetsForAlbum: {},
|
||||
selectedAssetsInAlbumViewer: {},
|
||||
isAlbumExist: false,
|
||||
isMultiselectEnable: false,
|
||||
));
|
||||
: super(
|
||||
AssetSelectionState(
|
||||
selectedNewAssetsForAlbum: {},
|
||||
selectedMonths: {},
|
||||
selectedAdditionalAssetsForAlbum: {},
|
||||
selectedAssetsInAlbumViewer: {},
|
||||
isAlbumExist: false,
|
||||
isMultiselectEnable: false,
|
||||
),
|
||||
);
|
||||
|
||||
void setIsAlbumExist(bool isAlbumExist) {
|
||||
state = state.copyWith(isAlbumExist: isAlbumExist);
|
||||
}
|
||||
|
||||
void removeAssetsInMonth(
|
||||
String removedMonth, List<ImmichAsset> assetsInMonth) {
|
||||
Set<ImmichAsset> currentAssetList = state.selectedNewAssetsForAlbum;
|
||||
String removedMonth,
|
||||
List<AssetResponseDto> assetsInMonth,
|
||||
) {
|
||||
Set<AssetResponseDto> currentAssetList = state.selectedNewAssetsForAlbum;
|
||||
Set<String> currentMonthList = state.selectedMonths;
|
||||
|
||||
currentMonthList
|
||||
.removeWhere((selectedMonth) => selectedMonth == removedMonth);
|
||||
|
||||
for (ImmichAsset asset in assetsInMonth) {
|
||||
for (AssetResponseDto asset in assetsInMonth) {
|
||||
currentAssetList.removeWhere((e) => e.id == asset.id);
|
||||
}
|
||||
|
||||
state = state.copyWith(
|
||||
selectedNewAssetsForAlbum: currentAssetList,
|
||||
selectedMonths: currentMonthList);
|
||||
selectedNewAssetsForAlbum: currentAssetList,
|
||||
selectedMonths: currentMonthList,
|
||||
);
|
||||
}
|
||||
|
||||
void addAdditionalAssets(List<ImmichAsset> assets) {
|
||||
void addAdditionalAssets(List<AssetResponseDto> assets) {
|
||||
state = state.copyWith(
|
||||
selectedAdditionalAssetsForAlbum: {
|
||||
...state.selectedAdditionalAssetsForAlbum,
|
||||
@@ -44,7 +49,7 @@ class AssetSelectionNotifier extends StateNotifier<AssetSelectionState> {
|
||||
);
|
||||
}
|
||||
|
||||
void addAllAssetsInMonth(String month, List<ImmichAsset> assetsInMonth) {
|
||||
void addAllAssetsInMonth(String month, List<AssetResponseDto> assetsInMonth) {
|
||||
state = state.copyWith(
|
||||
selectedMonths: {...state.selectedMonths, month},
|
||||
selectedNewAssetsForAlbum: {
|
||||
@@ -54,7 +59,7 @@ class AssetSelectionNotifier extends StateNotifier<AssetSelectionState> {
|
||||
);
|
||||
}
|
||||
|
||||
void addNewAssets(List<ImmichAsset> assets) {
|
||||
void addNewAssets(List<AssetResponseDto> assets) {
|
||||
state = state.copyWith(
|
||||
selectedNewAssetsForAlbum: {
|
||||
...state.selectedNewAssetsForAlbum,
|
||||
@@ -63,20 +68,20 @@ class AssetSelectionNotifier extends StateNotifier<AssetSelectionState> {
|
||||
);
|
||||
}
|
||||
|
||||
void removeSelectedNewAssets(List<ImmichAsset> assets) {
|
||||
Set<ImmichAsset> currentList = state.selectedNewAssetsForAlbum;
|
||||
void removeSelectedNewAssets(List<AssetResponseDto> assets) {
|
||||
Set<AssetResponseDto> currentList = state.selectedNewAssetsForAlbum;
|
||||
|
||||
for (ImmichAsset asset in assets) {
|
||||
for (AssetResponseDto asset in assets) {
|
||||
currentList.removeWhere((e) => e.id == asset.id);
|
||||
}
|
||||
|
||||
state = state.copyWith(selectedNewAssetsForAlbum: currentList);
|
||||
}
|
||||
|
||||
void removeSelectedAdditionalAssets(List<ImmichAsset> assets) {
|
||||
Set<ImmichAsset> currentList = state.selectedAdditionalAssetsForAlbum;
|
||||
void removeSelectedAdditionalAssets(List<AssetResponseDto> assets) {
|
||||
Set<AssetResponseDto> currentList = state.selectedAdditionalAssetsForAlbum;
|
||||
|
||||
for (ImmichAsset asset in assets) {
|
||||
for (AssetResponseDto asset in assets) {
|
||||
currentList.removeWhere((e) => e.id == asset.id);
|
||||
}
|
||||
|
||||
@@ -104,7 +109,7 @@ class AssetSelectionNotifier extends StateNotifier<AssetSelectionState> {
|
||||
);
|
||||
}
|
||||
|
||||
void addAssetsInAlbumViewer(List<ImmichAsset> assets) {
|
||||
void addAssetsInAlbumViewer(List<AssetResponseDto> assets) {
|
||||
state = state.copyWith(
|
||||
selectedAssetsInAlbumViewer: {
|
||||
...state.selectedAssetsInAlbumViewer,
|
||||
@@ -113,10 +118,10 @@ class AssetSelectionNotifier extends StateNotifier<AssetSelectionState> {
|
||||
);
|
||||
}
|
||||
|
||||
void removeAssetsInAlbumViewer(List<ImmichAsset> assets) {
|
||||
Set<ImmichAsset> currentList = state.selectedAssetsInAlbumViewer;
|
||||
void removeAssetsInAlbumViewer(List<AssetResponseDto> assets) {
|
||||
Set<AssetResponseDto> currentList = state.selectedAssetsInAlbumViewer;
|
||||
|
||||
for (ImmichAsset asset in assets) {
|
||||
for (AssetResponseDto asset in assets) {
|
||||
currentList.removeWhere((e) => e.id == asset.id);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:immich_mobile/modules/sharing/models/shared_album.model.dart';
|
||||
import 'package:immich_mobile/modules/sharing/services/shared_album.service.dart';
|
||||
import 'package:openapi/api.dart';
|
||||
|
||||
class SharedAlbumNotifier extends StateNotifier<List<SharedAlbum>> {
|
||||
class SharedAlbumNotifier extends StateNotifier<List<AlbumResponseDto>> {
|
||||
SharedAlbumNotifier(this._sharedAlbumService) : super([]);
|
||||
|
||||
final SharedAlbumService _sharedAlbumService;
|
||||
|
||||
getAllSharedAlbums() async {
|
||||
List<SharedAlbum> sharedAlbums =
|
||||
List<AlbumResponseDto>? sharedAlbums =
|
||||
await _sharedAlbumService.getAllSharedAlbum();
|
||||
|
||||
state = sharedAlbums;
|
||||
if (sharedAlbums != null) {
|
||||
state = sharedAlbums;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> deleteAlbum(String albumId) async {
|
||||
@@ -37,7 +39,9 @@ class SharedAlbumNotifier extends StateNotifier<List<SharedAlbum>> {
|
||||
}
|
||||
|
||||
Future<bool> removeAssetFromAlbum(
|
||||
String albumId, List<String> assetIds) async {
|
||||
String albumId,
|
||||
List<String> assetIds,
|
||||
) async {
|
||||
var res = await _sharedAlbumService.removeAssetFromAlbum(albumId, assetIds);
|
||||
|
||||
if (res) {
|
||||
@@ -49,12 +53,12 @@ class SharedAlbumNotifier extends StateNotifier<List<SharedAlbum>> {
|
||||
}
|
||||
|
||||
final sharedAlbumProvider =
|
||||
StateNotifierProvider<SharedAlbumNotifier, List<SharedAlbum>>((ref) {
|
||||
StateNotifierProvider<SharedAlbumNotifier, List<AlbumResponseDto>>((ref) {
|
||||
return SharedAlbumNotifier(ref.watch(sharedAlbumServiceProvider));
|
||||
});
|
||||
|
||||
final sharedAlbumDetailProvider = FutureProvider.autoDispose
|
||||
.family<SharedAlbum, String>((ref, albumId) async {
|
||||
.family<AlbumResponseDto?, String>((ref, albumId) async {
|
||||
final SharedAlbumService sharedAlbumService =
|
||||
ref.watch(sharedAlbumServiceProvider);
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:immich_mobile/shared/models/user.model.dart';
|
||||
import 'package:immich_mobile/shared/services/user.service.dart';
|
||||
import 'package:openapi/api.dart';
|
||||
|
||||
final suggestedSharedUsersProvider =
|
||||
FutureProvider.autoDispose<List<User>>((ref) async {
|
||||
FutureProvider.autoDispose<List<UserResponseDto>>((ref) async {
|
||||
UserService userService = ref.watch(userServiceProvider);
|
||||
|
||||
return await userService.getAllUsersInfo();
|
||||
return await userService.getAllUsersInfo(isAll: false) ?? [];
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user