Skip to content

Commit 7e32f70

Browse files
authored
feat(cat-voices): share dialog in proposal view (#2256)
* feat(cat-voices): share dialog in proposal view * refactor(cat-voices): rename selfRef to proposalId for clarity in ProposalViewHeader and related components * refactor(cat-voices): rename proposalId to proposalRef * refactor(cat-voices): rename proposalId to proposalRef in ProposalViewHeader for improved clarity
1 parent 82a83b8 commit 7e32f70

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed
Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,48 @@
1+
import 'dart:async';
2+
3+
import 'package:catalyst_voices/routes/routing/proposal_route.dart';
14
import 'package:catalyst_voices/widgets/buttons/voices_buttons.dart';
5+
import 'package:catalyst_voices/widgets/modals/proposals/share_proposal_dialog.dart';
6+
import 'package:catalyst_voices/widgets/snackbar/voices_snackbar.dart';
7+
import 'package:catalyst_voices/widgets/snackbar/voices_snackbar_type.dart';
8+
import 'package:catalyst_voices_blocs/catalyst_voices_blocs.dart';
9+
import 'package:catalyst_voices_localization/catalyst_voices_localization.dart';
10+
import 'package:catalyst_voices_models/catalyst_voices_models.dart';
211
import 'package:flutter/material.dart';
12+
import 'package:flutter_bloc/flutter_bloc.dart';
313

414
class ProposalShareButton extends StatelessWidget {
515
const ProposalShareButton({super.key});
616

717
@override
818
Widget build(BuildContext context) {
9-
return ShareButton(
10-
onTap: () {
11-
// TODO(LynxLynxx): Implement Share
19+
return BlocSelector<ProposalCubit, ProposalState, DocumentRef?>(
20+
selector: (state) {
21+
return state.data.header.proposalRef;
22+
},
23+
builder: (context, proposalRef) {
24+
return ShareButton(
25+
onTap: () {
26+
if (proposalRef != null) {
27+
final url = ProposalRoute.fromRef(ref: proposalRef).location;
28+
unawaited(ShareProposalDialog.show(context, url));
29+
} else {
30+
_showErrorSnackbar(context);
31+
}
32+
},
33+
);
1234
},
1335
);
1436
}
37+
38+
void _showErrorSnackbar(BuildContext context) {
39+
VoicesSnackBar.hideCurrent(context);
40+
41+
VoicesSnackBar(
42+
type: VoicesSnackBarType.error,
43+
behavior: SnackBarBehavior.floating,
44+
title: context.l10n.somethingWentWrong,
45+
message: context.l10n.shareProposalErrorDescription,
46+
).show(context);
47+
}
1548
}

catalyst_voices/packages/internal/catalyst_voices_blocs/lib/src/proposal/proposal_cubit.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ final class ProposalCubit extends Cubit<ProposalState>
265265
: const <Segment>[];
266266

267267
final header = ProposalViewHeader(
268+
proposalRef: proposalDocumentRef,
268269
title: proposalDocument?.title ?? '',
269270
authorName: proposalDocument?.authorName ?? '',
270271
createdAt: proposalDocumentRef?.version?.tryDateTime,

catalyst_voices/packages/internal/catalyst_voices_localization/lib/l10n/intl_en.arb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2546,5 +2546,9 @@
25462546
"type": "int"
25472547
}
25482548
}
2549+
},
2550+
"shareProposalErrorDescription": "Something went wrong while sharing proposal. Please try again later.",
2551+
"@shareProposalErrorDescription": {
2552+
"description": "Error description when sharing proposal fails"
25492553
}
25502554
}

catalyst_voices/packages/internal/catalyst_voices_view_models/lib/src/proposal/proposal_view_header.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'package:catalyst_voices_view_models/catalyst_voices_view_models.dart';
33
import 'package:equatable/equatable.dart';
44

55
final class ProposalViewHeader extends Equatable {
6+
final DocumentRef? proposalRef;
67
final String title;
78
final String authorName;
89
final DateTime? createdAt;
@@ -11,6 +12,7 @@ final class ProposalViewHeader extends Equatable {
1112
final bool isFavorite;
1213

1314
const ProposalViewHeader({
15+
this.proposalRef,
1416
this.title = '',
1517
this.authorName = '',
1618
this.createdAt,
@@ -21,6 +23,7 @@ final class ProposalViewHeader extends Equatable {
2123

2224
@override
2325
List<Object?> get props => [
26+
proposalRef,
2427
title,
2528
authorName,
2629
createdAt,
@@ -30,6 +33,7 @@ final class ProposalViewHeader extends Equatable {
3033
];
3134

3235
ProposalViewHeader copyWith({
36+
Optional<DocumentRef>? proposalRef,
3337
String? title,
3438
String? authorName,
3539
Optional<DateTime>? createdAt,
@@ -38,6 +42,7 @@ final class ProposalViewHeader extends Equatable {
3842
bool? isFavorite,
3943
}) {
4044
return ProposalViewHeader(
45+
proposalRef: proposalRef.dataOr(this.proposalRef),
4146
title: title ?? this.title,
4247
authorName: authorName ?? this.authorName,
4348
createdAt: createdAt.dataOr(this.createdAt),

0 commit comments

Comments
 (0)