You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.7 KiB

3 years ago
// import 'dart:async';
3 years ago
import 'package:bytedesk_kefu/blocs/help_bloc/bloc.dart';
import 'package:bytedesk_kefu/model/helpArticle.dart';
import 'package:bytedesk_kefu/model/helpCategory.dart';
import 'package:bytedesk_kefu/repositories/help_repository.dart';
3 years ago
import 'package:bytedesk_kefu/util/bytedesk_utils.dart';
3 years ago
import 'package:bloc/bloc.dart';
class HelpBloc extends Bloc<HelpEvent, HelpState> {
//
final HelpRepository helpRepository = new HelpRepository();
3 years ago
HelpBloc() : super(new UnHelpState()) {
on<GetHelpCategoryEvent>(_mapGetHelpCategoryToState);
on<GetHelpArticleEvent>(_mapGetHelpArticleState);
3 years ago
}
3 years ago
// @override
// Stream<HelpState> mapEventToState(HelpEvent event) async* {
// if (event is GetHelpCategoryEvent) {
// yield* _mapGetHelpCategoryToState(event);
// } else if (event is GetHelpArticleEvent) {
// yield* _mapGetHelpArticleState(event);
// }
// }
void _mapGetHelpCategoryToState(
GetHelpCategoryEvent event, Emitter<HelpState> emit) async {
emit(HelpLoading());
3 years ago
try {
final List<HelpCategory> categoryList =
await helpRepository.getHelpCategories(event.uid);
3 years ago
emit(HelpCategoryState(categoryList));
3 years ago
} catch (error) {
3 years ago
BytedeskUtils.printLog(error);
3 years ago
emit(HelpLoadError());
3 years ago
}
}
3 years ago
void _mapGetHelpArticleState(
GetHelpArticleEvent event, Emitter<HelpState> emit) async {
emit(HelpLoading());
3 years ago
try {
final List<HelpArticle> categoryList =
await helpRepository.getCategoryArticles(event.categoryId);
3 years ago
emit(HelpArticleState(categoryList));
3 years ago
} catch (error) {
3 years ago
BytedeskUtils.printLog(error);
3 years ago
emit(HelpLoadError());
3 years ago
}
}
}