2022-04-29 06:46:37 +02:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2022-08-03 07:04:34 +02:00
|
|
|
import 'package:immich_mobile/modules/album/models/album_viewer_page_state.model.dart';
|
|
|
|
import 'package:immich_mobile/modules/album/providers/shared_album.provider.dart';
|
|
|
|
import 'package:immich_mobile/modules/album/services/album.service.dart';
|
2022-04-29 06:46:37 +02:00
|
|
|
|
|
|
|
class AlbumViewerNotifier extends StateNotifier<AlbumViewerPageState> {
|
2022-06-25 20:46:51 +02:00
|
|
|
AlbumViewerNotifier(this.ref)
|
|
|
|
: super(AlbumViewerPageState(editTitleText: "", isEditAlbum: false));
|
2022-04-29 06:46:37 +02:00
|
|
|
|
|
|
|
final Ref ref;
|
|
|
|
|
|
|
|
void enableEditAlbum() {
|
|
|
|
state = state.copyWith(isEditAlbum: true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void disableEditAlbum() {
|
|
|
|
state = state.copyWith(isEditAlbum: false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setEditTitleText(String newTitle) {
|
|
|
|
state = state.copyWith(editTitleText: newTitle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void remoteEditTitleText() {
|
|
|
|
state = state.copyWith(editTitleText: "");
|
|
|
|
}
|
|
|
|
|
|
|
|
void resetState() {
|
|
|
|
state = state.copyWith(editTitleText: "", isEditAlbum: false);
|
|
|
|
}
|
|
|
|
|
2022-06-25 20:46:51 +02:00
|
|
|
Future<bool> changeAlbumTitle(
|
2022-07-13 14:23:48 +02:00
|
|
|
String albumId,
|
|
|
|
String ownerId,
|
|
|
|
String newAlbumTitle,
|
|
|
|
) async {
|
2022-08-03 07:04:34 +02:00
|
|
|
AlbumService service = ref.watch(albumServiceProvider);
|
2022-04-29 06:46:37 +02:00
|
|
|
|
2022-06-25 20:46:51 +02:00
|
|
|
bool isSuccess =
|
|
|
|
await service.changeTitleAlbum(albumId, ownerId, newAlbumTitle);
|
2022-04-29 06:46:37 +02:00
|
|
|
|
|
|
|
if (isSuccess) {
|
|
|
|
state = state.copyWith(editTitleText: "", isEditAlbum: false);
|
|
|
|
ref.read(sharedAlbumProvider.notifier).getAllSharedAlbums();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-04-29 20:10:42 +02:00
|
|
|
state = state.copyWith(editTitleText: "", isEditAlbum: false);
|
2022-04-29 06:46:37 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-25 20:46:51 +02:00
|
|
|
final albumViewerProvider =
|
|
|
|
StateNotifierProvider<AlbumViewerNotifier, AlbumViewerPageState>((ref) {
|
2022-04-29 06:46:37 +02:00
|
|
|
return AlbumViewerNotifier(ref);
|
|
|
|
});
|