Skip to content

Commit

Permalink
Remove anonymous option from feedback page
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsreichardt committed Mar 5, 2024
1 parent 18b3d0e commit a2f37d5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 121 deletions.
61 changes: 11 additions & 50 deletions app/lib/feedback/feedback_box_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class FeedbackPageBody extends StatelessWidget {
const _DislikeField(),
const _MissingField(),
const _HeardFromField(),
const _AnonymousCheckbox(),
const _ContactInformation(),
const FeedbackPageSubmitButton(key: Key("submitButton")),
const SizedBox(height: _padding)
],
Expand All @@ -94,59 +94,20 @@ class FeedbackPageBody extends StatelessWidget {
// }
// }

class _AnonymousCheckbox extends StatelessWidget {
const _AnonymousCheckbox();
class _ContactInformation extends StatelessWidget {
const _ContactInformation();

@override
Widget build(BuildContext context) {
final bloc = BlocProvider.of<FeedbackBloc>(context);
return StreamBuilder<bool>(
stream: bloc.isAnonymous,
builder: (context, isAnonymousSnapshot) {
final isAnonymous = isAnonymousSnapshot.data ?? false;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const Divider(),
const SizedBox(height: 8),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 0),
child: CheckboxListTile(
value: isAnonymous,
onChanged: (v) {
if (v == null) return;
bloc.changeIsAnonymous(v);
},
secondary: const Icon(Icons.security),
title: const Text(
"Ich möchte mein Feedback anonym abschicken",
),
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: AnimatedSwitcher(
duration: const Duration(milliseconds: 250),
child: isAnonymous
? const Text(
"Bitte beachte, dass wenn du einen Fehler bei dir melden möchtest, wir dir nicht weiterhelfen können, wenn du das Feedback anonym abschickst.",
style: TextStyle(fontSize: 12, color: Colors.grey),
)
: Padding(
padding: const EdgeInsets.only(top: 8),
child: _FeedbackTextField(
labelText: "Kontaktdaten für Rückfragen",
icon: const Icon(Icons.question_answer),
onChanged: bloc.changeContactOptions,
stream: bloc.contactOptions,
),
),
),
),
SizedBox(height: isAnonymous ? 8 : 16),
],
);
},
return Padding(
padding: const EdgeInsets.only(top: 8),
child: _FeedbackTextField(
labelText: "Kontaktdaten für Rückfragen",
icon: const Icon(Icons.question_answer),
onChanged: bloc.changeContactOptions,
stream: bloc.contactOptions,
),
);
}
}
Expand Down
25 changes: 5 additions & 20 deletions app/lib/feedback/src/bloc/feedback_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,16 @@ class FeedbackBloc extends BlocBase {
final _dislikeSubject = BehaviorSubject<String?>();
final _missingSubject = BehaviorSubject<String?>();
final _heardFromSubject = BehaviorSubject<String?>();
final _isAnonymousSubject = BehaviorSubject.seeded(false);
final _contactOptions = BehaviorSubject<String?>();

FeedbackBloc(this._api, this._cache, this._platformInformationRetriever,
this.uid, this.feedbackAnalytics) {
isAnonymous = _isAnonymousSubject.stream;
}
this.uid, this.feedbackAnalytics);

Function(double?) get changeRating => _ratingSubject.sink.add;
Function(String?) get changeLike => _likeSubject.sink.add;
Function(String?) get changeDislike => _dislikeSubject.sink.add;
Function(String?) get changeMissing => _missingSubject.sink.add;
Function(String?) get changeHeardFrom => _heardFromSubject.sink.add;
Function(bool) get changeIsAnonymous => _isAnonymousSubject.sink.add;
Function(String?) get changeContactOptions => _contactOptions.sink.add;

ValueStream<double?> get rating => _ratingSubject;
Expand All @@ -54,16 +50,11 @@ class FeedbackBloc extends BlocBase {
ValueStream<String?> get heardFrom => _heardFromSubject;
ValueStream<String?> get contactOptions => _contactOptions;

/// Whether the user wants to remain anonymous.
/// Defaults to false.
late Stream<bool> isAnonymous;

/// Submits the feedback given to the [FeedbackApi].
///
/// Will add uid, contact information and platform information to the
/// [UserFeedback] as long as [changeIsAnonymous] was not passed true as the
/// latest value.
/// platform information will be read from the [PlatformInformationRetriever].
/// [UserFeedback] and platform information will be read from the
/// [PlatformInformationRetriever].
///
/// Throws a [CoolDownException] if
/// [FeedbackCache.hasFeedbackSubmissionCoolDown] returns true.
Expand All @@ -80,16 +71,12 @@ class FeedbackBloc extends BlocBase {
"User has not yet exceeded the cool down.", feedbackCoolDown);
}

