Skip to content

Commit

Permalink
Session-specific feedback (#110)
Browse files Browse the repository at this point in the history
* Fixes a bug with a missing context because of multiple initializations of the router

* Use the session feedback API when giving feedback for a specific session

* Fix API URL construction for session feedback

* Add a testing guideline
  • Loading branch information
MillerAdulu authored Aug 23, 2024
1 parent 9f7000c commit 126e801
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 9 deletions.
1 change: 1 addition & 0 deletions lib/common/data/models/feedback_dto.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class FeedbackDTO with _$FeedbackDTO {
factory FeedbackDTO({
required String feedback,
required int rating,
String? sessionSlug,
}) = _FeedbackDTO;

factory FeedbackDTO.fromJson(Map<String, dynamic> json) =>
Expand Down
9 changes: 8 additions & 1 deletion lib/common/repository/api_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,15 @@ class ApiRepository {
// Submit feedback as form data
Future<String> submitFeedback({required FeedbackDTO feedbackDTO}) async {
try {
final url = StringBuffer('/events/$_eventSlug/feedback');

if (feedbackDTO.sessionSlug != null &&
feedbackDTO.sessionSlug!.isNotEmpty) {
url.write('/sessions/${feedbackDTO.sessionSlug}');
}

final response = await _networkUtil.postReq(
'/events/$_eventSlug/feedback',
url.toString(),
body: feedbackDTO.toJson(),
);

Expand Down
14 changes: 9 additions & 5 deletions lib/common/utils/notification_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ class NotificationService {
required String channelKey,
required LocalSession session,
}) async {
final endTime = session.endDateTime;
final notificationTime = endTime.subtract(const Duration(minutes: 5));
final notificationTime =
session.endDateTime.subtract(const Duration(minutes: 5));
// Uncomment the line below to test the notification in 5 seconds
// final notificationTime = DateTime.now().add(const Duration(seconds: 5));
String? title;
String? body;

Expand All @@ -73,6 +75,7 @@ class NotificationService {
channelKey: channelKey,
title: title,
body: body,
payload: {'sessionSlug': session.slug},
),
schedule: NotificationCalendar.fromDate(date: notificationTime),
);
Expand All @@ -87,9 +90,10 @@ class NotificationService {
switch (receivedAction.channelKey) {
case 'session_channel':
Logger().f('Navigating to feedback screen');
await getIt<FlutterConRouter>()
.config()
.push(FlutterConRouter.feedbackRoute);
await getIt<FlutterConRouter>().config().push(
FlutterConRouter.feedbackRoute,
extra: receivedAction.payload!['sessionSlug'],
);
}
}
}
4 changes: 3 additions & 1 deletion lib/common/utils/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ class FlutterConRouter {
GoRoute(
path: feedbackRoute,
name: feedbackRoute,
builder: (context, state) => const FeedbackScreen(),
builder: (context, state) => FeedbackScreen(
sessionSlug: state.extra as String?,
),
),
],
);
Expand Down
2 changes: 2 additions & 0 deletions lib/features/feedback/cubit/send_feedback_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ class SendFeedbackCubit extends Cubit<SendFeedbackState> {
Future<void> sendFeedback({
required String feedback,
required int rating,
String? sessionSlug,
}) async {
try {
emit(const SendFeedbackState.loading());
final message = await _apiRepository.submitFeedback(
feedbackDTO: FeedbackDTO(
feedback: feedback,
rating: rating,
sessionSlug: sessionSlug,
),
);

Expand Down
8 changes: 7 additions & 1 deletion lib/features/feedback/ui/feedback_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import 'package:fluttercon/l10n/l10n.dart';
import 'package:go_router/go_router.dart';

class FeedbackScreen extends StatefulWidget {
const FeedbackScreen({super.key});
const FeedbackScreen({
super.key,
this.sessionSlug,
});

final String? sessionSlug;

@override
State<FeedbackScreen> createState() => _FeedbackScreenState();
Expand Down Expand Up @@ -151,6 +156,7 @@ class _FeedbackScreenState extends State<FeedbackScreen> {
.sendFeedback(
feedback: feedback,
rating: selectedRating!,
sessionSlug: widget.sessionSlug,
);
} else {
ScaffoldMessenger.of(context).showSnackBar(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: fluttercon
description: "A new Flutter project."
publish_to: 'none'
version: 1.13.00+11300
version: 1.13.01+11301

environment:
sdk: ">=3.5.0 <4.0.0"
Expand Down

0 comments on commit 126e801

Please sign in to comment.