2025-07-15 20:37:44 -05:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
|
import 'package:immich_mobile/domain/models/album/album.model.dart';
|
|
|
|
|
import 'package:immich_mobile/providers/infrastructure/album.provider.dart';
|
|
|
|
|
|
2025-10-28 11:52:01 -05:00
|
|
|
final currentRemoteAlbumScopedProvider = Provider<RemoteAlbum?>((ref) => null);
|
|
|
|
|
final currentRemoteAlbumProvider = NotifierProvider<CurrentAlbumNotifier, RemoteAlbum?>(
|
2025-07-15 20:37:44 -05:00
|
|
|
CurrentAlbumNotifier.new,
|
2025-10-28 11:52:01 -05:00
|
|
|
dependencies: [currentRemoteAlbumScopedProvider, remoteAlbumServiceProvider],
|
2025-07-15 20:37:44 -05:00
|
|
|
);
|
|
|
|
|
|
2025-10-28 11:52:01 -05:00
|
|
|
class CurrentAlbumNotifier extends Notifier<RemoteAlbum?> {
|
2025-07-15 20:37:44 -05:00
|
|
|
@override
|
2025-10-28 11:52:01 -05:00
|
|
|
RemoteAlbum? build() {
|
|
|
|
|
final album = ref.watch(currentRemoteAlbumScopedProvider);
|
2025-07-15 20:37:44 -05:00
|
|
|
|
2025-10-28 11:52:01 -05:00
|
|
|
if (album == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2025-07-15 20:37:44 -05:00
|
|
|
|
2025-10-28 11:52:01 -05:00
|
|
|
final watcher = ref.watch(remoteAlbumServiceProvider).watchAlbum(album.id).listen((updatedAlbum) {
|
2025-07-15 20:37:44 -05:00
|
|
|
if (updatedAlbum != null) {
|
|
|
|
|
state = updatedAlbum;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2025-10-28 11:52:01 -05:00
|
|
|
ref.onDispose(watcher.cancel);
|
|
|
|
|
|
|
|
|
|
return album;
|
2025-07-15 20:37:44 -05:00
|
|
|
}
|
|
|
|
|
}
|