Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Application] Added a bloc to load the char birthdays for a particula…
…r month
- Loading branch information
Showing
4 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
lib/application/birthdays_per_month/birthdays_per_month_bloc.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'package:bloc/bloc.dart'; | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
import 'package:shiori/domain/models/models.dart'; | ||
import 'package:shiori/domain/services/genshin_service.dart'; | ||
import 'package:shiori/domain/services/telemetry_service.dart'; | ||
|
||
part 'birthdays_per_month_bloc.freezed.dart'; | ||
part 'birthdays_per_month_event.dart'; | ||
part 'birthdays_per_month_state.dart'; | ||
|
||
class BirthdaysPerMonthBloc extends Bloc<BirthdaysPerMonthEvent, BirthdaysPerMonthState> { | ||
final GenshinService _genshinService; | ||
final TelemetryService _telemetryService; | ||
|
||
BirthdaysPerMonthBloc(this._genshinService, this._telemetryService) : super(const BirthdaysPerMonthState.loading()); | ||
|
||
@override | ||
Stream<BirthdaysPerMonthState> mapEventToState(BirthdaysPerMonthEvent event) async* { | ||
final s = await event.map( | ||
init: (e) => _init(e.month), | ||
); | ||
yield s; | ||
} | ||
|
||
Future<BirthdaysPerMonthState> _init(int month) async { | ||
await _telemetryService.trackBirthdaysPerMonthOpened(month); | ||
final characters = _genshinService.getCharacterBirthdays(month: month); | ||
return BirthdaysPerMonthState.loaded(month: month, characters: characters); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
lib/application/birthdays_per_month/birthdays_per_month_event.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
part of 'birthdays_per_month_bloc.dart'; | ||
|
||
@freezed | ||
class BirthdaysPerMonthEvent with _$BirthdaysPerMonthEvent { | ||
const factory BirthdaysPerMonthEvent.init({ | ||
required int month, | ||
}) = _BirthdaysPerMonthEvent; | ||
} |
11 changes: 11 additions & 0 deletions
11
lib/application/birthdays_per_month/birthdays_per_month_state.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
part of 'birthdays_per_month_bloc.dart'; | ||
|
||
@freezed | ||
class BirthdaysPerMonthState with _$BirthdaysPerMonthState { | ||
const factory BirthdaysPerMonthState.loading() = _LoadingState; | ||
|
||
const factory BirthdaysPerMonthState.loaded({ | ||
required int month, | ||
required List<CharacterBirthdayModel> characters, | ||
}) = _LoadedState; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters