2022-04-23 19:08:45 -07: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>> {
|
2022-06-25 11:46:51 -07:00
|
|
|
SharedAlbumNotifier(this._sharedAlbumService) : super([]);
|
2022-04-23 19:08:45 -07:00
|
|
|
|
2022-06-25 11:46:51 -07:00
|
|
|
final SharedAlbumService _sharedAlbumService;
|
2022-04-23 19:08:45 -07:00
|
|
|
|
|
|
|
getAllSharedAlbums() async {
|
2022-06-21 22:23:35 -07:00
|
|
|
List<SharedAlbum> sharedAlbums =
|
|
|
|
await _sharedAlbumService.getAllSharedAlbum();
|
2022-04-23 19:08:45 -07: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-21 22:23:35 -07:00
|
|
|
Future<bool> removeAssetFromAlbum(
|
|
|
|
String albumId, List<String> assetIds) async {
|
2022-04-23 19:08:45 -07:00
|
|
|
var res = await _sharedAlbumService.removeAssetFromAlbum(albumId, assetIds);
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-21 22:23:35 -07:00
|
|
|
final sharedAlbumProvider =
|
|
|
|
StateNotifierProvider<SharedAlbumNotifier, List<SharedAlbum>>((ref) {
|
2022-06-25 11:46:51 -07:00
|
|
|
return SharedAlbumNotifier(ref.watch(sharedAlbumServiceProvider));
|
2022-04-23 19:08:45 -07:00
|
|
|
});
|
|
|
|
|
2022-06-21 22:23:35 -07:00
|
|
|
final sharedAlbumDetailProvider = FutureProvider.autoDispose
|
|
|
|
.family<SharedAlbum, String>((ref, albumId) async {
|
2022-06-25 11:46:51 -07:00
|
|
|
final SharedAlbumService sharedAlbumService =
|
|
|
|
ref.watch(sharedAlbumServiceProvider);
|
2022-04-23 19:08:45 -07:00
|
|
|
|
2022-06-21 22:23:35 -07:00
|
|
|
return await sharedAlbumService.getAlbumDetail(albumId);
|
2022-04-23 19:08:45 -07:00
|
|
|
});
|