new: add json editor and editing configs <3
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import 'package:hiddify/core/database/database_provider.dart';
|
||||
import 'package:hiddify/core/directories/directories_provider.dart';
|
||||
import 'package:hiddify/core/http_client/http_client_provider.dart';
|
||||
import 'package:hiddify/features/config_option/data/config_option_data_providers.dart';
|
||||
import 'package:hiddify/features/config_option/notifier/config_option_notifier.dart';
|
||||
import 'package:hiddify/features/profile/data/profile_data_source.dart';
|
||||
import 'package:hiddify/features/profile/data/profile_path_resolver.dart';
|
||||
import 'package:hiddify/features/profile/data/profile_repository.dart';
|
||||
@@ -15,6 +17,7 @@ Future<ProfileRepository> profileRepository(ProfileRepositoryRef ref) async {
|
||||
profileDataSource: ref.watch(profileDataSourceProvider),
|
||||
profilePathResolver: ref.watch(profilePathResolverProvider),
|
||||
singbox: ref.watch(singboxServiceProvider),
|
||||
configOptionRepository: ref.watch(configOptionRepositoryProvider),
|
||||
httpClient: ref.watch(httpClientProvider),
|
||||
);
|
||||
await repo.init().getOrElse((l) => throw l).run();
|
||||
|
||||
@@ -6,6 +6,8 @@ import 'package:fpdart/fpdart.dart';
|
||||
import 'package:hiddify/core/database/app_database.dart';
|
||||
import 'package:hiddify/core/http_client/dio_http_client.dart';
|
||||
import 'package:hiddify/core/utils/exception_handler.dart';
|
||||
import 'package:hiddify/features/config_option/data/config_option_repository.dart';
|
||||
import 'package:hiddify/features/connection/model/connection_failure.dart';
|
||||
import 'package:hiddify/features/profile/data/profile_data_mapper.dart';
|
||||
import 'package:hiddify/features/profile/data/profile_data_source.dart';
|
||||
import 'package:hiddify/features/profile/data/profile_parser.dart';
|
||||
@@ -36,7 +38,10 @@ abstract interface class ProfileRepository {
|
||||
bool markAsActive = false,
|
||||
CancelToken? cancelToken,
|
||||
});
|
||||
|
||||
TaskEither<ProfileFailure, Unit> updateContent(
|
||||
String profileId,
|
||||
String content,
|
||||
);
|
||||
TaskEither<ProfileFailure, Unit> addByContent(
|
||||
String content, {
|
||||
required String name,
|
||||
@@ -67,12 +72,14 @@ class ProfileRepositoryImpl with ExceptionHandler, InfraLogger implements Profil
|
||||
required this.profileDataSource,
|
||||
required this.profilePathResolver,
|
||||
required this.singbox,
|
||||
required this.configOptionRepository,
|
||||
required this.httpClient,
|
||||
});
|
||||
|
||||
final ProfileDataSource profileDataSource;
|
||||
final ProfilePathResolver profilePathResolver;
|
||||
final SingboxService singbox;
|
||||
final ConfigOptionRepository configOptionRepository;
|
||||
final DioHttpClient httpClient;
|
||||
|
||||
@override
|
||||
@@ -177,6 +184,30 @@ class ProfileRepositoryImpl with ExceptionHandler, InfraLogger implements Profil
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
TaskEither<ProfileFailure, Unit> updateContent(
|
||||
String profileId,
|
||||
String content,
|
||||
) {
|
||||
return exceptionHandler(
|
||||
() async {
|
||||
final file = profilePathResolver.file(profileId);
|
||||
final tempFile = profilePathResolver.tempFile(profileId);
|
||||
|
||||
try {
|
||||
await tempFile.writeAsString(content);
|
||||
return await validateConfig(file.path, tempFile.path, false).run();
|
||||
} finally {
|
||||
if (tempFile.existsSync()) tempFile.deleteSync();
|
||||
}
|
||||
},
|
||||
(error, stackTrace) {
|
||||
loggy.warning("error adding profile by content", error, stackTrace);
|
||||
return ProfileUnexpectedFailure(error, stackTrace);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
TaskEither<ProfileFailure, Unit> addByContent(
|
||||
String content, {
|
||||
@@ -186,28 +217,22 @@ class ProfileRepositoryImpl with ExceptionHandler, InfraLogger implements Profil
|
||||
return exceptionHandler(
|
||||
() async {
|
||||
final profileId = const Uuid().v4();
|
||||
final file = profilePathResolver.file(profileId);
|
||||
final tempFile = profilePathResolver.tempFile(profileId);
|
||||
|
||||
try {
|
||||
await tempFile.writeAsString(content);
|
||||
return await validateConfig(file.path, tempFile.path, false)
|
||||
.andThen(
|
||||
() => TaskEither(() async {
|
||||
final profile = LocalProfileEntity(
|
||||
id: profileId,
|
||||
active: markAsActive,
|
||||
name: name,
|
||||
lastUpdate: DateTime.now(),
|
||||
);
|
||||
await profileDataSource.insert(profile.toEntry());
|
||||
return right(unit);
|
||||
}),
|
||||
)
|
||||
.run();
|
||||
} finally {
|
||||
if (tempFile.existsSync()) tempFile.deleteSync();
|
||||
}
|
||||
return await updateContent(profileId, content)
|
||||
.andThen(
|
||||
() => TaskEither(() async {
|
||||
final profile = LocalProfileEntity(
|
||||
id: profileId,
|
||||
active: markAsActive,
|
||||
name: name,
|
||||
lastUpdate: DateTime.now(),
|
||||
);
|
||||
await profileDataSource.insert(profile.toEntry());
|
||||
|
||||
return right(unit);
|
||||
}),
|
||||
)
|
||||
.run();
|
||||
},
|
||||
(error, stackTrace) {
|
||||
loggy.warning("error adding profile by content", error, stackTrace);
|
||||
@@ -252,6 +277,10 @@ class ProfileRepositoryImpl with ExceptionHandler, InfraLogger implements Profil
|
||||
($) async {
|
||||
final configFile = profilePathResolver.file(id);
|
||||
// TODO pass options
|
||||
final options = await configOptionRepository.getConfigOptions();
|
||||
|
||||
singbox.changeOptions(options).mapLeft(InvalidConfigOption.new).run();
|
||||
|
||||
return await $(
|
||||
singbox.generateFullConfigByPath(configFile.path).mapLeft(ProfileFailure.unexpected),
|
||||
);
|
||||
|
||||
1330
lib/features/profile/details/json_editor.dart
Normal file
1330
lib/features/profile/details/json_editor.dart
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,5 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import 'package:hiddify/features/profile/data/profile_data_providers.dart';
|
||||
@@ -36,22 +38,53 @@ class ProfileDetailsNotifier extends _$ProfileDetailsNotifier with AppLogger {
|
||||
loggy.warning('failed to load profile', err);
|
||||
throw err;
|
||||
},
|
||||
(profile) {
|
||||
(profile) async {
|
||||
if (profile == null) {
|
||||
loggy.warning('profile with id: [$id] does not exist');
|
||||
throw const ProfileNotFoundFailure();
|
||||
}
|
||||
|
||||
_originalProfile = profile;
|
||||
return ProfileDetailsState(profile: profile, isEditing: true);
|
||||
final result = await _profilesRepo.generateConfig(id).run();
|
||||
|
||||
var configContent = result.fold(
|
||||
(failure) => throw Exception('Failed to generate config: $failure'),
|
||||
(config) => config,
|
||||
);
|
||||
if (configContent.isNotEmpty) {
|
||||
try {
|
||||
final jsonObject = jsonDecode(configContent);
|
||||
List<Map<String, dynamic>> res = [];
|
||||
if (jsonObject is Map<String, dynamic> && jsonObject['outbounds'] is List) {
|
||||
for (var outbound in jsonObject['outbounds'] as List<dynamic>) {
|
||||
if (outbound is Map<String, dynamic> && outbound['type'] != null && !['selector', 'urltest', 'dns', 'block'].contains(outbound['type']) && !['direct', 'bypass', 'direct-fragment'].contains(outbound['tag'])) {
|
||||
res.add(outbound);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// print('No outbounds found in the config');
|
||||
}
|
||||
configContent = '{"outbounds": ${json.encode(res)}}';
|
||||
} catch (e) {
|
||||
// print('Error parsing JSON: $e');
|
||||
}
|
||||
} else {
|
||||
// print('Config content is null or empty');
|
||||
}
|
||||
return ProfileDetailsState(profile: profile, isEditing: true, configContent: configContent);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
ProfileRepository get _profilesRepo =>
|
||||
ref.read(profileRepositoryProvider).requireValue;
|
||||
ProfileRepository get _profilesRepo => ref.read(profileRepositoryProvider).requireValue;
|
||||
ProfileEntity? _originalProfile;
|
||||
|
||||
void setField({String? name, String? url, Option<int>? updateInterval}) {
|
||||
void setField({
|
||||
String? name,
|
||||
String? url,
|
||||
Option<int>? updateInterval,
|
||||
String? configContent,
|
||||
}) {
|
||||
if (state case AsyncData(:final value)) {
|
||||
state = AsyncData(
|
||||
value.copyWith(
|
||||
@@ -70,6 +103,8 @@ class ProfileDetailsNotifier extends _$ProfileDetailsNotifier with AppLogger {
|
||||
),
|
||||
local: (lp) => lp.copyWith(name: name ?? lp.name),
|
||||
),
|
||||
configContentChanged: value.configContentChanged || value.configContent != configContent,
|
||||
configContent: configContent ?? value.configContent,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -91,15 +126,28 @@ class ProfileDetailsNotifier extends _$ProfileDetailsNotifier with AppLogger {
|
||||
if (profile.name.isBlank || profile.url.isBlank) {
|
||||
loggy.debug('save: invalid arguments');
|
||||
} else if (value.isEditing) {
|
||||
if (_originalProfile case RemoteProfileEntity(:final url)
|
||||
when url == profile.url) {
|
||||
if (_originalProfile case RemoteProfileEntity(:final url) when url == profile.url) {
|
||||
loggy.debug('editing profile');
|
||||
failureOrSuccess = await _profilesRepo.patch(profile).run();
|
||||
if (failureOrSuccess.isRight()) {
|
||||
failureOrSuccess = await _profilesRepo
|
||||
.updateContent(
|
||||
profile.id,
|
||||
value.configContent,
|
||||
)
|
||||
.run();
|
||||
}
|
||||
} else {
|
||||
loggy.debug('updating profile');
|
||||
failureOrSuccess = await _profilesRepo
|
||||
.updateSubscription(profile, patchBaseProfile: true)
|
||||
.run();
|
||||
failureOrSuccess = await _profilesRepo.updateSubscription(profile, patchBaseProfile: true).run();
|
||||
if (failureOrSuccess.isRight()) {
|
||||
failureOrSuccess = await _profilesRepo
|
||||
.updateContent(
|
||||
profile.id,
|
||||
value.configContent,
|
||||
)
|
||||
.run();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
loggy.debug('adding profile, url: [${profile.url}]');
|
||||
@@ -138,10 +186,7 @@ class ProfileDetailsNotifier extends _$ProfileDetailsNotifier with AppLogger {
|
||||
final profile = value.profile;
|
||||
state = AsyncData(value.copyWith(update: const AsyncLoading()));
|
||||
|
||||
final failureOrUpdatedProfile = await _profilesRepo
|
||||
.updateSubscription(profile as RemoteProfileEntity)
|
||||
.flatMap((_) => _profilesRepo.getById(id))
|
||||
.run();
|
||||
final failureOrUpdatedProfile = await _profilesRepo.updateSubscription(profile as RemoteProfileEntity).flatMap((_) => _profilesRepo.getById(id)).run();
|
||||
|
||||
state = AsyncData(
|
||||
value.copyWith(
|
||||
@@ -167,10 +212,7 @@ class ProfileDetailsNotifier extends _$ProfileDetailsNotifier with AppLogger {
|
||||
state = AsyncData(
|
||||
value.copyWith(
|
||||
delete: await AsyncValue.guard(() async {
|
||||
await _profilesRepo
|
||||
.deleteById(profile.id)
|
||||
.getOrElse((l) => throw l)
|
||||
.run();
|
||||
await _profilesRepo.deleteById(profile.id).getOrElse((l) => throw l).run();
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:fluentui_system_icons/fluentui_system_icons.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
@@ -7,12 +9,17 @@ import 'package:hiddify/core/localization/translations.dart';
|
||||
import 'package:hiddify/core/model/failures.dart';
|
||||
import 'package:hiddify/core/widget/adaptive_icon.dart';
|
||||
import 'package:hiddify/features/common/confirmation_dialogs.dart';
|
||||
import 'package:hiddify/features/profile/details/json_editor.dart';
|
||||
import 'package:hiddify/features/profile/details/profile_details_notifier.dart';
|
||||
import 'package:hiddify/features/profile/model/profile_entity.dart';
|
||||
import 'package:hiddify/features/settings/widgets/widgets.dart';
|
||||
import 'package:hiddify/utils/utils.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:humanizer/humanizer.dart';
|
||||
// import 'package:lucy_editor/lucy_editor.dart';
|
||||
// import 'package:re_highlight/languages/json.dart';
|
||||
// import 'package:re_highlight/styles/atom-one-light.dart';
|
||||
// import 'package:json_editor_flutter/json_editor_flutter.dart';
|
||||
|
||||
class ProfileDetailsPage extends HookConsumerWidget with PresLogger {
|
||||
const ProfileDetailsPage(this.id, {super.key});
|
||||
@@ -39,14 +46,12 @@ class ProfileDetailsPage extends HookConsumerWidget with PresLogger {
|
||||
);
|
||||
case AsyncError(:final error):
|
||||
final String action;
|
||||
if (ref.read(provider) case AsyncData(value: final data)
|
||||
when data.isEditing) {
|
||||
if (ref.read(provider) case AsyncData(value: final data) when data.isEditing) {
|
||||
action = t.profile.save.failureMsg;
|
||||
} else {
|
||||
action = t.profile.add.failureMsg;
|
||||
}
|
||||
CustomAlertDialog.fromErr(t.presentError(error, action: action))
|
||||
.show(context);
|
||||
CustomAlertDialog.fromErr(t.presentError(error, action: action)).show(context);
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -82,9 +87,7 @@ class ProfileDetailsPage extends HookConsumerWidget with PresLogger {
|
||||
|
||||
switch (ref.watch(provider)) {
|
||||
case AsyncData(value: final state):
|
||||
final showLoadingOverlay = state.isBusy ||
|
||||
state.save is MutationSuccess ||
|
||||
state.delete is MutationSuccess;
|
||||
final showLoadingOverlay = state.isBusy || state.save is MutationSuccess || state.delete is MutationSuccess;
|
||||
|
||||
return Stack(
|
||||
children: [
|
||||
@@ -96,6 +99,16 @@ class ProfileDetailsPage extends HookConsumerWidget with PresLogger {
|
||||
title: Text(t.profile.detailsPageTitle),
|
||||
pinned: true,
|
||||
actions: [
|
||||
// MenuItemButton(
|
||||
// onPressed: context.pop,
|
||||
// child: Text(
|
||||
// MaterialLocalizations.of(context).cancelButtonLabel,
|
||||
// ),
|
||||
// ),
|
||||
MenuItemButton(
|
||||
onPressed: notifier.save,
|
||||
child: Text(t.profile.save.buttonText),
|
||||
),
|
||||
if (state.isEditing)
|
||||
PopupMenuButton(
|
||||
icon: Icon(AdaptiveIcon(context).more),
|
||||
@@ -111,8 +124,7 @@ class ProfileDetailsPage extends HookConsumerWidget with PresLogger {
|
||||
PopupMenuItem(
|
||||
child: Text(t.profile.delete.buttonTxt),
|
||||
onTap: () async {
|
||||
final deleteConfirmed =
|
||||
await showConfirmationDialog(
|
||||
final deleteConfirmed = await showConfirmationDialog(
|
||||
context,
|
||||
title: t.profile.delete.buttonTxt,
|
||||
message: t.profile.delete.confirmationMsg,
|
||||
@@ -129,9 +141,7 @@ class ProfileDetailsPage extends HookConsumerWidget with PresLogger {
|
||||
],
|
||||
),
|
||||
Form(
|
||||
autovalidateMode: state.showErrorMessages
|
||||
? AutovalidateMode.always
|
||||
: AutovalidateMode.disabled,
|
||||
autovalidateMode: state.showErrorMessages ? AutovalidateMode.always : AutovalidateMode.disabled,
|
||||
child: SliverList.list(
|
||||
children: [
|
||||
Padding(
|
||||
@@ -141,20 +151,13 @@ class ProfileDetailsPage extends HookConsumerWidget with PresLogger {
|
||||
),
|
||||
child: CustomTextFormField(
|
||||
initialValue: state.profile.name,
|
||||
onChanged: (value) =>
|
||||
notifier.setField(name: value),
|
||||
validator: (value) => (value?.isEmpty ?? true)
|
||||
? t.profile.detailsForm.emptyNameMsg
|
||||
: null,
|
||||
onChanged: (value) => notifier.setField(name: value),
|
||||
validator: (value) => (value?.isEmpty ?? true) ? t.profile.detailsForm.emptyNameMsg : null,
|
||||
label: t.profile.detailsForm.nameLabel,
|
||||
hint: t.profile.detailsForm.nameHint,
|
||||
),
|
||||
),
|
||||
if (state.profile
|
||||
case RemoteProfileEntity(
|
||||
:final url,
|
||||
:final options
|
||||
)) ...[
|
||||
if (state.profile case RemoteProfileEntity(:final url, :final options)) ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
@@ -162,12 +165,8 @@ class ProfileDetailsPage extends HookConsumerWidget with PresLogger {
|
||||
),
|
||||
child: CustomTextFormField(
|
||||
initialValue: url,
|
||||
onChanged: (value) =>
|
||||
notifier.setField(url: value),
|
||||
validator: (value) =>
|
||||
(value != null && !isUrl(value))
|
||||
? t.profile.detailsForm.invalidUrlMsg
|
||||
: null,
|
||||
onChanged: (value) => notifier.setField(url: value),
|
||||
validator: (value) => (value != null && !isUrl(value)) ? t.profile.detailsForm.invalidUrlMsg : null,
|
||||
label: t.profile.detailsForm.urlLabel,
|
||||
hint: t.profile.detailsForm.urlHint,
|
||||
),
|
||||
@@ -180,13 +179,10 @@ class ProfileDetailsPage extends HookConsumerWidget with PresLogger {
|
||||
) ??
|
||||
t.general.toggle.disabled,
|
||||
),
|
||||
leading:
|
||||
const Icon(FluentIcons.arrow_sync_24_regular),
|
||||
leading: const Icon(FluentIcons.arrow_sync_24_regular),
|
||||
onTap: () async {
|
||||
final intervalInHours =
|
||||
await SettingsInputDialog(
|
||||
title: t.profile.detailsForm
|
||||
.updateIntervalDialogTitle,
|
||||
final intervalInHours = await SettingsInputDialog(
|
||||
title: t.profile.detailsForm.updateIntervalDialogTitle,
|
||||
initialValue: options?.updateInterval.inHours,
|
||||
optionalAction: (
|
||||
t.general.state.disable,
|
||||
@@ -205,17 +201,28 @@ class ProfileDetailsPage extends HookConsumerWidget with PresLogger {
|
||||
},
|
||||
),
|
||||
],
|
||||
// Padding(
|
||||
// padding: const EdgeInsets.symmetric(
|
||||
// horizontal: 16,
|
||||
// vertical: 8,
|
||||
// ),
|
||||
// child: CustomTextFormField(
|
||||
// initialValue: state.configContent,
|
||||
// // onChanged: (value) => notifier.setField(name: value),
|
||||
// maxLines: 7,
|
||||
// label: t.profile.detailsForm.configContentLabel,
|
||||
// hint: t.profile.detailsForm.configContentHint,
|
||||
// ),
|
||||
// ),
|
||||
if (state.isEditing) ...[
|
||||
ListTile(
|
||||
title: Text(t.profile.detailsForm.lastUpdate),
|
||||
leading:
|
||||
const Icon(FluentIcons.history_24_regular),
|
||||
leading: const Icon(FluentIcons.history_24_regular),
|
||||
subtitle: Text(state.profile.lastUpdate.format()),
|
||||
dense: true,
|
||||
),
|
||||
],
|
||||
if (state.profile
|
||||
case RemoteProfileEntity(:final subInfo?)) ...[
|
||||
if (state.profile case RemoteProfileEntity(:final subInfo?)) ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 18,
|
||||
@@ -225,8 +232,7 @@ class ProfileDetailsPage extends HookConsumerWidget with PresLogger {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text.rich(
|
||||
style:
|
||||
Theme.of(context).textTheme.bodySmall,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
TextSpan(
|
||||
children: [
|
||||
_buildSubProp(
|
||||
@@ -242,8 +248,7 @@ class ProfileDetailsPage extends HookConsumerWidget with PresLogger {
|
||||
),
|
||||
const TextSpan(text: " "),
|
||||
_buildSubProp(
|
||||
FluentIcons
|
||||
.arrow_bidirectional_up_down_16_regular,
|
||||
FluentIcons.arrow_bidirectional_up_down_16_regular,
|
||||
subInfo.total.size(),
|
||||
t.profile.subscription.total,
|
||||
),
|
||||
@@ -252,8 +257,7 @@ class ProfileDetailsPage extends HookConsumerWidget with PresLogger {
|
||||
),
|
||||
const Gap(12),
|
||||
Text.rich(
|
||||
style:
|
||||
Theme.of(context).textTheme.bodySmall,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
TextSpan(
|
||||
children: [
|
||||
_buildSubProp(
|
||||
@@ -268,39 +272,23 @@ class ProfileDetailsPage extends HookConsumerWidget with PresLogger {
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
SliverFillRemaining(
|
||||
hasScrollBody: false,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 16,
|
||||
),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
OverflowBar(
|
||||
spacing: 12,
|
||||
overflowAlignment: OverflowBarAlignment.end,
|
||||
children: [
|
||||
OutlinedButton(
|
||||
onPressed: context.pop,
|
||||
child: Text(
|
||||
MaterialLocalizations.of(context)
|
||||
.cancelButtonLabel,
|
||||
),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: notifier.save,
|
||||
child: Text(t.profile.save.buttonText),
|
||||
),
|
||||
],
|
||||
if (state.isEditing) ...[
|
||||
SizedBox(
|
||||
height: MediaQuery.of(context).size.height * 0.8,
|
||||
child: JsonEditor(
|
||||
expandedObjects: const ["outbounds"],
|
||||
onChanged: (value) {
|
||||
if (value == null) return;
|
||||
const encoder = const JsonEncoder.withIndent(' ');
|
||||
|
||||
notifier.setField(configContent: encoder.convert(value));
|
||||
},
|
||||
enableHorizontalScroll: true,
|
||||
json: state.configContent,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -15,8 +15,9 @@ class ProfileDetailsState with _$ProfileDetailsState {
|
||||
AsyncValue<void>? save,
|
||||
AsyncValue<void>? update,
|
||||
AsyncValue<void>? delete,
|
||||
@Default("") String configContent,
|
||||
@Default(false) bool configContentChanged,
|
||||
}) = _ProfileDetailsState;
|
||||
|
||||
bool get isBusy =>
|
||||
save is AsyncLoading || delete is AsyncLoading || update is AsyncLoading;
|
||||
bool get isBusy => save is AsyncLoading || delete is AsyncLoading || update is AsyncLoading;
|
||||
}
|
||||
|
||||
@@ -13,37 +13,26 @@ import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
part 'profiles_overview_notifier.g.dart';
|
||||
|
||||
@riverpod
|
||||
class ProfilesOverviewSortNotifier extends _$ProfilesOverviewSortNotifier
|
||||
with AppLogger {
|
||||
class ProfilesOverviewSortNotifier extends _$ProfilesOverviewSortNotifier with AppLogger {
|
||||
@override
|
||||
({ProfilesSort by, SortMode mode}) build() {
|
||||
return (by: ProfilesSort.lastUpdate, mode: SortMode.descending);
|
||||
}
|
||||
|
||||
void changeSort(ProfilesSort sortBy) =>
|
||||
state = (by: sortBy, mode: state.mode);
|
||||
void changeSort(ProfilesSort sortBy) => state = (by: sortBy, mode: state.mode);
|
||||
|
||||
void toggleMode() => state = (
|
||||
by: state.by,
|
||||
mode: state.mode == SortMode.ascending
|
||||
? SortMode.descending
|
||||
: SortMode.ascending
|
||||
);
|
||||
void toggleMode() => state = (by: state.by, mode: state.mode == SortMode.ascending ? SortMode.descending : SortMode.ascending);
|
||||
}
|
||||
|
||||
@riverpod
|
||||
class ProfilesOverviewNotifier extends _$ProfilesOverviewNotifier
|
||||
with AppLogger {
|
||||
class ProfilesOverviewNotifier extends _$ProfilesOverviewNotifier with AppLogger {
|
||||
@override
|
||||
Stream<List<ProfileEntity>> build() {
|
||||
final sort = ref.watch(profilesOverviewSortNotifierProvider);
|
||||
return _profilesRepo
|
||||
.watchAll(sort: sort.by, sortMode: sort.mode)
|
||||
.map((event) => event.getOrElse((l) => throw l));
|
||||
return _profilesRepo.watchAll(sort: sort.by, sortMode: sort.mode).map((event) => event.getOrElse((l) => throw l));
|
||||
}
|
||||
|
||||
ProfileRepository get _profilesRepo =>
|
||||
ref.read(profileRepositoryProvider).requireValue;
|
||||
ProfileRepository get _profilesRepo => ref.read(profileRepositoryProvider).requireValue;
|
||||
|
||||
Future<Unit> selectActiveProfile(String id) async {
|
||||
loggy.debug('changing active profile to: [$id]');
|
||||
|
||||
Reference in New Issue
Block a user