Skip to content

Commit

Permalink
fix: clean up post merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Zied-Dahmani committed Nov 18, 2024
1 parent 2468132 commit d3447f9
Show file tree
Hide file tree
Showing 9 changed files with 178 additions and 22 deletions.
4 changes: 2 additions & 2 deletions lib/core/di/bloc_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ void _registerBlocsModule() {

_registerFactoryWithParams<ProposalCreationBloc, List<DaoData>, void>(
(daos, _) => ProposalCreationBloc(
_getIt<PublishProposalUseCase>(),
daos,
_getIt<PublishProposalUseCase>(),
_getIt<ErrorHandlerManager>(),
daos,
),
);
}
2 changes: 1 addition & 1 deletion lib/core/network/models/proposal_details_model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/core/network/models/proposal_model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 19 additions & 14 deletions lib/ui/proposals/creation/interactor/proposal_creation_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:hypha_wallet/core/error_handler/error_handler_manager.dart';
import 'package:hypha_wallet/core/error_handler/model/hypha_error.dart';
import 'package:hypha_wallet/core/network/models/dao_data_model.dart';
import 'package:hypha_wallet/core/network/models/outcome_model.dart';
import 'package:hypha_wallet/core/network/models/proposal_creation_model.dart';
import 'package:hypha_wallet/ui/architecture/interactor/page_states.dart';
import 'package:hypha_wallet/ui/architecture/result/result.dart';
Expand All @@ -17,46 +16,52 @@ part 'proposal_creation_event.dart';
part 'proposal_creation_state.dart';

class ProposalCreationBloc extends Bloc<ProposalCreationEvent, ProposalCreationState> {
final List<DaoData> daos;
final PublishProposalUseCase _publishProposalUseCase;
final ErrorHandlerManager _errorHandlerManager;
final List<DaoData> daos;

ProposalCreationBloc(this.daos, this._publishProposalUseCase, this._errorHandlerManager) : super(ProposalCreationState(proposal: ProposalCreationModel())) {
on<_Initialize>(_initialize);
on<_UpdateCurrentView>(_updateCurrentView);
on<_UpdateProposal>(_updateProposal);
on<_PublishProposal>(_publishProposal);
on<_ClearPageCommand>((_, emit) => emit(state.copyWith(command: null)));

_pageController = PageController(initialPage: daos.length > 1 ? 0 : 1);
if (daos.length == 1) {
emit(state.copyWith(proposal: state.proposal!.copyWith({'dao': daos.first})));
}
}

late final PageController _pageController;

PageController get pageController => _pageController;

// TODO(Zied): fix emit
Future<void> _updateCurrentView(_UpdateCurrentView event, Emitter<ProposalCreationState> emit) async {
void _initialize(_Initialize event, Emitter<ProposalCreationState> emit) {

if (daos.length == 1) {
emit(state.copyWith(proposal: state.proposal!.copyWith({'dao': daos.first})));
}
}

void _updateCurrentView(_UpdateCurrentView event, Emitter<ProposalCreationState> emit) {
if (event.nextViewIndex == -1) {
emit(state.copyWith(command: const PageCommand.navigateBackToProposals()));
} else {
switch (event.nextViewIndex) {
case 0 || 1 || 4 || 5:
case 0 || 1 || 3 || 4:
navigate(emit, event.nextViewIndex);
break;
case 2:
if (state.proposal!.title != null && state.proposal!.details != null) {
navigate(emit, event.nextViewIndex);
}
break;
case 3:
navigate(
// TODO(Zied): refactor this
/* case 3:
navigate(
emit,
state.proposal!.type == OutcomeType.agreement.label
? event.nextViewIndex + 1
: event.nextViewIndex);
break;
break; */
default:
break;
}
Expand All @@ -72,13 +77,13 @@ class ProposalCreationBloc extends Bloc<ProposalCreationEvent, ProposalCreationS
);
}

Future<void> _updateProposalFields(updates, emit) async {
void _updateProposalFields(updates, emit) {
final ProposalCreationModel proposal = state.proposal!.copyWith(updates);
emit(state.copyWith(proposal: proposal));
}

Future<void> _updateProposal(_UpdateProposal event, Emitter<ProposalCreationState> emit) async {
unawaited(_updateProposalFields(event.updates, emit));
void _updateProposal(_UpdateProposal event, Emitter<ProposalCreationState> emit) {
_updateProposalFields(event.updates, emit);
}

Future<void> _publishProposal(_PublishProposal event, Emitter<ProposalCreationState> emit) async {
Expand Down
Loading

0 comments on commit d3447f9

Please sign in to comment.