Skip to content

Commit

Permalink
feat(app): improve filter indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Sep 18, 2024
1 parent b26bfd8 commit 4ca96b9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 31 deletions.
16 changes: 0 additions & 16 deletions app/lib/common/widgets/drug_list/cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,3 @@ class DrugListState with _$DrugListState {
) = _LoadedState;
const factory DrugListState.error() = _ErrorState;
}

bool areDrugsFiltered({
required DrugListState state,
required ActiveDrugs activeDrugs,
required bool searchForDrugClass,
}) => state.whenOrNull(
loaded: (allDrugs, filter) {
final totalNumberOfDrugs = allDrugs.length;
final currentNumberOfDrugs = filter.filter(
allDrugs,
activeDrugs,
searchForDrugClass: searchForDrugClass,
).length;
return totalNumberOfDrugs != currentNumberOfDrugs;
},
) ?? false;
38 changes: 23 additions & 15 deletions app/lib/common/widgets/drug_search/drug_filters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,27 +141,35 @@ class DrugFilters extends StatelessWidget {
final ActiveDrugs activeDrugs;
final bool searchForDrugClass;

bool _showActiveIndicator() {
return areDrugsFiltered(
state: state,
activeDrugs: activeDrugs,
searchForDrugClass: searchForDrugClass,
);
}
bool _showActiveIndicator() => state.whenOrNull(
loaded: (allDrugs, filter) {
final relevantDrugsFilter = FilterState.from(
FilterState.initial(),
query: filter.query,
);
final totalNumberOfDrugs = relevantDrugsFilter.filter(
allDrugs,
activeDrugs,
searchForDrugClass: searchForDrugClass,
).length;
final currentNumberOfDrugs = filter.filter(
allDrugs,
activeDrugs,
searchForDrugClass: searchForDrugClass,
).length;
return totalNumberOfDrugs != currentNumberOfDrugs;
},
) ?? false;

Widget _buildActiveIndicator() {
const indicatorSize = PharMeTheme.smallToMediumSpace;
const indicatorSize = PharMeTheme.smallSpace;
return Positioned(
right: 0,
bottom: 0,
right: 0 + indicatorSize * 0.25,
bottom: 0 + indicatorSize * 0.25,
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: PharMeTheme.sinaiPurple,
border: Border.all(
color: PharMeTheme.surfaceColor,
width: indicatorSize / 8,
),
color: PharMeTheme.sinaiMagenta,
),
width: indicatorSize,
height: indicatorSize,
Expand Down

0 comments on commit 4ca96b9

Please sign in to comment.