Skip to content

Commit

Permalink
feat(#567): generalize message when no drugs
Browse files Browse the repository at this point in the history
  • Loading branch information
jannis-baum committed Apr 14, 2023
1 parent f3811c3 commit 731b83f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
23 changes: 18 additions & 5 deletions app/lib/common/widgets/drug_list/builder.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
import '../../module.dart';

List<Widget> buildDrugList(BuildContext context, DrugListState state) =>
List<Widget> buildDrugList(
BuildContext context,
DrugListState state, {
String? noDrugsMessage,
}) =>
state.when(
initial: () => [Container()],
error: () => [errorIndicator(context.l10n.err_generic)],
loaded: (drugs, filter) => _buildDrugCards(context, drugs, filter),
loaded: (drugs, filter) => _buildDrugCards(
context,
drugs,
filter,
noDrugsMessage: noDrugsMessage,
),
loading: () => [loadingIndicator()],
);

List<Widget> _buildDrugCards(
BuildContext context, List<Drug> drugs, FilterState filter) {
BuildContext context,
List<Drug> drugs,
FilterState filter, {
String? noDrugsMessage,
}) {
final filteredDrugs = filter.filter(drugs);
if (filteredDrugs.isEmpty) {
return [errorIndicator(context.l10n.err_no_drugs)];
if (filteredDrugs.isEmpty && noDrugsMessage != null) {
return [errorIndicator(noDrugsMessage)];
}
return [
SizedBox(height: 8),
Expand Down
1 change: 1 addition & 0 deletions app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"gene_page_phenotype_tooltip": "The phenotype describes the effect that your personal variant of this gene has on the enzyme it encodes.",
"gene_page_affected_drugs": "Affected drugs",
"gene_page_affected_drugs_tooltip": "The drugs listed here are affected by your variant of this gene.",
"gene_page_no_affected_drugs": "Your variant of this gene has no known effect on any drug.",

"nav_report": "Report",
"tab_report": "Gene report",
Expand Down
3 changes: 2 additions & 1 deletion app/lib/report/pages/gene.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class GenePage extends HookWidget {
SizedBox(height: 12),
SubHeader(context.l10n.gene_page_affected_drugs,
tooltip: context.l10n.gene_page_affected_drugs_tooltip),
...buildDrugList(context, state)
...buildDrugList(context, state,
noDrugsMessage: context.l10n.gene_page_no_affected_drugs)
],
),
),
Expand Down
3 changes: 2 additions & 1 deletion app/lib/search/pages/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class SearchPage extends HookWidget {
TooltipIcon(context.l10n.search_page_tooltip_search),
buildFilter(context),
]),
body: buildDrugList(context, state),
body: buildDrugList(context, state,
noDrugsMessage: context.l10n.err_no_drugs),
);
}));
}
Expand Down

0 comments on commit 731b83f

Please sign in to comment.