Refactor profile addition flow

This commit is contained in:
problematicconsumer
2023-07-26 14:17:11 +03:30
parent cad4e47ee5
commit d741b7a427
13 changed files with 340 additions and 223 deletions

View File

@@ -3,6 +3,7 @@ import 'dart:async';
import 'package:fpdart/fpdart.dart';
import 'package:hiddify/data/data_providers.dart';
import 'package:hiddify/domain/profiles/profiles.dart';
import 'package:hiddify/features/common/active_profile/active_profile_notifier.dart';
import 'package:hiddify/utils/utils.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
@@ -27,6 +28,18 @@ class ProfilesNotifier extends _$ProfilesNotifier with AppLogger {
}).run();
}
Future<Unit> addProfile(String url) async {
final activeProfile = await ref.read(activeProfileProvider.future);
loggy.debug("adding profile, url: [$url]");
return ref
.read(profilesRepositoryProvider)
.addByUrl(url, markAsActive: activeProfile == null)
.getOrElse((l) {
loggy.warning("failed to add profile: $l");
throw l;
}).run();
}
Future<Unit?> updateProfile(Profile profile) async {
loggy.debug("updating profile");
return ref