Skip to content

Commit

Permalink
[Application] Added a bloc to load the char birthdays for a particula…
Browse files Browse the repository at this point in the history
…r month
  • Loading branch information
Wolfteam committed May 6, 2022
1 parent 84dc75e commit 8d1619b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/application/birthdays_per_month/birthdays_per_month_bloc.dart
@@ -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);
}
}
@@ -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 lib/application/birthdays_per_month/birthdays_per_month_state.dart
@@ -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;
}
1 change: 1 addition & 0 deletions lib/application/bloc.dart
Expand Up @@ -2,6 +2,7 @@ export 'artifact/artifact_bloc.dart';
export 'artifacts/artifacts_bloc.dart';
export 'banner_history/banner_history_bloc.dart';
export 'banner_history_item/banner_history_item_bloc.dart';
export 'birthdays_per_month/birthdays_per_month_bloc.dart';
export 'calculator_asc_materials/material_item/calculator_asc_materials_item_bloc.dart';
export 'calculator_asc_materials/material_item_quantity/calculator_asc_materials_item_update_quantity_bloc.dart';
export 'calculator_asc_materials/materials/calculator_asc_materials_bloc.dart';
Expand Down

0 comments on commit 8d1619b

Please sign in to comment.