Skip to content

Commit 04c9ece

Browse files
refactor(cat-voices): rename SectionsController into SegmentsController (#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
1 parent 771ee64 commit 04c9ece

39 files changed

+857
-1041
lines changed

catalyst_voices/apps/voices/lib/pages/proposal_builder/proposal_builder_body.dart

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import 'package:catalyst_voices/pages/proposal_builder/proposal_builder_rich_text_step.dart';
2-
import 'package:catalyst_voices/widgets/navigation/sections_list_view.dart';
3-
import 'package:catalyst_voices/widgets/navigation/sections_list_view_builder.dart';
1+
import 'package:catalyst_voices/widgets/widgets.dart';
42
import 'package:catalyst_voices_view_models/catalyst_voices_view_models.dart';
53
import 'package:flutter/material.dart';
64
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
@@ -15,16 +13,15 @@ class ProposalBuilderBody extends StatelessWidget {
1513

1614
@override
1715
Widget build(BuildContext context) {
18-
return SectionsListViewBuilder(
16+
return SegmentsListViewBuilder(
1917
builder: (context, value, child) {
20-
return SectionsListView<WorkspaceSection, WorkspaceSectionStep>(
18+
return SegmentsListView<ProposalBuilderSegment, ProposalBuilderSection>(
2119
itemScrollController: itemScrollController,
2220
items: value,
23-
stepBuilder: (context, step) {
24-
switch (step) {
25-
case RichTextStep():
26-
return ProposalBuilderRichTextStep(step: step);
27-
}
21+
sectionBuilder: (context, data) {
22+
return Text(
23+
'${data.id}',
24+
);
2825
},
2926
);
3027
},

catalyst_voices/apps/voices/lib/pages/proposal_builder/proposal_builder_navigation_panel.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class ProposalBuilderNavigationPanel extends StatelessWidget {
1414
tabs: [
1515
SpaceSidePanelTab(
1616
name: context.l10n.workspaceProposalNavigationSegments,
17-
body: SectionsMenuListener(
18-
controller: SectionsControllerScope.of(context),
17+
body: SegmentsMenuListener(
18+
controller: SegmentsControllerScope.of(context),
1919
),
2020
),
2121
],

catalyst_voices/apps/voices/lib/pages/proposal_builder/proposal_builder_page.dart

+25-25
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import 'dart:async';
33
import 'package:catalyst_voices/pages/proposal_builder/proposal_builder_body.dart';
44
import 'package:catalyst_voices/pages/proposal_builder/proposal_builder_navigation_panel.dart';
55
import 'package:catalyst_voices/pages/proposal_builder/proposal_builder_setup_panel.dart';
6-
import 'package:catalyst_voices/widgets/containers/space_scaffold.dart';
7-
import 'package:catalyst_voices/widgets/navigation/sections_controller.dart';
6+
import 'package:catalyst_voices/widgets/widgets.dart';
87
import 'package:catalyst_voices_blocs/catalyst_voices_blocs.dart';
8+
import 'package:catalyst_voices_models/catalyst_voices_models.dart';
99
import 'package:catalyst_voices_view_models/catalyst_voices_view_models.dart';
1010
import 'package:flutter/foundation.dart';
1111
import 'package:flutter/material.dart';
@@ -25,29 +25,29 @@ class ProposalBuilderPage extends StatefulWidget {
2525
}
2626

2727
class _ProposalBuilderPageState extends State<ProposalBuilderPage> {
28-
late final SectionsController _sectionsController;
28+
late final SegmentsController _segmentsController;
2929
late final ItemScrollController _bodyItemScrollController;
3030

31-
SectionStepId? _activeStepId;
32-
StreamSubscription<List<Section>>? _sectionsSub;
31+
NodeId? _activeSegmentId;
32+
StreamSubscription<List<Segment>>? _segmentsSub;
3333

3434
@override
3535
void initState() {
3636
super.initState();
3737

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

40-
_sectionsController = SectionsController();
40+
_segmentsController = SegmentsController();
4141
_bodyItemScrollController = ItemScrollController();
4242

43-
_sectionsController
43+
_segmentsController
4444
..addListener(_handleSectionsControllerChange)
4545
..attachItemsScrollController(_bodyItemScrollController);
4646

47-
_sectionsSub = bloc.stream
48-
.map((event) => event.sections)
47+
_segmentsSub = bloc.stream
48+
.map((event) => event.segments)
4949
.distinct(listEquals)
50-
.listen(_updateSections);
50+
.listen(_updateSegments);
5151

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

6565
@override
6666
void dispose() {
67-
unawaited(_sectionsSub?.cancel());
68-
_sectionsSub = null;
67+
unawaited(_segmentsSub?.cancel());
68+
_segmentsSub = null;
6969

70-
_sectionsController.dispose();
70+
_segmentsController.dispose();
7171
super.dispose();
7272
}
7373

7474
@override
7575
Widget build(BuildContext context) {
76-
return SectionsControllerScope(
77-
controller: _sectionsController,
76+
return SegmentsControllerScope(
77+
controller: _segmentsController,
7878
child: SpaceScaffold(
7979
left: const ProposalBuilderNavigationPanel(),
8080
body: ProposalBuilderBody(
@@ -85,23 +85,23 @@ class _ProposalBuilderPageState extends State<ProposalBuilderPage> {
8585
);
8686
}
8787

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

91-
final newState = state.sections.isEmpty
92-
? SectionsControllerState.initial(sections: data)
93-
: state.copyWith(sections: data);
91+
final newState = state.segments.isEmpty
92+
? SegmentsControllerState.initial(segments: data)
93+
: state.copyWith(segments: data);
9494

95-
_sectionsController.value = newState;
95+
_segmentsController.value = newState;
9696
}
9797

9898
void _handleSectionsControllerChange() {
99-
final activeStepId = _sectionsController.value.activeStepId;
99+
final activeSectionId = _segmentsController.value.activeSectionId;
100100

101-
if (_activeStepId != activeStepId) {
102-
_activeStepId = activeStepId;
101+
if (_activeSegmentId != activeSectionId) {
102+
_activeSegmentId = activeSectionId;
103103

104-
final event = ActiveStepChangedEvent(activeStepId);
104+
final event = ActiveStepChangedEvent(activeSectionId);
105105
context.read<ProposalBuilderBloc>().add(event);
106106
}
107107
}

catalyst_voices/apps/voices/lib/pages/proposal_builder/proposal_builder_rich_text_step.dart

-128
This file was deleted.

catalyst_voices/apps/voices/lib/pages/treasury/steps/treasury_campaign_details_step.dart catalyst_voices/apps/voices/lib/pages/treasury/sections/treasury_campaign_categories_step.dart

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
1-
import 'package:catalyst_voices/widgets/navigation/section_step_state_builder.dart';
21
import 'package:catalyst_voices/widgets/widgets.dart';
32
import 'package:catalyst_voices_localization/catalyst_voices_localization.dart';
43
import 'package:catalyst_voices_view_models/catalyst_voices_view_models.dart';
54
import 'package:flutter/material.dart';
65

7-
class TreasuryCampaignDetailsStep extends StatelessWidget {
8-
final TreasurySectionStep step;
6+
class TreasuryCampaignCategoriesTile extends StatelessWidget {
7+
final TreasurySection data;
98

10-
const TreasuryCampaignDetailsStep({
9+
const TreasuryCampaignCategoriesTile(
10+
this.data, {
1111
super.key,
12-
required this.step,
1312
});
1413

1514
@override
1615
Widget build(BuildContext context) {
17-
return SectionStepStateBuilder(
18-
id: step.sectionStepId,
16+
return SectionStateBuilder(
17+
id: data.id,
1918
builder: (context, value, child) {
2019
return WorkspaceTextTileContainer(
21-
name: step.localizedDesc(context),
20+
name: data.resolveDesc(context) ?? data.resolveTitle(context),
2221
isSelected: value.isSelected,
2322
headerActions: [
2423
VoicesTextButton(
25-
onTap: step.isEditable ? () {} : null,
24+
onTap: data.isEditable ? () {} : null,
2625
child: Text(context.l10n.stepEdit),
2726
),
2827
],
29-
content: step.localizedDesc(context),
28+
content: data.resolveDesc(context) ?? data.resolveTitle(context),
3029
);
3130
},
3231
);

catalyst_voices/apps/voices/lib/pages/treasury/steps/treasury_proposal_template_step.dart catalyst_voices/apps/voices/lib/pages/treasury/sections/treasury_campaign_details_tile.dart

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
1-
import 'package:catalyst_voices/widgets/navigation/section_step_state_builder.dart';
21
import 'package:catalyst_voices/widgets/widgets.dart';
32
import 'package:catalyst_voices_localization/catalyst_voices_localization.dart';
43
import 'package:catalyst_voices_view_models/catalyst_voices_view_models.dart';
54
import 'package:flutter/material.dart';
65

7-
class TreasuryProposalTemplateStep extends StatelessWidget {
8-
final TreasurySectionStep step;
6+
class TreasuryCampaignDetailsTile extends StatelessWidget {
7+
final TreasurySection data;
98

10-
const TreasuryProposalTemplateStep({
9+
const TreasuryCampaignDetailsTile(
10+
this.data, {
1111
super.key,
12-
required this.step,
1312
});
1413

1514
@override
1615
Widget build(BuildContext context) {
17-
return SectionStepStateBuilder(
18-
id: step.sectionStepId,
16+
return SectionStateBuilder(
17+
id: data.id,
1918
builder: (context, value, child) {
2019
return WorkspaceTextTileContainer(
21-
name: step.localizedDesc(context),
20+
name: data.resolveDesc(context) ?? data.resolveTitle(context),
2221
isSelected: value.isSelected,
2322
headerActions: [
2423
VoicesTextButton(
25-
onTap: step.isEditable ? () {} : null,
24+
onTap: data.isEditable ? () {} : null,
2625
child: Text(context.l10n.stepEdit),
2726
),
2827
],
29-
content: step.localizedDesc(context),
28+
content: data.resolveDesc(context) ?? data.resolveTitle(context),
3029
);
3130
},
3231
);

0 commit comments

Comments
 (0)