Skip to content

Commit

Permalink
[Application] Added a region filter to the characters page
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfteam committed Jul 10, 2021
1 parent 95edf9c commit 2d5a107
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/application/characters/characters_bloc.dart
Expand Up @@ -69,6 +69,7 @@ class CharactersBloc extends Bloc<CharactersEvent, CharactersState> {
weaponTypes: currentState.tempWeaponTypes,
roleType: currentState.tempRoleType,
excludeKeys: currentState.excludeKeys,
regionType: currentState.tempRegionType,
),
cancelChanges: (_) => currentState.copyWith.call(
tempCharacterFilterType: currentState.characterFilterType,
Expand All @@ -79,6 +80,13 @@ class CharactersBloc extends Bloc<CharactersEvent, CharactersState> {
tempWeaponTypes: currentState.weaponTypes,
tempRoleType: currentState.roleType,
excludeKeys: currentState.excludeKeys,
tempRegionType: currentState.regionType,
),
regionTypeChanged: (e) => currentState.copyWith.call(tempRegionType: e.regionType),
resetFilters: (_) => _buildInitialState(
excludeKeys: state.maybeMap(loaded: (state) => state.excludeKeys, orElse: () => []),
elementTypes: ElementType.values,
weaponTypes: WeaponType.values,
),
);
yield s;
Expand All @@ -94,6 +102,7 @@ class CharactersBloc extends Bloc<CharactersEvent, CharactersState> {
CharacterFilterType characterFilterType = CharacterFilterType.name,
SortDirectionType sortDirectionType = SortDirectionType.asc,
CharacterRoleType roleType = CharacterRoleType.all,
RegionType? regionType,
}) {
final isLoaded = state is _LoadedState;
var characters = _genshinService.getCharactersForCard();
Expand Down Expand Up @@ -124,6 +133,8 @@ class CharactersBloc extends Bloc<CharactersEvent, CharactersState> {
roleType: roleType,
tempRoleType: roleType,
excludeKeys: excludeKeys,
regionType: regionType,
tempRegionType: regionType,
);
}

Expand All @@ -147,6 +158,10 @@ class CharactersBloc extends Bloc<CharactersEvent, CharactersState> {
characters = characters.where((el) => el.roleType == roleType).toList();
}

if (regionType != null) {
characters = characters.where((el) => el.regionType == regionType).toList();
}

switch (statusType) {
case ItemStatusType.released:
characters = characters.where((el) => !el.isComingSoon).toList();
Expand Down Expand Up @@ -179,6 +194,10 @@ class CharactersBloc extends Bloc<CharactersEvent, CharactersState> {
sortDirectionType: sortDirectionType,
tempSortDirectionType: sortDirectionType,
excludeKeys: excludeKeys,
roleType: roleType,
tempRoleType: roleType,
regionType: regionType,
tempRegionType: regionType,
);
return s;
}
Expand Down
4 changes: 4 additions & 0 deletions lib/application/characters/characters_event.dart
Expand Up @@ -24,7 +24,11 @@ class CharactersEvent with _$CharactersEvent {

const factory CharactersEvent.roleTypeChanged(CharacterRoleType roleType) = _CharacterTypeChanged;

const factory CharactersEvent.regionTypeChanged(RegionType? regionType) = _RegionTypeChanged;

const factory CharactersEvent.applyFilterChanges() = _ApplyFilterChanges;

const factory CharactersEvent.cancelChanges() = _CancelChanges;

const factory CharactersEvent.resetFilters() = _ResetFilters;
}
2 changes: 2 additions & 0 deletions lib/application/characters/characters_state.dart
Expand Up @@ -22,6 +22,8 @@ class CharactersState with _$CharactersState {
required SortDirectionType tempSortDirectionType,
required CharacterRoleType roleType,
required CharacterRoleType tempRoleType,
RegionType? regionType,
RegionType? tempRegionType,
@Default(<String>[]) List<String> excludeKeys,
}) = _LoadedState;
}
2 changes: 2 additions & 0 deletions lib/domain/models/characters/character_card_model.dart
Expand Up @@ -11,6 +11,7 @@ class CharacterCardModel {
final bool isComingSoon;
final List<String> materials;
final CharacterRoleType roleType;
final RegionType regionType;

const CharacterCardModel({
required this.key,
Expand All @@ -21,6 +22,7 @@ class CharacterCardModel {
required this.elementType,
required this.materials,
required this.roleType,
required this.regionType,
this.isNew = false,
this.isComingSoon = false,
});
Expand Down
1 change: 1 addition & 0 deletions lib/infrastructure/genshin_service.dart
Expand Up @@ -791,6 +791,7 @@ class GenshinServiceImpl implements GenshinService {
isComingSoon: character.isComingSoon,
isNew: character.isNew,
roleType: character.role,
regionType: character.region,
);
}

Expand Down

0 comments on commit 2d5a107

Please sign in to comment.