2022-04-29 06:46:37 +02:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2024-05-01 04:36:40 +02:00
|
|
|
import 'package:immich_mobile/models/albums/album_viewer_page_state.model.dart';
|
2024-05-02 22:59:14 +02:00
|
|
|
import 'package:immich_mobile/providers/album/shared_album.provider.dart';
|
|
|
|
import 'package:immich_mobile/services/album.service.dart';
|
2024-05-01 04:36:40 +02:00
|
|
|
import 'package:immich_mobile/entities/album.entity.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(
|
2023-02-06 09:13:32 +02:00
|
|
|
Album album,
|
2022-07-13 14:23:48 +02:00
|
|
|
String newAlbumTitle,
|
|
|
|
) async {
|
2022-08-03 07:04:34 +02:00
|
|
|
AlbumService service = ref.watch(albumServiceProvider);
|
2022-04-29 06:46:37 +02:00
|
|
|
|
2023-02-06 09:13:32 +02:00
|
|
|
bool isSuccess = await service.changeTitleAlbum(album, 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);
|
|
|
|
});
|