Skip to content

Commit

Permalink
feat(#646): sort drugs and show button
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Aug 23, 2023
1 parent 3e21765 commit 6d87710
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import '../../../module.dart';

bool isDrugSelected(Drug drug) {
return UserData.instance.activeDrugNames!.contains(drug.name);
}

List<Widget> buildDrugCheckboxList(
BuildContext context,
List<Drug> drugs,
Expand All @@ -9,13 +13,17 @@ List<Widget> buildDrugCheckboxList(
final onCheckboxChange = buildParams['onCheckboxChange'];
final checkboxesEnabled = buildParams['checkboxesEnabled'];
final sortedDrugs = List<Drug>.from(drugs);
sortedDrugs.sort((drugA, drugB) => drugA.name.compareTo(drugB.name));
sortedDrugs.sort((drugA, drugB) {
final drugASelected = isDrugSelected(drugA);
final drugBSelected = isDrugSelected(drugB);
if (drugASelected == drugBSelected) return drugA.name.compareTo(drugB.name);
return drugASelected ? -1 : 1;
});
return [
...sortedDrugs.map(
(drug) => CheckboxListTile(
enabled: checkboxesEnabled,
value: UserData.instance.activeDrugNames!
.contains(drug.name),
value: isDrugSelected(drug),
onChanged: (value) => onCheckboxChange(drug, value),
title: Text(drug.name.capitalize()),
subtitle: (drug.annotations.brandNames.isNotEmpty) ?
Expand Down
16 changes: 10 additions & 6 deletions app/lib/common/widgets/drug_search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,16 @@ class DrugSearch extends HookWidget {
if (showFilter) buildFilter(context),
]
),
...buildDrugList(
context,
state,
buildDrugItems: buildDrugItems,
noDrugsMessage: noDrugsMessage,
drugItemsBuildParams: drugItemsBuildParams,
Expanded(
child: ListView(
children: buildDrugList(
context,
state,
buildDrugItems: buildDrugItems,
noDrugsMessage: noDrugsMessage,
drugItemsBuildParams: drugItemsBuildParams,
),
),
),
],
);
Expand Down
20 changes: 12 additions & 8 deletions app/lib/drug_selection/pages/drug_selection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,13 @@ class DrugSelectionPage extends HookWidget {
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(16),
child: ListView(
child: Column(
children: [
_buildHeader(context),
_buildDrugList(context, state),
SizedBox(height: PharMeTheme.mediumSpace),
FullWidthButton(
context.l10n.general_continue,
() { context.router.replace(MainRoute()); },
enabled: _isEditable(state),
),
Expanded(child:_buildDrugList(context, state)),
SizedBox(height: PharMeTheme.mediumSpace),
_buildButton(context, state),
],
),
),
Expand Down Expand Up @@ -66,12 +63,19 @@ class DrugSelectionPage extends HookWidget {
Text(
context.l10n.drug_selection_later,
style: PharMeTheme.textTheme.bodyLarge),
SizedBox(height: PharMeTheme.mediumSpace),
]
),
);
}

Widget _buildButton(BuildContext context, DrugSelectionPageState state) {
return FullWidthButton(
context.l10n.action_continue,
() => context.router.replace(MainRoute()),
enabled: _isEditable(state),
);
}

Widget _buildDrugList(BuildContext context, DrugSelectionPageState state) {
if (CachedDrugs.instance.drugs!.isEmpty) {
return Column(
Expand Down
4 changes: 2 additions & 2 deletions app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"auth_success": "Successfully imported data",

"drug_selection_header": "Select active drugs",
"drug_selection_description": "Please select the drugs you are currently taking below. If you are not taking checked drugs anymore, you can uncheck them.",
"drug_selection_later": "Active drugs can influence how you react to other drugs. You can always change the status for each drug later.",
"drug_selection_description": "Please select the drugs you are currently taking below. If you are not taking pre-selected drugs anymore, please de-select them.",
"drug_selection_later": "You can always change the status for each drug later.",
"drug_selection_no_drugs_loaded": "No drugs loaded",

"err_could_not_retrieve_access_token": "An unexpected error occurred while retrieving the access token",
Expand Down

0 comments on commit 6d87710

Please sign in to comment.