Skip to content

Commit

Permalink
Fix progress not changing when reviewing an environment
Browse files Browse the repository at this point in the history
  • Loading branch information
omar-selo committed Oct 14, 2024
1 parent c5259ce commit 3e158d5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
2 changes: 1 addition & 1 deletion frontend/lib/providers/artefact.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Artefact extends _$Artefact {
state = AsyncData(artefact);
}

Future<void> updatecompletedEnvironmentReviewsCount(int count) async {
Future<void> updateCompletedEnvironmentReviewsCount(int count) async {
final artefact = await future;
state =
AsyncData(artefact.copyWith(completedEnvironmentReviewsCount: count));
Expand Down
38 changes: 38 additions & 0 deletions frontend/lib/providers/review_environment.dart
Original file line number Diff line number Diff line change
@@ -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<void> build() async {
return;
}

Future<void> 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,
);
}
}
10 changes: 3 additions & 7 deletions frontend/lib/ui/artefact_page/environment_review_pop_over.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
},
Expand Down

0 comments on commit 3e158d5

Please sign in to comment.