Skip to content

Commit 03c7cc6

Browse files
authored
feat: adding view all proposals (#2299)
1 parent 21511b8 commit 03c7cc6

File tree

4 files changed

+72
-14
lines changed

4 files changed

+72
-14
lines changed

catalyst_voices/apps/voices/lib/pages/discovery/sections/most_recent_proposals.dart

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,49 @@ class MostRecentProposals extends StatefulWidget {
2828
State<MostRecentProposals> createState() => _LatestProposalsState();
2929
}
3030

31+
class ViewAllProposals extends StatelessWidget {
32+
const ViewAllProposals({super.key});
33+
34+
@override
35+
Widget build(BuildContext context) {
36+
return const _Background(
37+
key: Key('MostRecentViewAllProposals'),
38+
constraints: BoxConstraints(maxHeight: 184),
39+
child: Center(
40+
child: _ViewAllProposalsButton(),
41+
),
42+
);
43+
}
44+
}
45+
46+
class _Background extends StatelessWidget {
47+
final Widget child;
48+
final BoxConstraints constraints;
49+
50+
const _Background({
51+
super.key,
52+
required this.child,
53+
this.constraints = const BoxConstraints(maxHeight: 900),
54+
});
55+
56+
@override
57+
Widget build(BuildContext context) {
58+
return Container(
59+
key: const Key('MostRecentProposals'),
60+
constraints: constraints,
61+
decoration: BoxDecoration(
62+
image: DecorationImage(
63+
image: CatalystImage.asset(
64+
VoicesAssets.images.campaignHero.path,
65+
).image,
66+
fit: BoxFit.cover,
67+
),
68+
),
69+
child: child,
70+
);
71+
}
72+
}
73+
3174
class _LatestProposalsState extends State<MostRecentProposals> {
3275
late final ScrollController _scrollController;
3376
late double _scrollPercentage;
@@ -116,15 +159,7 @@ class _LatestProposalsState extends State<MostRecentProposals> {
116159
),
117160
),
118161
const SizedBox(height: 16),
119-
VoicesFilledButton(
120-
backgroundColor: ThemeBuilder.buildTheme().colorScheme.onPrimary,
121-
foregroundColor: ThemeBuilder.buildTheme().colorScheme.primary,
122-
child: Text(
123-
key: const Key('ViewAllProposalsBtn'),
124-
context.l10n.viewAllProposals,
125-
),
126-
onTap: () => const ProposalsRoute().go(context),
127-
),
162+
const _ViewAllProposalsButton(),
128163
const SizedBox(height: 72),
129164
],
130165
),
@@ -170,3 +205,20 @@ class _LatestProposalsState extends State<MostRecentProposals> {
170205
_scrollController.jumpTo(maxScroll * value);
171206
}
172207
}
208+
209+
class _ViewAllProposalsButton extends StatelessWidget {
210+
const _ViewAllProposalsButton();
211+
212+
@override
213+
Widget build(BuildContext context) {
214+
return VoicesFilledButton(
215+
backgroundColor: ThemeBuilder.buildTheme().colorScheme.onPrimary,
216+
foregroundColor: ThemeBuilder.buildTheme().colorScheme.primary,
217+
child: Text(
218+
key: const Key('ViewAllProposalsBtn'),
219+
context.l10n.viewAllProposals,
220+
),
221+
onTap: () => const ProposalsRoute().go(context),
222+
);
223+
}
224+
}

catalyst_voices/apps/voices/lib/pages/discovery/state_selectors/most_recent_proposals_selector.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,19 @@ class MostRecentProposalsSelector extends StatelessWidget {
2525
}
2626

2727
class _MostRecentProposalsData extends StatelessWidget {
28+
static const _minProposalsToShowRecent = 6;
29+
2830
const _MostRecentProposalsData();
2931

3032
@override
3133
Widget build(BuildContext context) {
3234
return BlocSelector<DiscoveryCubit, DiscoveryState, _ListItems>(
3335
selector: (state) => state.mostRecentProposals.proposals,
3436
builder: (context, state) {
35-
return Offstage(
36-
offstage: state.length < 6,
37-
child: MostRecentProposals(proposals: state),
38-
);
37+
if (state.length < _minProposalsToShowRecent) {
38+
return const ViewAllProposals();
39+
}
40+
return MostRecentProposals(proposals: state);
3941
},
4042
);
4143
}

catalyst_voices/packages/internal/catalyst_voices_blocs/lib/src/discovery/discovery_cubit.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class DiscoveryCubit extends Cubit<DiscoveryState> with BlocErrorEmitterMixin {
189189
_proposalsSubscription =
190190
_proposalService.watchLatestProposals(limit: 7).listen(
191191
(proposals) async {
192-
_logger.finest('Got proposals: ${proposals.length}');
192+
_logger.info('Got proposals: ${proposals.length}');
193193
_emitMostRecentProposals(proposals);
194194
final currentFavorites =
195195
await _proposalService.watchFavoritesProposalsIds().first;

catalyst_voices/packages/internal/catalyst_voices_services/lib/src/proposal/proposal_service.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,10 @@ final class ProposalServiceImpl implements ProposalService {
392392
return _proposalRepository
393393
.watchLatestProposals(limit: limit)
394394
.switchMap((documents) async* {
395+
if (documents.isEmpty) {
396+
yield [];
397+
return;
398+
}
395399
final proposalsDataStreams = await Future.wait(
396400
documents.map(_createProposalDataStream).toList(),
397401
);

0 commit comments

Comments
 (0)