This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:trainhub_flutter/injection.dart';
|
||||
import 'package:trainhub_flutter/domain/entities/annotation.dart';
|
||||
import 'package:trainhub_flutter/domain/repositories/analysis_repository.dart';
|
||||
import 'package:trainhub_flutter/domain/repositories/exercise_repository.dart';
|
||||
import 'package:trainhub_flutter/presentation/analysis/analysis_state.dart';
|
||||
|
||||
part 'analysis_controller.g.dart';
|
||||
@@ -8,10 +10,12 @@ part 'analysis_controller.g.dart';
|
||||
@riverpod
|
||||
class AnalysisController extends _$AnalysisController {
|
||||
late AnalysisRepository _repo;
|
||||
late ExerciseRepository _exerciseRepo;
|
||||
|
||||
@override
|
||||
Future<AnalysisState> build() async {
|
||||
_repo = getIt<AnalysisRepository>();
|
||||
_exerciseRepo = getIt<ExerciseRepository>();
|
||||
final sessions = await _repo.getAllSessions();
|
||||
return AnalysisState(sessions: sessions);
|
||||
}
|
||||
@@ -35,10 +39,7 @@ class AnalysisController extends _$AnalysisController {
|
||||
final annotations = await _repo.getAnnotations(id);
|
||||
final current = state.valueOrNull ?? const AnalysisState();
|
||||
state = AsyncValue.data(
|
||||
current.copyWith(
|
||||
activeSession: session,
|
||||
annotations: annotations,
|
||||
),
|
||||
current.copyWith(activeSession: session, annotations: annotations),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -77,6 +78,34 @@ class AnalysisController extends _$AnalysisController {
|
||||
state = AsyncValue.data(current.copyWith(annotations: annotations));
|
||||
}
|
||||
|
||||
Future<void> updateAnnotation(AnnotationEntity annotation) async {
|
||||
final current = state.valueOrNull;
|
||||
if (current?.activeSession == null) return;
|
||||
await _repo.updateAnnotation(
|
||||
id: annotation.id,
|
||||
name: annotation.name ?? '',
|
||||
description: annotation.description ?? '',
|
||||
color: annotation.color ?? 'grey',
|
||||
);
|
||||
final annotations = await _repo.getAnnotations(current!.activeSession!.id);
|
||||
state = AsyncValue.data(current.copyWith(annotations: annotations));
|
||||
}
|
||||
|
||||
Future<void> createExerciseFromAnnotation({
|
||||
required String name,
|
||||
required String instructions,
|
||||
required String videoPath,
|
||||
required double startTime,
|
||||
required double endTime,
|
||||
}) async {
|
||||
final videoRef = '$videoPath#t=${startTime.toStringAsFixed(2)},${endTime.toStringAsFixed(2)}';
|
||||
await _exerciseRepo.create(
|
||||
name: name,
|
||||
instructions: instructions.isEmpty ? null : instructions,
|
||||
videoUrl: videoRef,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> deleteAnnotation(String id) async {
|
||||
await _repo.deleteAnnotation(id);
|
||||
final current = state.valueOrNull;
|
||||
|
||||
Reference in New Issue
Block a user