Skip to content

Commit

Permalink
[Application] Added initial item release history bloc
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfteam committed Apr 19, 2022
1 parent 77c1c8b commit 5d2cd30
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/application/bloc.dart
Expand Up @@ -20,6 +20,7 @@ export 'game_codes/game_codes_bloc.dart';
export 'home/home_bloc.dart';
export 'inventory/inventory_bloc.dart';
export 'item_quantity_form/item_quantity_form_bloc.dart';
export 'item_release_history/item_release_history_bloc.dart';
export 'main/main_bloc.dart';
export 'main_tab/main_tab_bloc.dart';
export 'material/material_bloc.dart';
Expand Down
@@ -0,0 +1,29 @@
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 'item_release_history_bloc.freezed.dart';
part 'item_release_history_event.dart';
part 'item_release_history_state.dart';

class ItemReleaseHistoryBloc extends Bloc<ItemReleaseHistoryEvent, ItemReleaseHistoryState> {
final GenshinService _genshinService;
final TelemetryService _telemetryService;

ItemReleaseHistoryBloc(this._genshinService, this._telemetryService) : super(const ItemReleaseHistoryState.loading());

@override
Stream<ItemReleaseHistoryState> mapEventToState(ItemReleaseHistoryEvent event) async* {
final s = await event.map(
init: (e) async {
await _telemetryService.trackItemReleaseHistoryOpened(e.itemKey);
final history = _genshinService.getItemReleaseHistory(e.itemKey);
return ItemReleaseHistoryState.initial(itemKey: e.itemKey, history: history);
},
);

yield s;
}
}
@@ -0,0 +1,6 @@
part of 'item_release_history_bloc.dart';

@freezed
class ItemReleaseHistoryEvent with _$ItemReleaseHistoryEvent {
const factory ItemReleaseHistoryEvent.init({required String itemKey}) = _Init;
}
@@ -0,0 +1,11 @@
part of 'item_release_history_bloc.dart';

@freezed
class ItemReleaseHistoryState with _$ItemReleaseHistoryState {
const factory ItemReleaseHistoryState.loading() = _Loading;

const factory ItemReleaseHistoryState.initial({
required String itemKey,
required List<ItemReleaseHistoryModel> history,
}) = _InitialState;
}

0 comments on commit 5d2cd30

Please sign in to comment.