2022-04-24 04:08:45 +02:00
|
|
|
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';
|
|
|
|
|
|
|
|
class SharedAlbumNotifier extends StateNotifier<List<SharedAlbum>> {
|
|
|
|
SharedAlbumNotifier() : super([]);
|
|
|
|
|
|
|
|
final SharedAlbumService _sharedAlbumService = SharedAlbumService();
|
|
|
|
|
|
|
|
getAllSharedAlbums() async {
|
2022-06-22 07:23:35 +02:00
|
|
|
List<SharedAlbum> sharedAlbums =
|
|
|
|
await _sharedAlbumService.getAllSharedAlbum();
|
2022-04-24 04:08:45 +02:00
|
|
|
|
|
|
|
state = sharedAlbums;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<bool> deleteAlbum(String albumId) async {
|
|
|
|
var res = await _sharedAlbumService.deleteAlbum(albumId);
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
state = state.where((album) => album.id != albumId).toList();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<bool> leaveAlbum(String albumId) async {
|
|
|
|
var res = await _sharedAlbumService.leaveAlbum(albumId);
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
state = state.where((album) => album.id != albumId).toList();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-22 07:23:35 +02:00
|
|
|
Future<bool> removeAssetFromAlbum(
|
|
|
|
String albumId, List<String> assetIds) async {
|
2022-04-24 04:08:45 +02:00
|
|
|
var res = await _sharedAlbumService.removeAssetFromAlbum(albumId, assetIds);
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-22 07:23:35 +02:00
|
|
|
final sharedAlbumProvider =
|
|
|
|
StateNotifierProvider<SharedAlbumNotifier, List<SharedAlbum>>((ref) {
|
2022-04-24 04:08:45 +02:00
|
|
|
return SharedAlbumNotifier();
|
|
|
|
});
|
|
|
|
|
2022-06-22 07:23:35 +02:00
|
|
|
final sharedAlbumDetailProvider = FutureProvider.autoDispose
|
|
|
|
.family<SharedAlbum, String>((ref, albumId) async {
|
|
|
|
final SharedAlbumService sharedAlbumService = SharedAlbumService();
|
2022-04-24 04:08:45 +02:00
|
|
|
|
2022-06-22 07:23:35 +02:00
|
|
|
return await sharedAlbumService.getAlbumDetail(albumId);
|
2022-04-24 04:08:45 +02:00
|
|
|
});
|