2021-06-19 15:41:19 +00:00
|
|
|
import 'package:app_flowy/home/domain/edit_context.dart';
|
|
|
|
import 'package:app_flowy/home/domain/page_context.dart';
|
|
|
|
import 'package:app_flowy/home/presentation/widgets/blank_page.dart';
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
|
|
import 'package:dartz/dartz.dart';
|
|
|
|
part 'home_bloc.freezed.dart';
|
|
|
|
|
|
|
|
class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
|
|
|
HomeBloc() : super(HomeState.initial());
|
|
|
|
|
|
|
|
@override
|
|
|
|
Stream<HomeState> mapEventToState(
|
|
|
|
HomeEvent event,
|
|
|
|
) async* {
|
|
|
|
yield* event.map(
|
|
|
|
setPage: (e) async* {
|
|
|
|
yield state.copyWith(pageContext: e.context);
|
|
|
|
},
|
|
|
|
showLoading: (e) async* {
|
|
|
|
yield state.copyWith(isLoading: e.isLoading);
|
|
|
|
},
|
|
|
|
setEditPannel: (e) async* {
|
|
|
|
yield state.copyWith(editContext: some(e.editContext));
|
|
|
|
},
|
|
|
|
dismissEditPannel: (value) async* {
|
|
|
|
yield state.copyWith(editContext: none());
|
|
|
|
},
|
2021-07-20 15:51:08 +00:00
|
|
|
forceCollapse: (e) async* {
|
|
|
|
yield state.copyWith(forceCollapse: e.forceCollapse);
|
2021-06-19 15:41:19 +00:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future<void> close() {
|
|
|
|
return super.close();
|
|
|
|
}
|
|
|
|
}
|
2021-07-22 03:23:15 +00:00
|
|
|
|
|
|
|
@freezed
|
|
|
|
abstract class HomeEvent with _$HomeEvent {
|
|
|
|
const factory HomeEvent.showLoading(bool isLoading) = _ShowLoading;
|
|
|
|
const factory HomeEvent.forceCollapse(bool forceCollapse) = _ForceCollapse;
|
|
|
|
|
|
|
|
//page
|
|
|
|
const factory HomeEvent.setPage(PageContext context) = SetCurrentPage;
|
|
|
|
|
|
|
|
//edit pannel
|
|
|
|
const factory HomeEvent.setEditPannel(EditPannelContext editContext) =
|
|
|
|
_ShowEditPannel;
|
|
|
|
const factory HomeEvent.dismissEditPannel() = _DismissEditPannel;
|
|
|
|
}
|
|
|
|
|
|
|
|
@freezed
|
|
|
|
abstract class HomeState implements _$HomeState {
|
|
|
|
const factory HomeState({
|
|
|
|
required bool isLoading,
|
|
|
|
required bool forceCollapse,
|
|
|
|
required PageContext pageContext,
|
|
|
|
required Option<EditPannelContext> editContext,
|
|
|
|
}) = _HomeState;
|
|
|
|
|
|
|
|
factory HomeState.initial() => HomeState(
|
|
|
|
isLoading: false,
|
|
|
|
forceCollapse: false,
|
|
|
|
pageContext: const BlankPageContext(),
|
|
|
|
editContext: none(),
|
|
|
|
);
|
|
|
|
}
|