2023-10-22 17:05:10 +02:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2024-05-01 04:36:40 +02:00
|
|
|
import 'package:immich_mobile/models/shared_link/shared_link.model.dart';
|
2023-10-22 17:05:10 +02:00
|
|
|
import 'package:immich_mobile/modules/shared_link/services/shared_link.service.dart';
|
|
|
|
|
|
|
|
class SharedLinksNotifier extends StateNotifier<AsyncValue<List<SharedLink>>> {
|
|
|
|
final SharedLinkService _sharedLinkService;
|
|
|
|
|
|
|
|
SharedLinksNotifier(this._sharedLinkService) : super(const AsyncLoading()) {
|
|
|
|
fetchLinks();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> fetchLinks() async {
|
|
|
|
state = await _sharedLinkService.getAllSharedLinks();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> deleteLink(String id) async {
|
|
|
|
await _sharedLinkService.deleteSharedLink(id);
|
|
|
|
state = const AsyncLoading();
|
|
|
|
fetchLinks();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
final sharedLinksStateProvider =
|
|
|
|
StateNotifierProvider<SharedLinksNotifier, AsyncValue<List<SharedLink>>>(
|
|
|
|
(ref) {
|
|
|
|
return SharedLinksNotifier(
|
|
|
|
ref.watch(sharedLinkServiceProvider),
|
|
|
|
);
|
|
|
|
});
|