2023-10-22 10:05:10 -05:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2024-04-30 21:36:40 -05:00
|
|
|
import 'package:immich_mobile/models/shared_link/shared_link.model.dart';
|
2024-05-02 15:59:14 -05:00
|
|
|
import 'package:immich_mobile/services/shared_link.service.dart';
|
2023-10-22 10:05:10 -05:00
|
|
|
|
|
|
|
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),
|
|
|
|
);
|
|
|
|
});
|