From dbe91452ef5be562e0f1cde06feecc2c1734c072 Mon Sep 17 00:00:00 2001 From: Saif Nbet Date: Wed, 9 Oct 2024 16:16:23 +0100 Subject: [PATCH] feat: Implement dao selection screen --- .../cards/hypha_option_card.dart} | 4 +- .../components/dao_selection_view.dart | 64 +++++++++++++++++++ .../components/filter_proposals_view.dart | 6 +- .../list/components/proposals_view.dart | 4 +- .../list/interactor/proposals_bloc.dart | 4 +- 5 files changed, 74 insertions(+), 8 deletions(-) rename lib/{ui/proposals/filter/components/hypha_filter_card.dart => design/cards/hypha_option_card.dart} (95%) create mode 100644 lib/ui/proposals/creation/components/dao_selection_view.dart diff --git a/lib/ui/proposals/filter/components/hypha_filter_card.dart b/lib/design/cards/hypha_option_card.dart similarity index 95% rename from lib/ui/proposals/filter/components/hypha_filter_card.dart rename to lib/design/cards/hypha_option_card.dart index d36a1ebc..65ce7816 100644 --- a/lib/ui/proposals/filter/components/hypha_filter_card.dart +++ b/lib/design/cards/hypha_option_card.dart @@ -5,14 +5,14 @@ import 'package:hypha_wallet/design/hypha_card.dart'; import 'package:hypha_wallet/design/hypha_colors.dart'; import 'package:hypha_wallet/design/themes/extensions/theme_extension_provider.dart'; -class HyphaFilterCard extends StatelessWidget { +class HyphaOptionCard extends StatelessWidget { final DaoData? dao; final String? title; final String? subTitle; final dynamic valueNotifier; final int index; - const HyphaFilterCard(this.valueNotifier, this.index, + const HyphaOptionCard(this.valueNotifier, this.index, {this.dao, this.title, this.subTitle, super.key}); @override diff --git a/lib/ui/proposals/creation/components/dao_selection_view.dart b/lib/ui/proposals/creation/components/dao_selection_view.dart new file mode 100644 index 00000000..a72633e2 --- /dev/null +++ b/lib/ui/proposals/creation/components/dao_selection_view.dart @@ -0,0 +1,64 @@ +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import 'package:get_it/get_it.dart'; +import 'package:hypha_wallet/core/network/models/dao_data_model.dart'; +import 'package:hypha_wallet/design/cards/hypha_option_card.dart'; +import 'package:hypha_wallet/design/hypha_colors.dart'; +import 'package:hypha_wallet/design/themes/extensions/theme_extension_provider.dart'; +import 'package:hypha_wallet/ui/proposals/list/interactor/proposals_bloc.dart'; + +class DaoSelectionView extends StatefulWidget { + const DaoSelectionView({super.key}); + + @override + State createState() => _DaoSelectionViewState(); +} + +class _DaoSelectionViewState extends State { + late List daos; + final ValueNotifier selectedDaoIndexNotifier = ValueNotifier(0); + + @override + void initState() { + super.initState(); + daos = GetIt.I.get().daos; + } + + @override + Widget build(BuildContext context) { + return Container( + height: MediaQuery.sizeOf(context).height, + color: context.isDarkMode ? HyphaColors.darkBlack : HyphaColors.offWhite, + padding: const EdgeInsets.symmetric(horizontal: 20), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const SizedBox(height: 20), + Text( + 'Select a DAO', + style: context.hyphaTextTheme.smallTitles + .copyWith(color: HyphaColors.primaryBlu), + ), + Padding( + padding: const EdgeInsets.only(top: 20, bottom: 30), + child: Text( + 'On which of your DAO you want to publish a proposal? Please select one from the list.', + style: context.hyphaTextTheme.ralMediumBody + .copyWith(color: HyphaColors.midGrey), + ), + ), + ...List.generate( + daos.length, + (index) { + return Container( + margin: const EdgeInsets.symmetric(vertical: 10), + child: HyphaOptionCard( + dao: daos[index], selectedDaoIndexNotifier, index), + ); + }, + ) + ], + ), + ); + } +} diff --git a/lib/ui/proposals/filter/components/filter_proposals_view.dart b/lib/ui/proposals/filter/components/filter_proposals_view.dart index f9fdf372..57c136b3 100644 --- a/lib/ui/proposals/filter/components/filter_proposals_view.dart +++ b/lib/ui/proposals/filter/components/filter_proposals_view.dart @@ -4,7 +4,7 @@ import 'package:get/get.dart'; import 'package:hypha_wallet/design/buttons/hypha_app_button.dart'; import 'package:hypha_wallet/design/hypha_colors.dart'; import 'package:hypha_wallet/design/themes/extensions/theme_extension_provider.dart'; -import 'package:hypha_wallet/ui/proposals/filter/components/hypha_filter_card.dart'; +import 'package:hypha_wallet/design/cards/hypha_option_card.dart'; import 'package:hypha_wallet/ui/proposals/filter/interactor/filter_proposals_bloc.dart'; import 'package:hypha_wallet/ui/proposals/filter/interactor/filter_status.dart'; import 'package:hypha_wallet/ui/shared/hypha_body_widget.dart'; @@ -43,7 +43,7 @@ class FilterProposalsView extends StatelessWidget { (index) { return Container( margin: const EdgeInsets.symmetric(vertical: 10), - child: HyphaFilterCard( + child: HyphaOptionCard( dao: state.daoProposalCounts[index].dao, subTitle: '${state.daoProposalCounts[index].proposalCount} ${filterProposalsBloc.selectedStatusIndexNotifier.value == 0 ? 'Active' : 'Past'} Proposal${state.daoProposalCounts[index].proposalCount == 1 ? '' : 's'}', filterProposalsBloc.selectedDaoIndexNotifier, @@ -63,7 +63,7 @@ class FilterProposalsView extends StatelessWidget { (index) { return Container( margin: const EdgeInsets.symmetric(vertical: 10), - child: HyphaFilterCard( + child: HyphaOptionCard( title: _statusFilters[index], filterProposalsBloc.selectedStatusIndexNotifier, index, diff --git a/lib/ui/proposals/list/components/proposals_view.dart b/lib/ui/proposals/list/components/proposals_view.dart index dcb52583..1dfd20c9 100644 --- a/lib/ui/proposals/list/components/proposals_view.dart +++ b/lib/ui/proposals/list/components/proposals_view.dart @@ -74,6 +74,7 @@ class ProposalsView extends StatelessWidget { context .read() .add(const ProposalsEvent.initial(refresh: true)); + }, child: Container( margin: const EdgeInsets.only(top: 20), @@ -172,7 +173,8 @@ class ProposalsView extends StatelessWidget { }, ), )), - floatingActionButton: IconButton( + floatingActionButton:context + .read().daos.isEmpty?null: IconButton( onPressed: () { GetX.Get.to(() => const ProposalCreationPage(), transition: GetX.Transition.leftToRight); }, diff --git a/lib/ui/proposals/list/interactor/proposals_bloc.dart b/lib/ui/proposals/list/interactor/proposals_bloc.dart index bc2eed9d..8eddb2b6 100644 --- a/lib/ui/proposals/list/interactor/proposals_bloc.dart +++ b/lib/ui/proposals/list/interactor/proposals_bloc.dart @@ -23,7 +23,7 @@ class ProposalsBloc extends Bloc { final GetProposalsUseCase _getProposalsUseCase; final FetchProfileUseCase _fetchProfileUseCase; final ErrorHandlerManager _errorHandlerManager; - + List daos=[]; ProposalsBloc(this._getProposalsUseCase, this._fetchProfileUseCase, this._errorHandlerManager) : super(const ProposalsState()) { @@ -48,7 +48,7 @@ class ProposalsBloc extends Bloc { await _fetchProfileUseCase.run(); if (profileResult.isValue && profileResult.asValue!.value.daos.isNotEmpty) { - final List daos = profileResult.asValue!.value.daos; + daos = profileResult.asValue!.value.daos; // Fetch Proposals using the fetched DAOs final Result, HyphaError> proposalsResult =