final isAnonymous = _isAnonymousSubject.valueOrNull!;

final rating = _ratingSubject.valueOrNull;
final likes = _likeSubject.valueOrNull;
final dislikes = _dislikeSubject.valueOrNull;
final missing = _missingSubject.valueOrNull;
final heardFrom = _heardFromSubject.valueOrNull;
final uid = isAnonymous ? "" : this.uid;
final userContactInformation =
isAnonymous ? "" : _contactOptions.valueOrNull;
final userContactInformation = _contactOptions.valueOrNull;

await _platformInformationRetriever.init();

Expand All @@ -108,7 +95,7 @@ class FeedbackBloc extends BlocBase {
heardFrom: heardFrom,
uid: uid,
userContactInformation: userContactInformation,
deviceInformation: isAnonymous ? null : deviceInfo,
deviceInformation: deviceInfo,
);

if (feedback.requiredUserInputIsEmpty) throw EmptyFeedbackException();
Expand All @@ -129,15 +116,13 @@ class FeedbackBloc extends BlocBase {
changeLike(null);
changeHeardFrom(null);
changeContactOptions(null);
changeIsAnonymous(false);
}

@override
void dispose() {
_contactOptions.close();
_dislikeSubject.close();
_heardFromSubject.close();
_isAnonymousSubject.close();
_likeSubject.close();
_missingSubject.close();
_ratingSubject.close();
Expand Down
27 changes: 1 addition & 26 deletions app/test/feedback/feedback_bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ void main() {
MockPlatformInformationRetriever platformInformationRetriever;
late FeedbackBloc bloc;
UserFeedback? expectedResponseWithIdentifiableInfo;
UserFeedback? expectedAnonymousResponse;
late MockFeedbackAnalytics analytics;

setUp(() {
Expand All @@ -60,32 +59,9 @@ void main() {
appName: "appName",
packageName: "packageName",
));

expectedAnonymousResponse = UserFeedback.create().copyWith(
rating: rating,
likes: likes,
dislikes: dislikes,
missing: missing,
heardFrom: heardFrom,
uid: "",
userContactInformation: "",
deviceInformation: null,
);
});

test(
"Feedback is send with no identifiable information if the anonymous option is enable",
() async {
fillInAllFields(bloc);
bloc.changeIsAnonymous(true);

await bloc.submit();

expect(api.wasOnlyInvokedWith(expectedAnonymousResponse), true);
});
test(
"Feedback is send with uid, contact and device information, when not anonymous",
() async {
test("Feedback is send with uid, contact and device information", () async {
writeRdmValues(bloc);
fillInAllFields(bloc);

Expand Down Expand Up @@ -239,7 +215,6 @@ void fillInAllFields(FeedbackBloc bloc) {
bloc.changeDislike(dislikes);
bloc.changeMissing(missing);
bloc.changeHeardFrom(heardFrom);
bloc.changeIsAnonymous(false);
bloc.changeContactOptions(contactInfo);
}

Expand Down
26 changes: 1 addition & 25 deletions app/test/feedback/feedback_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ void main() {
MockPlatformInformationRetriever platformInformationRetriever;
late FeedbackBloc bloc;
UserFeedback? expectedResponseWithIdentifiableInfo;
UserFeedback? expectedAnonymousResponse;

setUp(() {
api = MockFeedbackApi();
Expand All @@ -58,16 +57,6 @@ void main() {
appName: "appName",
packageName: "packageName",
));

expectedAnonymousResponse = UserFeedback.create().copyWith(
likes: likes,
dislikes: dislikes,
missing: missing,
heardFrom: heardFrom,
uid: "",
userContactInformation: "",
deviceInformation: null,
);
});

tearDown(() {
Expand All @@ -87,19 +76,7 @@ void main() {
);
}

test(
"Feedback is send with no identifiable information if the anonymous option is enable",
() async {
fillInAllFields(bloc);
bloc.changeIsAnonymous(true);

await bloc.submit();

expect(api.wasOnlyInvokedWith(expectedAnonymousResponse), true);
});
test(
"Feedback is send with uid, contact and device information, when not anonymous",
() async {
test("Feedback is send with uid, contact and device information", () async {
writeRdmValues(bloc);
fillInAllFields(bloc);

Expand Down Expand Up @@ -146,7 +123,6 @@ void fillInAllFields(FeedbackBloc bloc) {
bloc.changeDislike(dislikes);
bloc.changeMissing(missing);
bloc.changeHeardFrom(heardFrom);
bloc.changeIsAnonymous(false);
bloc.changeContactOptions(contactInfo);
}

Expand Down

0 comments on commit a2f37d5

Please sign in to comment.