-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/proposal-template-models' of github.com:input-outp…
…ut-hk/catalyst-voices into feat/proposal-template-models
- Loading branch information
Showing
32 changed files
with
1,069 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
catalyst_voices/apps/voices/lib/pages/proposal_builder/proposal_builder.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export 'proposal_builder_page.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
catalyst_voices/apps/voices/lib/pages/proposal_builder/proposal_builder_page.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
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_blocs/catalyst_voices_blocs.dart'; | ||
import 'package:catalyst_voices_view_models/catalyst_voices_view_models.dart'; | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart'; | ||
|
||
class ProposalBuilderPage extends StatefulWidget { | ||
final String proposalId; | ||
|
||
const ProposalBuilderPage({ | ||
super.key, | ||
required this.proposalId, | ||
}); | ||
|
||
@override | ||
State<ProposalBuilderPage> createState() => _ProposalBuilderPageState(); | ||
} | ||
|
||
class _ProposalBuilderPageState extends State<ProposalBuilderPage> { | ||
late final SectionsController _sectionsController; | ||
late final ItemScrollController _bodyItemScrollController; | ||
|
||
SectionStepId? _activeStepId; | ||
StreamSubscription<List<Section>>? _sectionsSub; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
|
||
final bloc = context.read<ProposalBuilderBloc>(); | ||
|
||
_sectionsController = SectionsController(); | ||
_bodyItemScrollController = ItemScrollController(); | ||
|
||
_sectionsController | ||
..addListener(_handleSectionsControllerChange) | ||
..attachItemsScrollController(_bodyItemScrollController); | ||
|
||
_sectionsSub = bloc.stream | ||
.map((event) => event.sections) | ||
.distinct(listEquals) | ||
.listen(_updateSections); | ||
|
||
bloc.add(LoadProposalEvent(id: widget.proposalId)); | ||
} | ||
|
||
@override | ||
void didUpdateWidget(covariant ProposalBuilderPage oldWidget) { | ||
super.didUpdateWidget(oldWidget); | ||
|
||
if (widget.proposalId != oldWidget.proposalId) { | ||
final event = LoadProposalEvent(id: widget.proposalId); | ||
context.read<ProposalBuilderBloc>().add(event); | ||
} | ||
} | ||
|
||
@override | ||
void dispose() { | ||
unawaited(_sectionsSub?.cancel()); | ||
_sectionsSub = null; | ||
|
||
_sectionsController.dispose(); | ||
super.dispose(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return SectionsControllerScope( | ||
controller: _sectionsController, | ||
child: SpaceScaffold( | ||
left: const ProposalBuilderNavigationPanel(), | ||
body: ProposalBuilderBody( | ||
itemScrollController: _bodyItemScrollController, | ||
), | ||
right: const ProposalBuilderSetupPanel(), | ||
), | ||
); | ||
} | ||
|
||
void _updateSections(List<Section> data) { | ||
final state = _sectionsController.value; | ||
|
||
final newState = state.sections.isEmpty | ||
? SectionsControllerState.initial(sections: data) | ||
: state.copyWith(sections: data); | ||
|
||
_sectionsController.value = newState; | ||
} | ||
|
||
void _handleSectionsControllerChange() { | ||
final activeStepId = _sectionsController.value.activeStepId; | ||
|
||
if (_activeStepId != activeStepId) { | ||
_activeStepId = activeStepId; | ||
|
||
final event = ActiveStepChangedEvent(activeStepId); | ||
context.read<ProposalBuilderBloc>().add(event); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
catalyst_voices/apps/voices/lib/pages/workspace/workspace_empty_state.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import 'package:catalyst_voices/widgets/empty_state/empty_state.dart'; | ||
import 'package:catalyst_voices_blocs/catalyst_voices_blocs.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
|
||
class WorkspaceEmptyStateSelector extends StatelessWidget { | ||
const WorkspaceEmptyStateSelector({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return BlocSelector<WorkspaceBloc, WorkspaceState, bool>( | ||
selector: (state) => state.showEmptyState, | ||
builder: (context, state) { | ||
return Offstage( | ||
offstage: !state, | ||
child: const _WorkspaceEmptyState(), | ||
); | ||
}, | ||
); | ||
} | ||
} | ||
|
||
class _WorkspaceEmptyState extends StatelessWidget { | ||
const _WorkspaceEmptyState(); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
// TODO(damian-molinski): Strings and looks is not final | ||
return const Center( | ||
child: EmptyState( | ||
title: 'No proposals found', | ||
description: 'Created proposals will appear here', | ||
), | ||
); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
catalyst_voices/apps/voices/lib/pages/workspace/workspace_error.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import 'package:catalyst_voices/widgets/widgets.dart'; | ||
import 'package:catalyst_voices_blocs/catalyst_voices_blocs.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'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
|
||
typedef _StateData = ({bool show, LocalizedException? error}); | ||
|
||
class WorkspaceErrorSelector extends StatelessWidget { | ||
const WorkspaceErrorSelector({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return BlocSelector<WorkspaceBloc, WorkspaceState, _StateData>( | ||
selector: (state) => (show: state.showError, error: state.error), | ||
builder: (context, state) { | ||
final errorMessage = state.error?.message(context); | ||
|
||
return Offstage( | ||
offstage: !state.show, | ||
child: _WorkspaceError( | ||
message: errorMessage ?? context.l10n.somethingWentWrong, | ||
), | ||
); | ||
}, | ||
); | ||
} | ||
} | ||
|
||
class _WorkspaceError extends StatelessWidget { | ||
final String message; | ||
|
||
const _WorkspaceError({ | ||
required this.message, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Center( | ||
child: VoicesErrorIndicator( | ||
message: message, | ||
onRetry: () { | ||
const event = LoadProposalsEvent(); | ||
context.read<WorkspaceBloc>().add(event); | ||
}, | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.