Skip to content

Commit

Permalink
refactor(cat-voices): rename SectionsController into SegmentsControll…
Browse files Browse the repository at this point in the history
…er (#1484)

* refactor: rename SectionsController into SegmentController and all related components

* chore: cleanup ProposalBuilderBloc

* test: DocumentNodeId

* fix: failing test and bug in DocumentNodeId

* chore: remove UpdateStepAnswerEvent

* chore: rollback paths getter in DocumentNodeId
  • Loading branch information
damian-molinski authored Jan 9, 2025
1 parent 771ee64 commit 04c9ece
Show file tree
Hide file tree
Showing 39 changed files with 857 additions and 1,041 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import 'package:catalyst_voices/pages/proposal_builder/proposal_builder_rich_text_step.dart';
import 'package:catalyst_voices/widgets/navigation/sections_list_view.dart';
import 'package:catalyst_voices/widgets/navigation/sections_list_view_builder.dart';
import 'package:catalyst_voices/widgets/widgets.dart';
import 'package:catalyst_voices_view_models/catalyst_voices_view_models.dart';
import 'package:flutter/material.dart';
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
Expand All @@ -15,16 +13,15 @@ class ProposalBuilderBody extends StatelessWidget {

@override
Widget build(BuildContext context) {
return SectionsListViewBuilder(
return SegmentsListViewBuilder(
builder: (context, value, child) {
return SectionsListView<WorkspaceSection, WorkspaceSectionStep>(
return SegmentsListView<ProposalBuilderSegment, ProposalBuilderSection>(
itemScrollController: itemScrollController,
items: value,
stepBuilder: (context, step) {
switch (step) {
case RichTextStep():
return ProposalBuilderRichTextStep(step: step);
}
sectionBuilder: (context, data) {
return Text(
'${data.id}',
);
},
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class ProposalBuilderNavigationPanel extends StatelessWidget {
tabs: [
SpaceSidePanelTab(
name: context.l10n.workspaceProposalNavigationSegments,
body: SectionsMenuListener(
controller: SectionsControllerScope.of(context),
body: SegmentsMenuListener(
controller: SegmentsControllerScope.of(context),
),
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import 'dart:async';
import 'package:catalyst_voices/pages/proposal_builder/proposal_builder_body.dart';
import 'package:catalyst_voices/pages/proposal_builder/proposal_builder_navigation_panel.dart';
import 'package:catalyst_voices/pages/proposal_builder/proposal_builder_setup_panel.dart';
import 'package:catalyst_voices/widgets/containers/space_scaffold.dart';
import 'package:catalyst_voices/widgets/navigation/sections_controller.dart';
import 'package:catalyst_voices/widgets/widgets.dart';
import 'package:catalyst_voices_blocs/catalyst_voices_blocs.dart';
import 'package:catalyst_voices_models/catalyst_voices_models.dart';
import 'package:catalyst_voices_view_models/catalyst_voices_view_models.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
Expand All @@ -25,29 +25,29 @@ class ProposalBuilderPage extends StatefulWidget {
}

class _ProposalBuilderPageState extends State<ProposalBuilderPage> {
late final SectionsController _sectionsController;
late final SegmentsController _segmentsController;
late final ItemScrollController _bodyItemScrollController;

SectionStepId? _activeStepId;
StreamSubscription<List<Section>>? _sectionsSub;
NodeId? _activeSegmentId;
StreamSubscription<List<Segment>>? _segmentsSub;

@override
void initState() {
super.initState();

final bloc = context.read<ProposalBuilderBloc>();

_sectionsController = SectionsController();
_segmentsController = SegmentsController();
_bodyItemScrollController = ItemScrollController();

_sectionsController
_segmentsController
..addListener(_handleSectionsControllerChange)
..attachItemsScrollController(_bodyItemScrollController);

_sectionsSub = bloc.stream
.map((event) => event.sections)
_segmentsSub = bloc.stream
.map((event) => event.segments)
.distinct(listEquals)
.listen(_updateSections);
.listen(_updateSegments);

bloc.add(LoadProposalEvent(id: widget.proposalId));
}
Expand All @@ -64,17 +64,17 @@ class _ProposalBuilderPageState extends State<ProposalBuilderPage> {

@override
void dispose() {
unawaited(_sectionsSub?.cancel());
_sectionsSub = null;
unawaited(_segmentsSub?.cancel());
_segmentsSub = null;

_sectionsController.dispose();
_segmentsController.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return SectionsControllerScope(
controller: _sectionsController,
return SegmentsControllerScope(
controller: _segmentsController,
child: SpaceScaffold(
left: const ProposalBuilderNavigationPanel(),
body: ProposalBuilderBody(
Expand All @@ -85,23 +85,23 @@ class _ProposalBuilderPageState extends State<ProposalBuilderPage> {
);
}

void _updateSections(List<Section> data) {
final state = _sectionsController.value;
void _updateSegments(List<Segment> data) {
final state = _segmentsController.value;

final newState = state.sections.isEmpty
? SectionsControllerState.initial(sections: data)
: state.copyWith(sections: data);
final newState = state.segments.isEmpty
? SegmentsControllerState.initial(segments: data)
: state.copyWith(segments: data);

_sectionsController.value = newState;
_segmentsController.value = newState;
}

void _handleSectionsControllerChange() {
final activeStepId = _sectionsController.value.activeStepId;
final activeSectionId = _segmentsController.value.activeSectionId;

if (_activeStepId != activeStepId) {
_activeStepId = activeStepId;
if (_activeSegmentId != activeSectionId) {
_activeSegmentId = activeSectionId;

final event = ActiveStepChangedEvent(activeStepId);
final event = ActiveStepChangedEvent(activeSectionId);
context.read<ProposalBuilderBloc>().add(event);
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
import 'package:catalyst_voices/widgets/navigation/section_step_state_builder.dart';
import 'package:catalyst_voices/widgets/widgets.dart';
import 'package:catalyst_voices_localization/catalyst_voices_localization.dart';
import 'package:catalyst_voices_view_models/catalyst_voices_view_models.dart';
import 'package:flutter/material.dart';

class TreasuryCampaignDetailsStep extends StatelessWidget {
final TreasurySectionStep step;
class TreasuryCampaignCategoriesTile extends StatelessWidget {
final TreasurySection data;

const TreasuryCampaignDetailsStep({
const TreasuryCampaignCategoriesTile(
this.data, {
super.key,
required this.step,
});

@override
Widget build(BuildContext context) {
return SectionStepStateBuilder(
id: step.sectionStepId,
return SectionStateBuilder(
id: data.id,
builder: (context, value, child) {
return WorkspaceTextTileContainer(
name: step.localizedDesc(context),
name: data.resolveDesc(context) ?? data.resolveTitle(context),
isSelected: value.isSelected,
headerActions: [
VoicesTextButton(
onTap: step.isEditable ? () {} : null,
onTap: data.isEditable ? () {} : null,
child: Text(context.l10n.stepEdit),
),
],
content: step.localizedDesc(context),
content: data.resolveDesc(context) ?? data.resolveTitle(context),
);
},
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
import 'package:catalyst_voices/widgets/navigation/section_step_state_builder.dart';
import 'package:catalyst_voices/widgets/widgets.dart';
import 'package:catalyst_voices_localization/catalyst_voices_localization.dart';
import 'package:catalyst_voices_view_models/catalyst_voices_view_models.dart';
import 'package:flutter/material.dart';

class TreasuryProposalTemplateStep extends StatelessWidget {
final TreasurySectionStep step;
class TreasuryCampaignDetailsTile extends StatelessWidget {
final TreasurySection data;

const TreasuryProposalTemplateStep({
const TreasuryCampaignDetailsTile(
this.data, {
super.key,
required this.step,
});

@override
Widget build(BuildContext context) {
return SectionStepStateBuilder(
id: step.sectionStepId,
return SectionStateBuilder(
id: data.id,
builder: (context, value, child) {
return WorkspaceTextTileContainer(
name: step.localizedDesc(context),
name: data.resolveDesc(context) ?? data.resolveTitle(context),
isSelected: value.isSelected,
headerActions: [
VoicesTextButton(
onTap: step.isEditable ? () {} : null,
onTap: data.isEditable ? () {} : null,
child: Text(context.l10n.stepEdit),
),
],
content: step.localizedDesc(context),
content: data.resolveDesc(context) ?? data.resolveTitle(context),
);
},
);
Expand Down
Loading

0 comments on commit 04c9ece

Please sign in to comment.