Skip to content

Commit

Permalink
feat: emit section changes to bloc
Browse files Browse the repository at this point in the history
  • Loading branch information
damian-molinski committed Jan 14, 2025
1 parent 4d59e21 commit 9293d37
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class _ProposalBuilderSegments extends StatelessWidget {
key: key,
section: data.documentSection,
onChanged: (value) {
print('Section[${data.id}] changes: $value');
final event = SectionChangedEvent(changes: value);
context.read<ProposalBuilderBloc>().add(event);
},
);
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import 'package:catalyst_voices/widgets/document_builder/agreement_confirmation_widget.dart';
import 'package:catalyst_voices/widgets/document_builder/document_token_value_widget.dart';
import 'package:catalyst_voices/widgets/document_builder/single_dropdown_selection_widget.dart';
import 'package:catalyst_voices/widgets/document_builder/single_grouped_tag_selector_widget.dart';
import 'package:catalyst_voices/widgets/document_builder/single_line_https_url_widget.dart.dart';
import 'package:catalyst_voices/widgets/widgets.dart';
import 'package:catalyst_voices_localization/catalyst_voices_localization.dart';
import 'package:catalyst_voices_models/catalyst_voices_models.dart';
Expand Down Expand Up @@ -223,24 +218,24 @@ class _PropertyBuilder extends StatelessWidget {
case LanguageCodeDefinition():
return Text('${definition.runtimeType} not implemented');
case SingleLineHttpsURLEntryDefinition():
final castProperty = definition.castProperty(property);
/* final castProperty = definition.castProperty(property);
return SingleLineHttpsUrlWidget(
property: castProperty,
isEditMode: isEditMode,
onChanged: onChanged,
);
);*/
case SingleGroupedTagSelectorDefinition():
final castProperty = definition.castProperty(property);
/* final castProperty = definition.castProperty(property);
return SingleGroupedTagSelectorWidget(
id: castProperty.schema.nodeId,
selection: castProperty.value ?? const GroupedTagsSelection(),
groupedTags: definition.groupedTags(castProperty.schema),
isEditMode: isEditMode,
onChanged: onChanged,
isRequired: castProperty.schema.isRequired,
);
);*/
case DropDownSingleSelectDefinition():
final castProperty = definition.castProperty(property);
/* final castProperty = definition.castProperty(property);
return SingleDropdownSelectionWidget(
value: castProperty.value ?? castProperty.schema.defaultValue ?? '',
items: castProperty.schema.enumValues ?? [],
Expand All @@ -250,9 +245,9 @@ class _PropertyBuilder extends StatelessWidget {
isEditMode: isEditMode,
isRequired: castProperty.schema.isRequired,
onChanged: onChanged,
);
);*/
case AgreementConfirmationDefinition():
final castProperty = definition.castProperty(property);
/*final castProperty = definition.castProperty(property);
return AgreementConfirmationWidget(
value: castProperty.value,
definition: definition,
Expand All @@ -261,14 +256,15 @@ class _PropertyBuilder extends StatelessWidget {
title: castProperty.schema.title ?? '',
isEditMode: isEditMode,
onChanged: onChanged,
);
);*/
case TokenValueCardanoADADefinition():
return DocumentTokenValueWidget(
/*return DocumentTokenValueWidget(
property: definition.castProperty(property),
currency: const Currency.ada(),
isEditMode: isEditMode,
onChanged: onChanged,
);
);*/
return Text('${definition.runtimeType} casting problem');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,32 @@ final class ProposalBuilderBloc
_handleActiveStepEvent,
transformer: (events, mapper) => events.distinct(),
);
on<SectionChangedEvent>(_handleSectionChangedEvent);
}

void _handleActiveStepEvent(
ActiveNodeChangedEvent event,
Emitter<ProposalBuilderState> emit,
) {
_logger.info('Active node changed to [${event.id}]');

// TODO(damian-molinski): Show guidance for this node and its parents.
_activeNodeId = event.id;
}

void _handleSectionChangedEvent(
SectionChangedEvent event,
Emitter<ProposalBuilderState> emit,
) {
final documentBuilder = _documentBuilder;
assert(documentBuilder != null, 'DocumentBuilder not initialized');

documentBuilder!.addChanges(event.changes);
final document = documentBuilder.build();
final segments = _mapDocumentToSegments(document);

// TODO(damian-molinski): Get guidance + convert to MarkdownData
emit(state.copyWith(segments: segments));
}

Future<void> _loadDefaultProposalTemplate(
Expand Down Expand Up @@ -102,15 +128,6 @@ final class ProposalBuilderBloc
);
}

void _handleActiveStepEvent(
ActiveNodeChangedEvent event,
Emitter<ProposalBuilderState> emit,
) {
_logger.info('Active node changed to [${event.id}]');

_activeNodeId = event.id;
}

Future<void> _loadDocument({
required AsyncValueGetter<DocumentBuilder> documentBuilderGetter,
required Emitter<ProposalBuilderState> emit,
Expand All @@ -129,6 +146,7 @@ final class ProposalBuilderBloc
final document = documentBuilder.build();
final segments = _mapDocumentToSegments(document);

// TODO(damian-molinski): Get guidance + convert to MarkdownData
emit(ProposalBuilderState(segments: segments));
} on LocalizedException catch (error) {
emit(ProposalBuilderState(error: error));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,14 @@ final class ActiveNodeChangedEvent extends ProposalBuilderEvent {
@override
List<Object?> get props => [id];
}

final class SectionChangedEvent extends ProposalBuilderEvent {
final List<DocumentChange> changes;

const SectionChangedEvent({
required this.changes,
});

@override
List<Object?> get props => [changes];
}

0 comments on commit 9293d37

Please sign in to comment.