Skip to content

Commit

Permalink
feat(app): change search behavior in drug list if activity is changeable
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Sep 18, 2024
1 parent fc76c34 commit 5d29503
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
22 changes: 10 additions & 12 deletions app/lib/common/widgets/drug_list/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DrugList extends StatelessWidget {
this.buildDrugItems = buildDrugCards,
this.showDrugInteractionIndicator = false,
this.searchForDrugClass = true,
this.repeatMedicationsWhenNotFiltered = false,
this.drugActivityChangeable = false,
this.buildContainer,
});

Expand All @@ -28,7 +28,10 @@ class DrugList extends StatelessWidget {
final DrugItemBuilder buildDrugItems;
final bool showDrugInteractionIndicator;
final bool searchForDrugClass;
final bool repeatMedicationsWhenNotFiltered;
// if drugActivityChangeable, active medications are not filtered and repeated
// in the "All medications" list to make searching and toggling a medication's
// activity less confusing
final bool drugActivityChangeable;
final Widget Function(List<Widget> children)? buildContainer;

Widget _buildDrugList(
Expand All @@ -44,8 +47,9 @@ class DrugList extends StatelessWidget {
if (filteredDrugs.isEmpty && noDrugsMessage != null) {
return errorIndicator(noDrugsMessage!);
}
final activeFilteredDrugs =
filteredDrugs.filter((drug) => drug.isActive).toList();
final activeFilteredDrugs = drugActivityChangeable
? drugs.filter((drug) => drug.isActive).toList()
: filteredDrugs.filter((drug) => drug.isActive).toList();
final activeDrugsList = activeFilteredDrugs.isNotEmpty
? buildDrugItems(
context,
Expand All @@ -54,16 +58,10 @@ class DrugList extends StatelessWidget {
keyPrefix: 'active-',
)
: null;
final repeatMedications = repeatMedicationsWhenNotFiltered &&
!areDrugsFiltered(
state: state,
activeDrugs: activeDrugs,
searchForDrugClass: searchForDrugClass,
);
final otherDrugs = repeatMedications
final otherDrugs = drugActivityChangeable
? filteredDrugs
: filteredDrugs.filter((drug) => !drug.isActive).toList();
final otherDrugsHeader = repeatMedications
final otherDrugsHeader = drugActivityChangeable
? context.l10n.drug_list_subheader_all_drugs
: context.l10n.drug_list_subheader_other_drugs;
final allDrugsList = buildDrugItems(
Expand Down
6 changes: 3 additions & 3 deletions app/lib/common/widgets/drug_search/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class DrugSearch extends HookWidget {
required this.state,
required this.activeDrugs,
this.keepPosition = false,
this.repeatMedications = false,
this.drugActivityChangeable = false,
});

final bool showFilter;
final bool searchForDrugClass;
final bool keepPosition;
final bool repeatMedications;
final bool drugActivityChangeable;
final DrugItemBuilder buildDrugItems;
final bool showDrugInteractionIndicator;
final DrugListCubit cubit;
Expand Down Expand Up @@ -57,7 +57,7 @@ class DrugSearch extends HookWidget {
searchForDrugClass: searchForDrugClass,
buildContainer:
(children) => scrollList(keepPosition: keepPosition, children),
repeatMedicationsWhenNotFiltered: repeatMedications,
drugActivityChangeable: drugActivityChangeable,
),
_maybeBuildInteractionIndicator(context, state, activeDrugs)
?? SizedBox.shrink(),
Expand Down
2 changes: 1 addition & 1 deletion app/lib/drug_selection/pages/drug_selection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class DrugSelectionPage extends HookWidget {
)),
showDrugInteractionIndicator: !concludesOnboarding,
// to not confuse users when selecting a medication that then is removed from the list
repeatMedications: true,
drugActivityChangeable: true,
),
);
}
Expand Down

0 comments on commit 5d29503

Please sign in to comment.