From 3e158d582bda15b69196a4dac7bda19d9f402092 Mon Sep 17 00:00:00 2001 From: Omar Selo Date: Mon, 14 Oct 2024 17:58:13 +0300 Subject: [PATCH] Fix progress not changing when reviewing an environment --- frontend/lib/providers/artefact.dart | 2 +- .../lib/providers/review_environment.dart | 38 +++++++++++++++++++ .../environment_review_pop_over.dart | 10 ++--- 3 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 frontend/lib/providers/review_environment.dart diff --git a/frontend/lib/providers/artefact.dart b/frontend/lib/providers/artefact.dart index 3392a762..a5ac6059 100644 --- a/frontend/lib/providers/artefact.dart +++ b/frontend/lib/providers/artefact.dart @@ -22,7 +22,7 @@ class Artefact extends _$Artefact { state = AsyncData(artefact); } - Future updatecompletedEnvironmentReviewsCount(int count) async { + Future updateCompletedEnvironmentReviewsCount(int count) async { final artefact = await future; state = AsyncData(artefact.copyWith(completedEnvironmentReviewsCount: count)); diff --git a/frontend/lib/providers/review_environment.dart b/frontend/lib/providers/review_environment.dart new file mode 100644 index 00000000..8aa6af71 --- /dev/null +++ b/frontend/lib/providers/review_environment.dart @@ -0,0 +1,38 @@ +import 'package:riverpod_annotation/riverpod_annotation.dart'; + +import '../models/environment_review.dart'; +import 'artefact.dart'; +import 'artefact_environment_reviews.dart'; + +part 'review_environment.g.dart'; + +@riverpod +class ReviewEnvironment extends _$ReviewEnvironment { + @override + Future build() async { + return; + } + + Future review( + EnvironmentReview review, + int artefactId, + ) async { + await ref + .read(artefactEnvironmentReviewsProvider(artefactId).notifier) + .updateReview(review); + + final environmentReviews = + await ref.read(artefactEnvironmentReviewsProvider(artefactId).future); + + final newCompletedEnvironmentReviewsCount = environmentReviews.fold( + 0, + (count, review) => count + (review.reviewDecision.isEmpty ? 0 : 1), + ); + + await ref + .read(artefactProvider(artefactId).notifier) + .updateCompletedEnvironmentReviewsCount( + newCompletedEnvironmentReviewsCount, + ); + } +} diff --git a/frontend/lib/ui/artefact_page/environment_review_pop_over.dart b/frontend/lib/ui/artefact_page/environment_review_pop_over.dart index 98baab04..eeaab6a5 100644 --- a/frontend/lib/ui/artefact_page/environment_review_pop_over.dart +++ b/frontend/lib/ui/artefact_page/environment_review_pop_over.dart @@ -3,7 +3,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:yaru/widgets.dart'; import '../../models/environment_review.dart'; -import '../../providers/artefact_environment_reviews.dart'; +import '../../providers/review_environment.dart'; import '../spacing.dart'; import '../vanilla/vanilla_text_input.dart'; @@ -110,16 +110,12 @@ class EnvironmentReviewPopOverState const SizedBox(height: Spacing.level3), ElevatedButton( onPressed: () { - ref - .read( - artefactEnvironmentReviewsProvider(widget.artefactId) - .notifier, - ) - .updateReview( + ref.read(reviewEnvironmentProvider.notifier).review( widget.environmentReview.copyWith( reviewDecision: reviewDecisions, reviewComment: reviewCommentController.text, ), + widget.artefactId, ); Navigator.pop(context); },