Skip to content

Commit

Permalink
feat: implement proposals history
Browse files Browse the repository at this point in the history
  • Loading branch information
Zied-Dahmani committed Sep 24, 2024
1 parent 095ac10 commit eb63b27
Show file tree
Hide file tree
Showing 11 changed files with 538 additions and 14 deletions.
10 changes: 9 additions & 1 deletion lib/core/di/bloc_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,12 @@ void _registerBlocsModule() {
_getIt<GetDaosFromProposalCountsUseCase>(),
_getIt<ErrorHandlerManager>(),
));
}

_registerFactoryWithParams<ProposalsHistoryBloc, DaoData, void>(
(dao, _) => ProposalsHistoryBloc(
_getIt<GetProposalsUseCase>(),
_getIt<ErrorHandlerManager>(),
dao
),
);
}
2 changes: 2 additions & 0 deletions lib/core/di/di_setup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import 'package:hypha_wallet/core/network/api/services/token_service.dart';
import 'package:hypha_wallet/core/network/api/services/transaction_history_service.dart';
import 'package:hypha_wallet/core/network/api/services/user_account_service.dart';
import 'package:hypha_wallet/core/network/ipfs/ipfs_manager.dart';
import 'package:hypha_wallet/core/network/models/dao_data_model.dart';
import 'package:hypha_wallet/core/network/models/network.dart';
import 'package:hypha_wallet/core/network/models/user_profile_data.dart';
import 'package:hypha_wallet/core/network/networking_manager.dart';
Expand Down Expand Up @@ -76,6 +77,7 @@ import 'package:hypha_wallet/ui/proposals/details/usecases/get_proposal_details_
import 'package:hypha_wallet/ui/proposals/filter/interactor/filter_proposals_bloc.dart';
import 'package:hypha_wallet/ui/proposals/filter/usecases/aggregate_dao_proposal_counts_use_case.dart';
import 'package:hypha_wallet/ui/proposals/filter/usecases/get_daos_from_proposal_counts_use_case.dart';
import 'package:hypha_wallet/ui/proposals/history/interactor/proposals_history_bloc.dart';
import 'package:hypha_wallet/ui/proposals/list/interactor/proposals_bloc.dart';
import 'package:hypha_wallet/ui/proposals/list/usecases/get_proposals_use_case.dart';
import 'package:hypha_wallet/ui/search_user/interactor/search_user_bloc.dart';
Expand Down
20 changes: 20 additions & 0 deletions lib/ui/proposals/components/proposals_list.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:flutter/material.dart';
import 'package:hypha_wallet/core/network/models/proposal_model.dart';
import 'package:hypha_wallet/ui/proposals/list/components/hypha_proposals_action_card.dart';

class ProposalsList extends StatelessWidget {
final List<ProposalModel> proposals;

const ProposalsList(this.proposals, {super.key});

@override
Widget build(BuildContext context) {
return ListView.separated(
padding: const EdgeInsets.only(bottom: 22),
itemBuilder: (BuildContext context, int index) => HyphaProposalsActionCard(proposals[index]),
separatorBuilder: (BuildContext context, int index) {
return const SizedBox(height: 16);
},
itemCount: proposals.length);
}
}
35 changes: 35 additions & 0 deletions lib/ui/proposals/history/components/proposals_history_view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:get/get.dart';
import 'package:hypha_wallet/design/hypha_colors.dart';
import 'package:hypha_wallet/ui/proposals/components/proposals_list.dart';
import 'package:hypha_wallet/ui/proposals/history/interactor/proposals_history_bloc.dart';
import 'package:hypha_wallet/ui/shared/hypha_body_widget.dart';

class ProposalsHistoryView extends StatelessWidget {
const ProposalsHistoryView({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: context.isDarkMode ? HyphaColors.darkBlack : HyphaColors.offWhite,
appBar: AppBar(
title: const Text('Proposals History'),
),
body: RefreshIndicator(
onRefresh: () async {
context.read<ProposalsHistoryBloc>().add(const ProposalsHistoryEvent.initial(refresh: true));
},
child: BlocBuilder<ProposalsHistoryBloc, ProposalsHistoryState>(
builder: (context, state) {
return HyphaBodyWidget(pageState: state.pageState, success: (context) {
return Container(
padding: const EdgeInsets.all(20),
child: ProposalsList(state.proposals),
);
});
}),
)
);
}
}
39 changes: 39 additions & 0 deletions lib/ui/proposals/history/interactor/proposals_history_bloc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import 'package:flutter_bloc/flutter_bloc.dart';
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/proposal_model.dart';
import 'package:hypha_wallet/ui/architecture/interactor/page_states.dart';
import 'package:hypha_wallet/ui/architecture/result/result.dart';
import 'package:hypha_wallet/ui/proposals/filter/interactor/filter_status.dart';
import 'package:hypha_wallet/ui/proposals/list/usecases/get_proposals_use_case.dart';

part 'proposals_history_bloc.freezed.dart';
part 'proposals_history_event.dart';
part 'proposals_history_state.dart';

class ProposalsHistoryBloc extends Bloc<ProposalsHistoryEvent, ProposalsHistoryState> {
final GetProposalsUseCase _getProposalsUseCase;
final ErrorHandlerManager _errorHandlerManager;
final DaoData _dao;

ProposalsHistoryBloc(this._getProposalsUseCase, this._errorHandlerManager, this._dao) : super(const ProposalsHistoryState()) {
on<_Initial>(_initial);
}

Future<void> _initial(_Initial event, Emitter<ProposalsHistoryState> emit) async {
if (!event.refresh) {
emit(state.copyWith(pageState: PageState.loading));
}

final Result<List<ProposalModel>, HyphaError> proposalsResult = await _getProposalsUseCase.run([_dao], FilterStatus.past);

if (proposalsResult.isValue) {
emit(state.copyWith(pageState: PageState.success, proposals: proposalsResult.asValue!.value));
} else {
await _errorHandlerManager.handlerError(proposalsResult.asError!.error);
emit(state.copyWith(pageState: PageState.failure));
}
}
}
Loading

0 comments on commit eb63b27

Please sign in to comment.