- Upgrade flutter_riverpod to 3.1.0, riverpod_annotation to 4.0.0 - Upgrade freezed to 3.2.3, freezed_annotation to 3.1.0 - Migrate freezed classes to use sealed keyword (freezed 3.x) - Update provider naming (*NotifierProvider → *Provider) - Add legacy.dart import for StateNotifierProvider compatibility - Fix valueOrNull → value for AsyncValue - Remove unused imports and fields - Add sync from Authentik button to users/groups pages - Suppress invalid_annotation_target warning in analysis_options 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
92 lines
2.7 KiB
Dart
92 lines
2.7 KiB
Dart
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
import 'package:tatlock_ui/features/control_room/stacks/data/repositories/stack_repository_impl.dart';
|
|
import 'package:tatlock_ui/features/control_room/stacks/domain/entities/stack.dart';
|
|
|
|
part 'stacks_provider.g.dart';
|
|
|
|
/// Provides the list of all stacks.
|
|
@riverpod
|
|
Future<List<Stack>> stacks(Ref ref) async {
|
|
final repository = ref.watch(stackRepositoryProvider);
|
|
return repository.getStacks();
|
|
}
|
|
|
|
/// Provides a single stack by ID.
|
|
@riverpod
|
|
Future<Stack> stack(Ref ref, String id) async {
|
|
final repository = ref.watch(stackRepositoryProvider);
|
|
return repository.getStack(id);
|
|
}
|
|
|
|
/// Currently selected stack ID (null = all containers).
|
|
@riverpod
|
|
class SelectedStack extends _$SelectedStack {
|
|
@override
|
|
String? build() => null;
|
|
|
|
void select(String? stackId) {
|
|
state = stackId;
|
|
}
|
|
|
|
void clear() {
|
|
state = null;
|
|
}
|
|
}
|
|
|
|
/// Provides the YAML content for a stack.
|
|
@riverpod
|
|
Future<String> stackYaml(Ref ref, String stackId) async {
|
|
final repository = ref.watch(stackRepositoryProvider);
|
|
return repository.getStackYaml(stackId);
|
|
}
|
|
|
|
/// Provides the environment variables for a stack.
|
|
@riverpod
|
|
Future<Map<String, String>> stackEnvVars(Ref ref, String stackId) async {
|
|
final repository = ref.watch(stackRepositoryProvider);
|
|
return repository.getStackEnvVars(stackId);
|
|
}
|
|
|
|
/// Controller for stack configuration actions.
|
|
@riverpod
|
|
class StackConfigActions extends _$StackConfigActions {
|
|
@override
|
|
AsyncValue<void> build() => const AsyncValue.data(null);
|
|
|
|
Future<void> saveYaml(String stackId, String yaml) async {
|
|
state = const AsyncValue.loading();
|
|
state = await AsyncValue.guard(() async {
|
|
final repository = ref.read(stackRepositoryProvider);
|
|
await repository.updateStackYaml(stackId, yaml);
|
|
ref.invalidate(stackYamlProvider(stackId));
|
|
});
|
|
}
|
|
|
|
Future<void> saveEnvVars(String stackId, Map<String, String> envVars) async {
|
|
state = const AsyncValue.loading();
|
|
state = await AsyncValue.guard(() async {
|
|
final repository = ref.read(stackRepositoryProvider);
|
|
await repository.updateStackEnvVars(stackId, envVars);
|
|
ref.invalidate(stackEnvVarsProvider(stackId));
|
|
});
|
|
}
|
|
|
|
Future<void> deploy(String stackId) async {
|
|
state = const AsyncValue.loading();
|
|
state = await AsyncValue.guard(() async {
|
|
final repository = ref.read(stackRepositoryProvider);
|
|
await repository.deployStack(stackId);
|
|
ref.invalidate(stacksProvider);
|
|
});
|
|
}
|
|
|
|
Future<void> rebuild(String stackId) async {
|
|
state = const AsyncValue.loading();
|
|
state = await AsyncValue.guard(() async {
|
|
final repository = ref.read(stackRepositoryProvider);
|
|
await repository.rebuildStack(stackId);
|
|
ref.invalidate(stacksProvider);
|
|
});
|
|
}
|
|
}
|